Search in sources :

Example 1 with SamplingStatisticsDocument

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

the class CentralizedManifestTest method testSnapshotsWithoutDefaultRule.

@Test
void testSnapshotsWithoutDefaultRule() {
    Instant now = Instant.ofEpochSecond(1500000000);
    CentralizedManifest m = new CentralizedManifest();
    m.putRules(Arrays.asList(rule("r1"), rule("r2")), now);
    Map<String, CentralizedRule> rules = Whitebox.getInternalState(m, "rules", CentralizedManifest.class);
    rules.forEach((key, r) -> r.sample(now));
    List<SamplingStatisticsDocument> snapshots = m.snapshots(now);
    Assertions.assertEquals(2, snapshots.size());
}
Also used : SamplingStatisticsDocument(com.amazonaws.services.xray.model.SamplingStatisticsDocument) Instant(java.time.Instant) CentralizedRule(com.amazonaws.xray.strategy.sampling.rule.CentralizedRule) Test(org.junit.jupiter.api.Test)

Example 2 with SamplingStatisticsDocument

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

the class UnsignedXrayClientTest method getSamplingTargets.

@Test
public void getSamplingTargets() throws Exception {
    stubFor(any(anyUrl()).willReturn(aResponse().withStatus(200).withBody(SAMPLING_TARGETS)));
    GetSamplingTargetsRequest request = new GetSamplingTargetsRequest().withSamplingStatisticsDocuments(new SamplingStatisticsDocument().withClientID("client-id"));
    GetSamplingTargetsResult result = client.getSamplingTargets(request);
    GetSamplingTargetsResult expected = OBJECT_MAPPER.readValue(SAMPLING_TARGETS, GetSamplingTargetsResult.class);
    assertThat(expected).isEqualTo(result);
    verify(postRequestedFor(urlEqualTo("/SamplingTargets")).withHeader("Content-Type", equalTo("application/json")).withRequestBody(equalToJson("{" + " \"SamplingStatisticsDocuments\": [" + "    {" + "      \"ClientID\": \"client-id\"" + "    }" + " ] " + "}")));
}
Also used : SamplingStatisticsDocument(com.amazonaws.services.xray.model.SamplingStatisticsDocument) GetSamplingTargetsRequest(com.amazonaws.services.xray.model.GetSamplingTargetsRequest) GetSamplingTargetsResult(com.amazonaws.services.xray.model.GetSamplingTargetsResult) Test(org.junit.Test)

Example 3 with SamplingStatisticsDocument

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

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

the class CentralizedManifestTest method testSnapshotsWithDefaultRule.

@Test
void testSnapshotsWithDefaultRule() {
    Instant now = Instant.ofEpochSecond(1500000000);
    CentralizedManifest m = new CentralizedManifest();
    m.putRules(Arrays.asList(rule("r1"), rule("r2"), rule(CentralizedRule.DEFAULT_RULE_NAME)), now);
    Map<String, CentralizedRule> rules = Whitebox.getInternalState(m, "rules", CentralizedManifest.class);
    CentralizedRule defaultRule = Whitebox.getInternalState(m, "defaultRule", CentralizedManifest.class);
    rules.forEach((key, r) -> r.sample(now));
    defaultRule.sample(now);
    List<SamplingStatisticsDocument> snapshots = m.snapshots(now);
    Assertions.assertEquals(3, snapshots.size());
}
Also used : SamplingStatisticsDocument(com.amazonaws.services.xray.model.SamplingStatisticsDocument) Instant(java.time.Instant) CentralizedRule(com.amazonaws.xray.strategy.sampling.rule.CentralizedRule) Test(org.junit.jupiter.api.Test)

Example 5 with SamplingStatisticsDocument

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

the class CentralizedRule method snapshot.

public SamplingStatisticsDocument snapshot(Date now) {
    SamplingStatisticsDocument s = new SamplingStatisticsDocument().withRuleName(name).withTimestamp(now);
    lock.writeLock().lock();
    try {
        s.setRequestCount(statistics.getRequests());
        s.setSampledCount(statistics.getSampled());
        s.setBorrowCount(statistics.getBorrowed());
        statistics.reset();
    } finally {
        lock.writeLock().unlock();
    }
    return s;
}
Also used : SamplingStatisticsDocument(com.amazonaws.services.xray.model.SamplingStatisticsDocument)

Aggregations

SamplingStatisticsDocument (com.amazonaws.services.xray.model.SamplingStatisticsDocument)7 CentralizedRule (com.amazonaws.xray.strategy.sampling.rule.CentralizedRule)3 GetSamplingTargetsRequest (com.amazonaws.services.xray.model.GetSamplingTargetsRequest)2 GetSamplingTargetsResult (com.amazonaws.services.xray.model.GetSamplingTargetsResult)2 Instant (java.time.Instant)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 SamplingRule (com.amazonaws.services.xray.model.SamplingRule)1 SamplingTargetDocument (com.amazonaws.services.xray.model.SamplingTargetDocument)1 RandImpl (com.amazonaws.xray.strategy.sampling.rand.RandImpl)1 Clock (java.time.Clock)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1