-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
164 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...cks/inspectit/ocelot/core/instrumentation/context/propagation/BrowserPropagationUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package rocks.inspectit.ocelot.core.instrumentation.context.propagation; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import lombok.Getter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Component; | ||
import rocks.inspectit.ocelot.core.config.InspectitConfigChangedEvent; | ||
import rocks.inspectit.ocelot.core.config.InspectitEnvironment; | ||
import rocks.inspectit.ocelot.core.instrumentation.context.ContextPropagationUtil; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
/** | ||
* Class to regulate the currently used session-id-key. | ||
* The session-id-key is used to extract session-ids from http-request-headers to allow browser propagation. | ||
* The session-id-key can change during runtime and needs to updated inside the PROPAGATION_FIELDS in ContextPropagationUtil. | ||
*/ | ||
@Slf4j | ||
@Component | ||
public class BrowserPropagationUtil { | ||
|
||
@Autowired | ||
private InspectitEnvironment env; | ||
@Getter | ||
private static String sessionIdKey; | ||
|
||
@PostConstruct | ||
public void initialize() { | ||
setSessionIdKey(env.getCurrentConfig().getExporters().getTags().getHttp().getSessionIdKey()); | ||
} | ||
|
||
@EventListener | ||
private void configEventListener(InspectitConfigChangedEvent event) { | ||
String oldSessionIdKey = event.getOldConfig().getExporters().getTags().getHttp().getSessionIdKey(); | ||
String newSessionIdKey = event.getNewConfig().getExporters().getTags().getHttp().getSessionIdKey(); | ||
|
||
if(!oldSessionIdKey.equals(newSessionIdKey)) setSessionIdKey(newSessionIdKey); | ||
} | ||
|
||
@VisibleForTesting | ||
void setSessionIdKey(String key) { | ||
sessionIdKey = key; | ||
ContextPropagationUtil.setSessionIdKey(sessionIdKey); | ||
log.info("Use of new session-id-key: " + sessionIdKey); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...inspectit/ocelot/core/instrumentation/context/propagation/BrowserPropagationUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package rocks.inspectit.ocelot.core.instrumentation.context.propagation; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import rocks.inspectit.ocelot.core.instrumentation.context.ContextPropagationUtil; | ||
|
||
import java.util.Set; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class BrowserPropagationUtilTest { | ||
|
||
@InjectMocks | ||
BrowserPropagationUtil browserPropagationUtil; | ||
|
||
final static String key = "Cookie"; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
browserPropagationUtil.setSessionIdKey(key); | ||
} | ||
|
||
@Test | ||
void verifySessionIdKeyExists() { | ||
Set<String> headers = ContextPropagationUtil.getPropagationHeaderNames(); | ||
|
||
assertThat(headers.contains(key)).isTrue(); | ||
} | ||
|
||
@Test | ||
void verifySessionIdKeyIsUpdated() { | ||
Set<String> headers = ContextPropagationUtil.getPropagationHeaderNames(); | ||
assertThat(headers.contains(key)).isTrue(); | ||
|
||
String newKey = "NewCookie"; | ||
browserPropagationUtil.setSessionIdKey(newKey); | ||
|
||
assertThat(headers.contains(key)).isFalse(); | ||
assertThat(headers.contains(newKey)).isTrue(); | ||
} | ||
} |