You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+85-1Lines changed: 85 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
## Dynamically adjust sampling rules in X-Ray
2
-
This repo is used in the aws blog to showcase dynamic sampling rules on X-Ray
2
+
This repo is used in the AWS blog (https://aws.amazon.com/blogs/mt/dynamically-adjusting-x-ray-sampling-rules/) to showcase dynamic sampling rules on X-Ray
3
3
4
4
## Security
5
5
@@ -9,3 +9,87 @@ See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more inform
9
9
10
10
This library is licensed under the MIT-0 License. See the LICENSE file.
11
11
12
+
13
+
## Architecture
14
+
Generic pattern of dynamic sampling rule adjustment is shown below. The idea is to use CloudWatch alarm to trigger the X-Ray sampling rule
15
+
adjustment process. The alarm can be configured based on applications needs, for example high CPU utilization, number of Lambda function failures,
16
+
or rate of 5xx errors in API Gateway.
17
+
18
+

19
+
20
+
This pattern can be applied to a number of architectures. This repository illustrates it using a simple web application that
21
+
contains of API Gateway and backend Lambda function.
22
+
23
+

24
+
25
+
1. Clients access API Gateway using HTTP requests
26
+
2. API Gateway forwards requests to AWS Lambda function for processing
27
+
3. Errors in lambda function trigger CloudWatch alarm state change
28
+
4. Message about changed alarm state is posted in SNS topic
29
+
5. Lambda function is triggered in response to SNS message
30
+
6. Based on Alarm state, X-Ray sampling rules are adjusted
31
+
7. Incoming requests are traced based on updated rules
32
+
33
+
## Build and deploy instructions
34
+
Example template provided uses [AWS SAM](https://aws.amazon.com/serverless/sam/) to simplify the deployment.
35
+
36
+
To install lambda function dependencies and create a deployment package use the following command:
37
+
```
38
+
sam build
39
+
```
40
+
41
+
Once the project is built, use [sam deploy](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-deploy.html)
42
+
to deploy the stack:
43
+
44
+
```
45
+
sam deploy --guided
46
+
```
47
+
48
+
or by providing all parameters in command line:
49
+
50
+
```
51
+
sam deploy --stack-name <stack-name> --s3-bucket <deployment-bucket> --capabilities CAPABILITY_IAM
52
+
```
53
+
54
+
Use the `WebApi` output value to access the deployed API:
The repository demonstrates how to manage AWS X-Ray sampling rule resources
68
+
using CloudFormation. At the time of writing there is no standard resource type
69
+
you can use, so a custom implementation is needed.
70
+
71
+
The implementation relies on [Custom Resource Helper](https://github.com/aws-cloudformation/custom-resource-helper) package.
72
+
73
+
74
+
| Name | Type | Required | Default | Description |
75
+
| --- | ---| --- | ---| --- |
76
+
|`Name`| string | yes || Name of the sampling rule |
77
+
|`Priority`| int | yes || Must be from the range of 1-9999 |
78
+
|`FixedRate`| float | yes || Must be from the range of 0-1 |
79
+
|`ReservoirSize`| int | yes || Maximum number of request to sample per second |
80
+
|`ResourceARN`| string | no | * | Resource ARN to match |
81
+
|`ServiceName`| string | no | * | Name of the service to match |
82
+
|`ServiceType`| string | no | * | Type of the service to match |
83
+
|`Host`| string | no | * | The IP address or EC2 hostname to match |
84
+
|`HTTPMethod`| string | no | * | HTTP method to match |
85
+
|`URLPath`| string | no | * | URL path to match |
86
+
87
+
88
+
## Custom Resource return values
89
+
90
+
Return values can be referenced in CloudFormation template using [Fn::GetAtt](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html)
0 commit comments