Skip to content

AWS X-Ray Remote Sampler Part 2 - Add Rules Caching and Rules Matching Logic #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 14, 2024

Conversation

jj22ee
Copy link
Contributor

@jj22ee jj22ee commented Feb 7, 2024

Issue #, if available:
Second PR of 3 parts for adding the X-Ray remote sampling support for OTel Python SDK.
See Part 1

Description of changes:

  • Sampling RuleCache
    • Caches a list of Rules, ordered by rule priority then rule name. Each rule corresponds to the Sampling Rule from GetSamplingRules. Each call to GetSamplingRules will only update the Rules that have changed properties, to preserve the state of unchanged rules. This means when Reservoir and Statistics are implemented in the Rules, they will persist for unchanged rules.
    • The RuleCache will determine which Rule a set of {ResourceAttributes,SpanAttributes} matches with that has highest priority.
  • Rule
    • Corresponds to a SamplingRule and has logic to match with provided set of ResourceAttribute and SpanAttribute using the Matcher class.
    • Will determine the final sampling decision
  • Matcher class with methods to perform:
    • Convert X-Ray sampling rule options to regex patterns
    • Wild card and attribute matching
  • Initial class for FallbackSampler

Testing:

Unit tests

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jj22ee jj22ee requested review from AsakerMohd, srprash and a team February 7, 2024 18:25
Copy link
Contributor

@srprash srprash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor comments. Overall LGTM!

@jj22ee jj22ee merged commit c91cad3 into main Feb 14, 2024
@jj22ee jj22ee deleted the remote-sampler-2 branch February 14, 2024 02:25
jj22ee added a commit that referenced this pull request Feb 16, 2024
… targets (#55)

*Issue #, if available:*
This is the 3rd and final part of the X-Ray Remote Sampler
implementation for Python
[See Part
2](#47)

*Description of changes:*
- Added logic to fetch sampling targets for each sampling rule applier.
- The sampling targets are periodically fetched every 10 seconds by
making the [GetSamplingTargets API call to
X-Ray](https://docs.aws.amazon.com/xray/latest/api/API_GetSamplingTargets.html).
- The targets determine the reservoir quota and the rate at which a
sampling rule applier will sample the requests.
- Each rule applier keeps and updates a sampling statistics document
which is required in `GetSamplingTargets` call to determine the next
target
- Added the rate limiting and fixed rate samplers to be used in each
rule applier.
- Together these sampler determine how many requests to sample every
second and what percentage of additional requests to sample in that
second.
- The FallbackSampler is a combination of above samplers to sample 1
req/sec and 5% of additional requests in that second.

*Testing:*
Unit Tests and Remote Sampling Testbed


## **Testbed:**
1. Have XRay Daemon running or OTel collector with XRay Proxy Client
setup running. Ensure AWS credentials used has only default rule with 5%
sampling and 1 req/s

2. Checkout this PR Branch, and install `pip3 install
aws-opentelemetry-distro/`

3. Download this Python Sample App:
https://github.com/jj22ee/aws-otel-community/tree/python-sample/centralized-sampling-tests/sample-apps/python-flask
Install python3 requirements.txt
Replace the following:
```
###
### Set sampler HERE
###
```
with:
```
from amazon.opentelemetry.distro.sampler.aws_xray_remote_sampler import AwsXRayRemoteSampler
xray_sampler = AwsXRayRemoteSampler(resource, polling_interval=10)
trace.set_tracer_provider(TracerProvider(sampler=xray_sampler))
```
Run Python Sample app with `python3 app.py`

4. Download this repository:
https://github.com/aws-observability/aws-otel-community/
Within directory `centralized-sampling-tests/` run: `./gradlew
:integration-tests:run`
Check that the tests have passed.

TODO: wire in the remote sampler to the ADOT Python customizer in this
PR or a new PR

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants