Search in sources :

Example 1 with SamplingRequest

use of com.amazonaws.xray.strategy.sampling.SamplingRequest in project aws-xray-sdk-java by aws.

the class AWSXRayServletFilter method fromSamplingStrategy.

private SamplingResponse fromSamplingStrategy(HttpServletRequest httpServletRequest) {
    AWSXRayRecorder recorder = getRecorder();
    SamplingRequest samplingRequest = new SamplingRequest(getSegmentName(httpServletRequest), getHost(httpServletRequest).orElse(null), httpServletRequest.getRequestURI(), httpServletRequest.getMethod(), recorder.getOrigin());
    SamplingResponse sample = recorder.getSamplingStrategy().shouldTrace(samplingRequest);
    return sample;
}
Also used : SamplingRequest(com.amazonaws.xray.strategy.sampling.SamplingRequest) AWSXRayRecorder(com.amazonaws.xray.AWSXRayRecorder) SamplingResponse(com.amazonaws.xray.strategy.sampling.SamplingResponse)

Example 2 with SamplingRequest

use of com.amazonaws.xray.strategy.sampling.SamplingRequest in project aws-xray-sdk-java by aws.

the class AWSXRayRecorder method beginSegmentWithSampling.

/**
 * Begins a new segment after applying the configured sampling strategy. This method only uses the segment name and origin
 * (if defined) to compute a sampling decision.
 *
 * @param name the segment name, to be used for the sampling decision
 * @return Returns a proper segment if a sampled decision is made, and a no-op segment otherwise.
 */
public Segment beginSegmentWithSampling(String name) {
    final SamplingRequest samplingRequest = new SamplingRequest(name, null, null, null, this.origin);
    final SamplingResponse samplingResponse = this.getSamplingStrategy().shouldTrace(samplingRequest);
    if (samplingResponse.isSampled()) {
        Segment segment = beginSegment(name);
        if (samplingResponse.getRuleName().isPresent()) {
            segment.setRuleName(samplingResponse.getRuleName().get());
        }
        return segment;
    } else if (this.getSamplingStrategy().isForcedSamplingSupported()) {
        Segment segment = beginSegment(name);
        segment.setSampled(false);
        if (samplingResponse.getRuleName().isPresent()) {
            segment.setRuleName(samplingResponse.getRuleName().get());
        }
        return segment;
    }
    return beginNoOpSegment();
}
Also used : SamplingRequest(com.amazonaws.xray.strategy.sampling.SamplingRequest) Segment(com.amazonaws.xray.entities.Segment) FacadeSegment(com.amazonaws.xray.entities.FacadeSegment) SamplingResponse(com.amazonaws.xray.strategy.sampling.SamplingResponse)

Example 3 with SamplingRequest

use of com.amazonaws.xray.strategy.sampling.SamplingRequest in project aws-xray-sdk-java by aws.

the class CentralizedManifestTest method testPositiveDefaultRuleMatch.

@Test
void testPositiveDefaultRuleMatch() {
    Instant now = Instant.ofEpochSecond(1500000000);
    CentralizedManifest manifest = new CentralizedManifest();
    SamplingRule r2 = new SamplingRule().withRuleName(CentralizedRule.DEFAULT_RULE_NAME).withReservoirSize(20).withFixedRate(0.05);
    manifest.putRules(Arrays.asList(rule("r1"), r2), now);
    // Request that matches against the default rule
    SamplingRequest req = new SamplingRequest("privileged", "resourceARN", "service", "host", "method", "url", "serviceType", null);
    Assertions.assertEquals(CentralizedRule.DEFAULT_RULE_NAME, 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 4 with SamplingRequest

use of com.amazonaws.xray.strategy.sampling.SamplingRequest 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 5 with SamplingRequest

use of com.amazonaws.xray.strategy.sampling.SamplingRequest 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)

Aggregations

SamplingRequest (com.amazonaws.xray.strategy.sampling.SamplingRequest)12 SamplingRule (com.amazonaws.services.xray.model.SamplingRule)10 Test (org.junit.jupiter.api.Test)10 Instant (java.time.Instant)3 HashMap (java.util.HashMap)3 SamplingResponse (com.amazonaws.xray.strategy.sampling.SamplingResponse)2 AWSXRayRecorder (com.amazonaws.xray.AWSXRayRecorder)1 FacadeSegment (com.amazonaws.xray.entities.FacadeSegment)1 Segment (com.amazonaws.xray.entities.Segment)1