Search in sources :

Example 6 with SamplingRequest

use of com.amazonaws.xray.strategy.sampling.SamplingRequest in project aws-xray-sdk-java by aws.

the class MatchersTest method testPartialGlobMatch.

@Test
void testPartialGlobMatch() {
    Map<String, String> ruleAttributes = new HashMap<>();
    ruleAttributes.put("ip", "127.*.1");
    ruleAttributes.put("compression", "*");
    Map<String, String> reqAttributes = new HashMap<>();
    reqAttributes.put("ip", "127.0.0.1");
    reqAttributes.put("compression", "gzip");
    reqAttributes.put("encoding", "json");
    SamplingRule rule = new SamplingRule().withAttributes(ruleAttributes).withHost("*").withServiceName("*.foo.*").withHTTPMethod("*").withResourceARN("*").withURLPath("/bar/*").withServiceType("AWS::EC2::Instance");
    SamplingRequest req = new SamplingRequest("role-arn", "arn:aws:service:us-east-1:111111111111:resource", "www.foo.com", "192.168.1.1", "GET", "/bar/baz", "AWS::EC2::Instance", reqAttributes);
    Matchers m = new Matchers(rule);
    Assertions.assertTrue(m.match(req));
}
Also used : HashMap(java.util.HashMap) SamplingRule(com.amazonaws.services.xray.model.SamplingRule) SamplingRequest(com.amazonaws.xray.strategy.sampling.SamplingRequest) Test(org.junit.jupiter.api.Test)

Example 7 with SamplingRequest

use of com.amazonaws.xray.strategy.sampling.SamplingRequest in project aws-xray-sdk-java by aws.

the class MatchersTest method testFullGlobMatch.

@Test
void testFullGlobMatch() {
    Map<String, String> ruleAttributes = new HashMap<>();
    ruleAttributes.put("ip", "*");
    ruleAttributes.put("compression", "*");
    Map<String, String> reqAttributes = new HashMap<>();
    reqAttributes.put("ip", "127.0.0.1");
    reqAttributes.put("compression", "gzip");
    reqAttributes.put("encoding", "json");
    SamplingRule rule = new SamplingRule().withAttributes(ruleAttributes).withHost("*").withServiceName("*").withHTTPMethod("*").withResourceARN("*").withURLPath("*").withServiceType("*");
    SamplingRequest req = new SamplingRequest("role-arn", "arn:aws:service:us-east-1:111111111111:resource", "www.foo.com", "192.168.1.1", "GET", "/baz/bar", "AWS::EC2::Instance", reqAttributes);
    Matchers m = new Matchers(rule);
    Assertions.assertTrue(m.match(req));
}
Also used : HashMap(java.util.HashMap) SamplingRule(com.amazonaws.services.xray.model.SamplingRule) SamplingRequest(com.amazonaws.xray.strategy.sampling.SamplingRequest) Test(org.junit.jupiter.api.Test)

Example 8 with SamplingRequest

use of com.amazonaws.xray.strategy.sampling.SamplingRequest in project aws-xray-sdk-java by aws.

the class AWSXRayServletFilter method fromSamplingStrategy.

private SamplingResponse fromSamplingStrategy(HttpServletRequest httpServletRequest) {
    AWSXRayRecorder recorder = getRecorder();
    SamplingRequest samplingRequest = new SamplingRequest(getSegmentName(httpServletRequest), getHost(httpServletRequest).orElse(null), httpServletRequest.getRequestURI(), httpServletRequest.getMethod(), recorder.getOrigin());
    SamplingResponse sample = recorder.getSamplingStrategy().shouldTrace(samplingRequest);
    return sample;
}
Also used : SamplingRequest(com.amazonaws.xray.strategy.sampling.SamplingRequest) AWSXRayRecorder(com.amazonaws.xray.AWSXRayRecorder) SamplingResponse(com.amazonaws.xray.strategy.sampling.SamplingResponse)

Example 9 with SamplingRequest

use of com.amazonaws.xray.strategy.sampling.SamplingRequest in project aws-xray-sdk-java by aws.

the class CentralizedManifestTest method testPutRules.

@Test
void testPutRules() {
    Instant now = Instant.ofEpochSecond(1500000000);
    CentralizedManifest manifest = new CentralizedManifest();
    // Liberal sampling rule
    SamplingRule r1 = new SamplingRule().withRuleName("r1").withPriority(10).withReservoirSize(20).withFixedRate(0.05).withHost("*").withServiceName("*").withHTTPMethod("*").withURLPath("*").withResourceARN("*").withServiceType("*");
    manifest.putRules(Arrays.asList(r1), now);
    SamplingRequest req = new SamplingRequest("privileged", "resourceARN", "service", "host", "method", "url", "serviceType", null);
    Assertions.assertEquals("r1", manifest.match(req, now).sample(now).getRuleName().get());
}
Also used : Instant(java.time.Instant) SamplingRule(com.amazonaws.services.xray.model.SamplingRule) SamplingRequest(com.amazonaws.xray.strategy.sampling.SamplingRequest) Test(org.junit.jupiter.api.Test)

Example 10 with SamplingRequest

use of com.amazonaws.xray.strategy.sampling.SamplingRequest in project aws-xray-sdk-java by aws.

the class CentralizedManifestTest method testPositiveMatch.

@Test
void testPositiveMatch() {
    Instant now = Instant.ofEpochSecond(1500000000);
    CentralizedManifest manifest = new CentralizedManifest();
    SamplingRule r1 = new SamplingRule().withRuleName("r1").withPriority(10).withReservoirSize(20).withFixedRate(0.05).withHost("*").withServiceName("*").withHTTPMethod("*").withURLPath("*").withResourceARN("*").withServiceType("*");
    manifest.putRules(Arrays.asList(r1), now);
    SamplingRequest req = new SamplingRequest("privileged", "resourceARN", "service", "host", "method", "url", "serviceType", null);
    Assertions.assertEquals("r1", manifest.match(req, now).sample(now).getRuleName().get());
}
Also used : Instant(java.time.Instant) SamplingRule(com.amazonaws.services.xray.model.SamplingRule) SamplingRequest(com.amazonaws.xray.strategy.sampling.SamplingRequest) Test(org.junit.jupiter.api.Test)

Aggregations

SamplingRequest (com.amazonaws.xray.strategy.sampling.SamplingRequest)12 SamplingRule (com.amazonaws.services.xray.model.SamplingRule)10 Test (org.junit.jupiter.api.Test)10 Instant (java.time.Instant)3 HashMap (java.util.HashMap)3 SamplingResponse (com.amazonaws.xray.strategy.sampling.SamplingResponse)2 AWSXRayRecorder (com.amazonaws.xray.AWSXRayRecorder)1 FacadeSegment (com.amazonaws.xray.entities.FacadeSegment)1 Segment (com.amazonaws.xray.entities.Segment)1