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));
}
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));
}
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;
}
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());
}
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());
}
Aggregations