Search in sources :

Example 21 with SamplingRule

use of com.amazonaws.services.xray.model.SamplingRule in project aws-xray-sdk-java by aws.

the class CentralizedRuleTest method testSnapshot.

@Test
public void testSnapshot() {
    Clock clock = Clock.fixed(Instant.ofEpochSecond(1500000000), ZoneId.systemDefault());
    SamplingRule input = createInput("r1", 300, 10, 0.0);
    CentralizedRule rule = new CentralizedRule(input, new RandImpl());
    SamplingTargetDocument target = createTarget(2, 0.0, 1500000010);
    rule.update(target, clock.instant());
    rule.sample(clock.instant());
    Statistics s = Whitebox.getInternalState(rule, "statistics", CentralizedRule.class);
    // Assert statistics were updated
    Assert.assertEquals(1, s.getSampled());
    Assert.assertEquals(1, s.getRequests());
    Assert.assertEquals(0, s.getBorrowed());
    SamplingStatisticsDocument snapshot = rule.snapshot(Date.from(clock.instant()));
    // Assert snapshot contains expected statistics
    Assert.assertEquals("r1", snapshot.getRuleName());
    Assert.assertEquals(TimeUnit.SECONDS.toMillis(1500000000), snapshot.getTimestamp().toInstant().toEpochMilli());
    Assert.assertEquals(1, snapshot.getRequestCount().intValue());
    Assert.assertEquals(1, snapshot.getSampledCount().intValue());
    Assert.assertEquals(0, snapshot.getBorrowCount().intValue());
    // Assert current statistics are empty
    Assert.assertEquals(0, rule.snapshot(Date.from(clock.instant())).getRequestCount().intValue());
    Assert.assertEquals(0, rule.snapshot(Date.from(clock.instant())).getSampledCount().intValue());
    Assert.assertEquals(0, rule.snapshot(Date.from(clock.instant())).getBorrowCount().intValue());
}
Also used : RandImpl(com.amazonaws.xray.strategy.sampling.rand.RandImpl) SamplingStatisticsDocument(com.amazonaws.services.xray.model.SamplingStatisticsDocument) SamplingRule(com.amazonaws.services.xray.model.SamplingRule) Clock(java.time.Clock) SamplingTargetDocument(com.amazonaws.services.xray.model.SamplingTargetDocument) Test(org.junit.Test)

Example 22 with SamplingRule

use of com.amazonaws.services.xray.model.SamplingRule in project aws-xray-sdk-java by aws.

the class CentralizedManifestTest method testManifestSizeWithDefaultRule.

@Test
void testManifestSizeWithDefaultRule() {
    CentralizedManifest m = new CentralizedManifest();
    SamplingRule r2 = new SamplingRule().withRuleName(CentralizedRule.DEFAULT_RULE_NAME).withReservoirSize(20).withFixedRate(0.05);
    m.putRules(Arrays.asList(rule("r1"), r2), Instant.now());
    Assertions.assertEquals(2, m.size());
}
Also used : SamplingRule(com.amazonaws.services.xray.model.SamplingRule) Test(org.junit.jupiter.api.Test)

Example 23 with SamplingRule

use of com.amazonaws.services.xray.model.SamplingRule in project aws-xray-sdk-java by aws.

the class CentralizedManifestTest method testManifestSizeWithoutDefaultRule.

@Test
void testManifestSizeWithoutDefaultRule() {
    CentralizedManifest m = new CentralizedManifest();
    SamplingRule r1 = new SamplingRule().withRuleName(CentralizedRule.DEFAULT_RULE_NAME).withReservoirSize(20).withFixedRate(0.05);
    m.putRules(Arrays.asList(r1), Instant.now());
    Assertions.assertEquals(1, m.size());
}
Also used : SamplingRule(com.amazonaws.services.xray.model.SamplingRule) Test(org.junit.jupiter.api.Test)

Example 24 with SamplingRule

use of com.amazonaws.services.xray.model.SamplingRule 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 25 with SamplingRule

use of com.amazonaws.services.xray.model.SamplingRule 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

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