Search in sources :

Example 6 with SamplingRule

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

the class CentralizedRuleTest method testExpiredReservoirPositiveBernoulliSample.

@Test
public void testExpiredReservoirPositiveBernoulliSample() {
    Clock clock = Clock.fixed(Instant.ofEpochSecond(1500000000), ZoneId.systemDefault());
    SamplingRule input = createInput("r1", 300, 0, 0.5);
    CentralizedRule rule = new CentralizedRule(input, rand);
    SamplingTargetDocument target = createTarget(0, 0.5, 1499999999);
    rule.update(target, clock.instant());
    Mockito.when(rand.next()).thenReturn(0.2);
    // BernoulliSample() from expired reservoir
    SamplingResponse response = rule.sample(clock.instant());
    Mockito.verify(rand).next();
    Assert.assertTrue(response.isSampled());
    Assert.assertEquals("r1", response.getRuleName().get());
    Statistics s = Whitebox.getInternalState(rule, "statistics", CentralizedRule.class);
    Assert.assertEquals(1, s.getSampled());
    Assert.assertEquals(1, s.getRequests());
    Assert.assertEquals(0, s.getBorrowed());
}
Also used : SamplingRule(com.amazonaws.services.xray.model.SamplingRule) Clock(java.time.Clock) SamplingTargetDocument(com.amazonaws.services.xray.model.SamplingTargetDocument) SamplingResponse(com.amazonaws.xray.strategy.sampling.SamplingResponse) Test(org.junit.Test)

Example 7 with SamplingRule

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

the class CentralizedRuleTest method testNegativeSample.

@Test
public void testNegativeSample() {
    Clock clock = Clock.fixed(Instant.ofEpochSecond(1500000000), ZoneId.systemDefault());
    SamplingRule input = createInput("r1", 300, 10, 0.0);
    CentralizedRule rule = new CentralizedRule(input, rand);
    SamplingTargetDocument target = createTarget(0, 0.0, 1500000010);
    rule.update(target, clock.instant());
    SamplingResponse response = rule.sample(clock.instant());
    Assert.assertFalse(response.isSampled());
    Assert.assertEquals("r1", response.getRuleName().get());
    Statistics s = Whitebox.getInternalState(rule, "statistics", CentralizedRule.class);
    Assert.assertEquals(0, s.getSampled());
    Assert.assertEquals(1, s.getRequests());
    Assert.assertEquals(0, s.getBorrowed());
}
Also used : SamplingRule(com.amazonaws.services.xray.model.SamplingRule) Clock(java.time.Clock) SamplingTargetDocument(com.amazonaws.services.xray.model.SamplingTargetDocument) SamplingResponse(com.amazonaws.xray.strategy.sampling.SamplingResponse) Test(org.junit.Test)

Example 8 with SamplingRule

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

the class MatchersTest method testSimpleMismatch.

@Test
void testSimpleMismatch() {
    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.bar.com", "192.168.1.1", "POST", "/bar/123", "AWS::EC2::Instance", null);
    Matchers m = new Matchers(rule);
    Assertions.assertFalse(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 9 with SamplingRule

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

the class MatchersTest method testPartialRequestMismatch.

@Test
void testPartialRequestMismatch() {
    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.bar.com", null, "POST", "/bar/123", "AWS::EC2::Instance", null);
    Matchers m = new Matchers(rule);
    Assertions.assertFalse(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 10 with SamplingRule

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

the class MatchersTest method testPartialGlobMismatch.

@Test
void testPartialGlobMismatch() {
    SamplingRule rule = new SamplingRule().withAttributes(null).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.bar.com", "192.168.1.1", "GET", "/foo/baz", "AWS::EC2::Instance", null);
    Matchers m = new Matchers(rule);
    Assertions.assertFalse(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

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