use of com.amazonaws.services.xray.model.SamplingRule in project aws-xray-sdk-java by aws.
the class CentralizedManifestTest method testRebuildOnPriorityChange.
@Test
void testRebuildOnPriorityChange() {
CentralizedManifest manifest = new CentralizedManifest();
manifest.putRules(Arrays.asList(rule("r1")), Instant.now());
Map<String, CentralizedRule> rules1 = Whitebox.getInternalState(manifest, "rules", CentralizedManifest.class);
SamplingRule r = rule("r1").withPriority(200);
manifest.putRules(Arrays.asList(r), Instant.now());
Map<String, CentralizedRule> rules2 = Whitebox.getInternalState(manifest, "rules", CentralizedManifest.class);
// The map of rules should be rebuilt, resulting in a new object
Assertions.assertFalse(rules1 == rules2);
Assertions.assertEquals(1, rules1.size());
Assertions.assertEquals(1, rules2.size());
}
use of com.amazonaws.services.xray.model.SamplingRule in project aws-xray-sdk-java by aws.
the class CentralizedManifestTest method testPutRulesWithoutRebuild.
@Test
void testPutRulesWithoutRebuild() {
CentralizedManifest manifest = new CentralizedManifest();
manifest.putRules(Arrays.asList(rule("r1")), Instant.now());
Map<String, CentralizedRule> rules1 = Whitebox.getInternalState(manifest, "rules", CentralizedManifest.class);
SamplingRule r = rule("r1").withResourceARN("arn3");
manifest.putRules(Arrays.asList(r), Instant.now());
Map<String, CentralizedRule> rules2 = Whitebox.getInternalState(manifest, "rules", CentralizedManifest.class);
// The map of rules should not have been rebuilt
Assertions.assertTrue(rules1 == rules2);
}
use of com.amazonaws.services.xray.model.SamplingRule 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));
}
use of com.amazonaws.services.xray.model.SamplingRule 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));
}
use of com.amazonaws.services.xray.model.SamplingRule in project aws-xray-sdk-java by aws.
the class RulePoller method pollRule.
private void pollRule() {
Instant now = clock.instant();
logger.info("Polling sampling rules.");
GetSamplingRulesRequest req = new GetSamplingRulesRequest();
GetSamplingRulesResult records = client.getSamplingRules(req);
List<SamplingRule> rules = records.getSamplingRuleRecords().stream().map(SamplingRuleRecord::getSamplingRule).filter(CentralizedRule::isValid).collect(Collectors.toList());
manifest.putRules(rules, now);
}
Aggregations