Skip to content

Commit

Permalink
Migrate centralized sampling tests from aws-otel-test-framework (#299)
Browse files Browse the repository at this point in the history
* Migrate centralized sampling tests from aws-otel-test-framework

* Update .github/workflows/centralized-sampling-tests.yml

Co-authored-by: bryan-aguilar <46550959+bryan-aguilar@users.noreply.github.com>

* Update .github/workflows/centralized-sampling-tests.yml

Co-authored-by: bryan-aguilar <46550959+bryan-aguilar@users.noreply.github.com>

* Update .github/workflows/centralized-sampling-tests.yml

Co-authored-by: bryan-aguilar <46550959+bryan-aguilar@users.noreply.github.com>

* update setup-java@v3 action

* add centralized sampling apps to dependabot

* Update .github/dependabot.yml

---------

Co-authored-by: bryan-aguilar <46550959+bryan-aguilar@users.noreply.github.com>
  • Loading branch information
jj22ee and bryan-aguilar committed Mar 24, 2023
1 parent 3549983 commit 0088e56
Show file tree
Hide file tree
Showing 26 changed files with 2,221 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ updates:
schedule:
interval: "weekly"
day: "sunday"
- package-ecosystem: "gradle"
directory: "/centralized-sampling-tests/integration-tests"
schedule:
interval: "weekly"
day: "sunday"
- package-ecosystem: "gradle"
directory: "/centralized-sampling-tests/sample-apps/spring-boot"
schedule:
interval: "weekly"
day: "sunday"
50 changes: 50 additions & 0 deletions .github/workflows/centralized-sampling-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

name: Centralized Sampling Integration Tests

on:
push:
branches:
- master
paths:
- 'centralized-sampling-tests/**'
workflow_dispatch:

permissions:
id-token: write

jobs:
run_tests:
name: Run centralized sampling integration tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu'
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
role-to-assume: ${{ secrets.AWS_CENTRALIZED_SAMPLING_ROLE }}
role-duration-seconds: 1200
aws-region: us-west-2
- name: Build with Gradle Spring Boot App
run: ./gradlew :sample-apps:spring-boot:build
working-directory: centralized-sampling-tests
- name: Build with Gradle Integration Tests
run: ./gradlew :integration-tests:build
working-directory: centralized-sampling-tests
- name: Run test containers
run: docker-compose up --abort-on-container-exit
working-directory: centralized-sampling-tests
env:
INSTANCE_ID: ${{ github.run_id }}-${{ github.run_number }}
LISTEN_ADDRESS: 0.0.0.0:8080
59 changes: 59 additions & 0 deletions centralized-sampling-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Centralized Sampling Integration Tests

## Introduction

This project is meant to be used to test that X-ray's centralized sampling strategies
are working properly. This folder has sample apps configured for the integration tests
under sample apps in languages that support centralized sampling. As of now the languages
supported are Java and Go. To run these tests, first start up the collector, then
start up the chosen sample app, then start running the tests.

## Run Locally

### Set up collector
To run locally first set up the collector with the correct configuration.
It is possible that this is already done. Available ADOT Collector releases can be found here
[aws-otel-collector](https://github.com/aws-observability/aws-otel-collector/releases).
Make sure that the collector config is configured to work with a local x-ray listener pointed
to port 2000 and the docker run command exposes port 2000. Set up the ADOT collector with the
example-collector-config file. Clone the ADOT Collector repo and start the Collector with commands.
```shell
cd aws-otel-collector
```
```shell
docker run --rm -p 2000:2000 -p 55680:55680 -p 8889:8888 \
-e AWS_REGION=us-west-2 \
-e AWS_PROFILE=default \
-v ~/.aws:/root/.aws \
-v "${PWD}/examples/docker/config-test.yaml":/otel-local-config.yaml \
--name awscollector public.ecr.aws/aws-observability/aws-otel-collector:latest \
--config otel-local-config.yaml;
```

### Start up sample app
Start up the sample app of your choice in the sample apps folder. The sample apps exist in the sample-apps folder.
Each sample app will have a readMe on how to run it. If adding a sample-app to use for the integration tests see
[Sample-app-requirements](https://docs.google.com/document/d/1nu6XwYKe8h3EZ6upCQqf83hI9gQ-yg5WXlxHRjJ7BCg/edit?usp=sharing)
. The sample apps were manually instrumented for X-Ray Remote Sampling, for more context see
[here](https://aws-otel.github.io/docs/getting-started/java-sdk/trace-auto-instr#using-x-ray-remote-sampling)

### Start integration tests
Run this command in the directory `centralized-sampling-tests` once the Collector
and sample app are up and running. Ensure that the AWS account being used on your local account has no
pre-existing sample rules in it or the tests will fail.
```shell
./gradlew :integration-tests:run
```

### Github Actions
The tests will run automatically on PRs for changes that involve the centralized-sampling-tests folder.
It is also possible to run the tests manually as a GitHub action. To do this, you will need to make a fork
of the repository. From your fork, add a GitHub secret AWS_CENTRALIZED_SAMPLING_ROLE and add an AWS Dev
account with permissions to AWS XRay and GitHub setup.
Example:
```shell
AWS_CENTRALIZED_SAMPLING_ROLE: arn:aws:iam::123456789012:role/S3Access
```
See [Setup AWS GitHub](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services)
for more information. Once the secret is added go to your forks actions, select the Centralized Sampling Integration Tests workflow and
click the Run workflow button.
41 changes: 41 additions & 0 deletions centralized-sampling-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* User Manual available at https://docs.gradle.org/6.5/userguide/tutorial_java_projects.html
*/

plugins {
// Apply the java plugin to add support for Java
id 'java'
}

repositories {
mavenCentral()
}

dependencies {
// This dependency is used by the application.
implementation 'com.google.guava:guava:31.1-jre'

// Use JUnit test framework
testImplementation 'junit:junit:4.13.2'
}

allprojects {
repositories {
mavenCentral()
}
}

subprojects {
version = '1.0'

plugins.withId('java') {
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
}
32 changes: 32 additions & 0 deletions centralized-sampling-tests/collector-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
extensions:
health_check:
awsproxy:
local_mode: true
region: 'us-west-2'
endpoint: 0.0.0.0:2000

receivers:
otlp:
protocols:
grpc:
http:

exporters:
logging:
loglevel: debug
awsxray:
local_mode: true
region: 'us-west-2'

service:
pipelines:
traces:
receivers: [otlp]
exporters: [logging, awsxray]
metrics:
receivers: [otlp]
exporters: [logging]
extensions: [health_check, awsproxy]
telemetry:
logs:
level: "debug"
53 changes: 53 additions & 0 deletions centralized-sampling-tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
version: "3.7"
services:
otel:
image: amazon/aws-otel-collector:latest
command: --config /config/collector-config.yml
environment:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_SESSION_TOKEN
volumes:
- .:/config
- /tmp/awscreds:/tmp/awscreds
ports:
- '4317:4317'
- '2000:2000'

app:
build:
context: ./sample-apps/spring-boot
depends_on:
- otel
environment:
- INSTANCE_ID
- LISTEN_ADDRESS=0.0.0.0:8080
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_SESSION_TOKEN
- OTEL_RESOURCE_ATTRIBUTES=service.name=aws-otel-integ-test
- OTEL_EXPORTER_OTLP_ENDPOINT=http://otel:4317
- XRAY_ENDPOINT=http://otel:2000
- AWS_REGION=us-west-2
- OTEL_JAVAAGENT_DEBUG=true
- OTEL_METRICS_EXPORTER=otlp
volumes:
- /tmp/awscreds:/tmp/awscreds
ports:
- '8080:8080'

integration-tests:
build:
context: ./integration-tests
depends_on:
- otel
- app
environment:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_SESSION_TOKEN
- AWS_REGION=us-west-2
- XRAY_ENDPOINT=http://otel:2000
- TARGET_ADDRESS=http://app:8080
volumes:
- /tmp/awscreds:/tmp/awscreds
32 changes: 32 additions & 0 deletions centralized-sampling-tests/example-collector-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
extensions:
health_check:
awsproxy:
local_mode: true
region: 'us-west-2'
endpoint: 0.0.0.0:2000

receivers:
otlp:
protocols:
grpc:
http:

exporters:
logging:
loglevel: debug
awsxray:
local_mode: true
region: 'us-west-2'

service:
pipelines:
traces:
receivers: [otlp]
exporters: [logging, awsxray]
metrics:
receivers: [otlp]
exporters: [logging]
extensions: [health_check, awsproxy]
telemetry:
logs:
level: "debug"
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit 0088e56

Please sign in to comment.