Search in sources :

Example 11 with SamplingRequest

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

the class MatchersTest method testPartialAttributeGlobMismatch.

@Test
void testPartialAttributeGlobMismatch() {
    Map<String, String> ruleAttributes = new HashMap<>();
    ruleAttributes.put("ip", "127.*.0");
    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("AWS::EC2::Instance");
    SamplingRequest req = new SamplingRequest("role-arn", "arn:aws:service:us-east-1:111111111111:resource", "www.bar.com", "192.168.1.1", "GET", "/foo/baz", "AWS::EC2::Instance", reqAttributes);
    Matchers m = new Matchers(rule);
    Assertions.assertFalse(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 12 with SamplingRequest

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

the class MatchersTest method testSimpleMatch.

@Test
void testSimpleMatch() {
    SamplingRule rule = new SamplingRule().withAttributes(null).withHost("192.168.1.1").withServiceName("www.foo.com").withHTTPMethod("POST").withResourceARN("arn:aws:service:us-east-1:111111111111:resource").withURLPath("/bar/123").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", "POST", "/bar/123", "AWS::EC2::Instance", null);
    Matchers m = new Matchers(rule);
    Assertions.assertTrue(m.match(req));
}
Also used : 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