Search in sources :

Example 26 with SamplingRule

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());
}
Also used : CentralizedRule(com.amazonaws.xray.strategy.sampling.rule.CentralizedRule) SamplingRule(com.amazonaws.services.xray.model.SamplingRule) Test(org.junit.jupiter.api.Test)

Example 27 with SamplingRule

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);
}
Also used : CentralizedRule(com.amazonaws.xray.strategy.sampling.rule.CentralizedRule) SamplingRule(com.amazonaws.services.xray.model.SamplingRule) Test(org.junit.jupiter.api.Test)

Example 28 with SamplingRule

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));
}
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 29 with SamplingRule

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));
}
Also used : SamplingRule(com.amazonaws.services.xray.model.SamplingRule) SamplingRequest(com.amazonaws.xray.strategy.sampling.SamplingRequest) Test(org.junit.jupiter.api.Test)

Example 30 with SamplingRule

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);
}
Also used : SamplingRuleRecord(com.amazonaws.services.xray.model.SamplingRuleRecord) GetSamplingRulesResult(com.amazonaws.services.xray.model.GetSamplingRulesResult) Instant(java.time.Instant) GetSamplingRulesRequest(com.amazonaws.services.xray.model.GetSamplingRulesRequest) SamplingRule(com.amazonaws.services.xray.model.SamplingRule)

Aggregations

SamplingRule (com.amazonaws.services.xray.model.SamplingRule)30 Test (org.junit.jupiter.api.Test)17 SamplingRequest (com.amazonaws.xray.strategy.sampling.SamplingRequest)10 Test (org.junit.Test)10 SamplingTargetDocument (com.amazonaws.services.xray.model.SamplingTargetDocument)8 RandImpl (com.amazonaws.xray.strategy.sampling.rand.RandImpl)8 Clock (java.time.Clock)6 Instant (java.time.Instant)6 SamplingResponse (com.amazonaws.xray.strategy.sampling.SamplingResponse)5 CentralizedRule (com.amazonaws.xray.strategy.sampling.rule.CentralizedRule)5 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 GetSamplingRulesRequest (com.amazonaws.services.xray.model.GetSamplingRulesRequest)1 GetSamplingRulesResult (com.amazonaws.services.xray.model.GetSamplingRulesResult)1 SamplingRuleRecord (com.amazonaws.services.xray.model.SamplingRuleRecord)1 SamplingStatisticsDocument (com.amazonaws.services.xray.model.SamplingStatisticsDocument)1 CentralizedReservoir (com.amazonaws.xray.strategy.sampling.reservoir.CentralizedReservoir)1 LinkedHashMap (java.util.LinkedHashMap)1