-
Notifications
You must be signed in to change notification settings - Fork 91
Add E2E test verifying OTEL tracing across Zenko services #2378
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
Open
delthas
wants to merge
1
commit into
development/2.15
Choose a base branch
from
improvement/ZENKO-5258/otel-tracing-e2e-test
base: development/2.15
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+253
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| --- | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: jaeger | ||
| namespace: default | ||
| labels: | ||
| app: jaeger | ||
| spec: | ||
| replicas: 1 | ||
| selector: | ||
| matchLabels: | ||
| app: jaeger | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: jaeger | ||
| spec: | ||
| containers: | ||
| - name: jaeger | ||
| image: jaegertracing/all-in-one:1.76.0 | ||
| resources: | ||
| requests: | ||
| cpu: 100m | ||
| memory: 128Mi | ||
| limits: | ||
| memory: 512Mi | ||
| env: | ||
| - name: COLLECTOR_OTLP_ENABLED | ||
| value: "true" | ||
| - name: MEMORY_MAX_TRACES | ||
| value: "10000" | ||
| ports: | ||
| - containerPort: 16686 | ||
| name: query | ||
| - containerPort: 4317 | ||
| name: otlp-grpc | ||
| - containerPort: 4318 | ||
| name: otlp-http | ||
| readinessProbe: | ||
| httpGet: | ||
| path: / | ||
| port: 16686 | ||
| initialDelaySeconds: 5 | ||
| periodSeconds: 5 | ||
| --- | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| name: jaeger | ||
| namespace: default | ||
| spec: | ||
| selector: | ||
| app: jaeger | ||
| ports: | ||
| - name: query | ||
| port: 16686 | ||
| targetPort: 16686 | ||
| - name: otlp-grpc | ||
| port: 4317 | ||
| targetPort: 4317 | ||
| - name: otlp-http | ||
| port: 4318 | ||
| targetPort: 4318 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| @2.15.0 | ||
| @PreMerge | ||
| Feature: OpenTelemetry Tracing | ||
| Even when global sampling is disabled, a request carrying a W3C | ||
| traceparent header from a trusted (in-cluster) source must produce | ||
| a trace spanning all the Zenko services it touches. | ||
|
|
||
| Scenario: PutObject with injected traceparent produces a trace spanning cloudserver and vault | ||
| Given a "Non versioned" bucket | ||
| When I put an object with an injected traceparent | ||
| Then the injected trace should be found in Jaeger | ||
| And the trace should contain spans from service "connector-cloudserver" | ||
| And the trace should contain spans from service "connector-vault" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| import { Then, When } from '@cucumber/cucumber'; | ||
| import { strict as assert } from 'assert'; | ||
| import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3'; | ||
| import { randomBytes } from 'crypto'; | ||
| import { Identity, Utils } from 'cli-testing'; | ||
| import Zenko from 'world/Zenko'; | ||
|
|
||
| const JAEGER_POLL_TIMEOUT = 30000; | ||
| const JAEGER_POLL_INTERVAL = 2000; | ||
| const TRACED_OBJECT_KEY = 'otel-trace-test-object'; | ||
|
|
||
| interface JaegerTrace { | ||
| traceID: string; | ||
| spans: { processID: string }[]; | ||
| processes: Record<string, { serviceName: string }>; | ||
| } | ||
|
|
||
| function generateTraceContext(): { traceparent: string; traceId: string } { | ||
| const traceId = randomBytes(16).toString('hex'); | ||
| const spanId = randomBytes(8).toString('hex'); | ||
| return { traceparent: `00-${traceId}-${spanId}-01`, traceId }; | ||
| } | ||
|
|
||
| function buildInternalS3Client(endpoint: string, traceparent: string): S3Client { | ||
| const credentials = Identity.getCurrentCredentials(); | ||
| const client = new S3Client({ | ||
| region: 'us-east-1', | ||
| endpoint, | ||
| credentials: { | ||
| accessKeyId: credentials.accessKeyId, | ||
| secretAccessKey: credentials.secretAccessKey, | ||
| }, | ||
| forcePathStyle: true, | ||
| }); | ||
| // traceparent is not part of any SigV4 signed-header set, so injecting at | ||
| // the 'build' step (pre-signing) does not invalidate the signature. | ||
| client.middlewareStack.add( | ||
| next => async args => { | ||
| const request = args.request as { headers: Record<string, string> }; | ||
| request.headers.traceparent = traceparent; | ||
| return next(args); | ||
| }, | ||
| { step: 'build', name: 'injectTraceparent' }, | ||
| ); | ||
| return client; | ||
| } | ||
|
|
||
| async function fetchTraceById(endpoint: string, traceId: string): Promise<JaegerTrace | null> { | ||
| const response = await fetch(`${endpoint}/api/traces/${traceId}`, { | ||
| signal: AbortSignal.timeout(5000), | ||
| }); | ||
| if (response.status === 404) { | ||
| return null; | ||
| } | ||
| if (!response.ok) { | ||
| throw new Error(`Jaeger query returned HTTP ${response.status}`); | ||
| } | ||
| const body = await response.json() as { data: JaegerTrace[] }; | ||
| return body.data?.[0] ?? null; | ||
| } | ||
|
|
||
| async function pollJaegerForTrace( | ||
| endpoint: string, | ||
| traceId: string, | ||
| timeoutMs = JAEGER_POLL_TIMEOUT, | ||
| intervalMs = JAEGER_POLL_INTERVAL, | ||
| ): Promise<JaegerTrace> { | ||
| const deadline = Date.now() + timeoutMs; | ||
| let lastError: Error | null = null; | ||
|
|
||
| while (Date.now() < deadline) { | ||
| try { | ||
| const trace = await fetchTraceById(endpoint, traceId); | ||
| if (trace) { | ||
| return trace; | ||
| } | ||
| } catch (err) { | ||
| lastError = err as Error; | ||
| } | ||
| await Utils.sleep(intervalMs); | ||
| } | ||
|
|
||
| throw new Error( | ||
| `pollJaegerForTrace timed out after ${timeoutMs}ms waiting for trace ${traceId}` + | ||
| `${lastError ? `: ${lastError.message}` : ''}`, | ||
| ); | ||
| } | ||
|
|
||
| function traceHasSpansFromService(trace: JaegerTrace, serviceName: string): boolean { | ||
| const processIds = Object.entries(trace.processes) | ||
| .filter(([, proc]) => proc.serviceName === serviceName) | ||
| .map(([id]) => id); | ||
|
|
||
| return trace.spans.some(span => processIds.includes(span.processID)); | ||
| } | ||
|
|
||
| When('I put an object with an injected traceparent', | ||
| async function (this: Zenko) { | ||
| const endpoint = this.parameters.InternalCloudserverEndpoint; | ||
| assert.ok(endpoint, 'InternalCloudserverEndpoint missing from world parameters'); | ||
| const bucketName = this.getSaved<string>('bucketName'); | ||
| assert.ok(bucketName, 'No bucketName saved from a previous step'); | ||
|
|
||
| const { traceparent, traceId } = generateTraceContext(); | ||
| const client = buildInternalS3Client(endpoint, traceparent); | ||
| await client.send(new PutObjectCommand({ | ||
| Bucket: bucketName, | ||
| Key: TRACED_OBJECT_KEY, | ||
| Body: 'otel-trace-payload', | ||
| })); | ||
|
|
||
| this.addToSaved('jaegerTraceId', traceId); | ||
| }, | ||
| ); | ||
|
|
||
| Then('the injected trace should be found in Jaeger', | ||
| { timeout: JAEGER_POLL_TIMEOUT + 10000 }, | ||
| async function (this: Zenko) { | ||
| const endpoint = this.parameters.JaegerQueryEndpoint; | ||
| assert.ok(endpoint, 'JaegerQueryEndpoint missing from world parameters'); | ||
| const traceId = this.getSaved<string>('jaegerTraceId'); | ||
| assert.ok(traceId, 'No jaegerTraceId saved from a previous step'); | ||
|
|
||
| const trace = await pollJaegerForTrace(endpoint, traceId); | ||
| this.addToSaved('jaegerTrace', trace); | ||
| }, | ||
| ); | ||
|
|
||
| Then('the trace should contain spans from service {string}', | ||
| async function (this: Zenko, service: string) { | ||
| const trace = this.getSaved<JaegerTrace>('jaegerTrace'); | ||
| assert.ok(trace, 'No trace saved from the previous step'); | ||
|
|
||
| assert.ok( | ||
| traceHasSpansFromService(trace, service), | ||
| `Trace ${trace.traceID} does not contain spans from service "${service}". ` + | ||
| `Services in trace: ${[...new Set( | ||
| Object.values(trace.processes).map(p => p.serviceName), | ||
| )].join(', ')}`, | ||
| ); | ||
| }, | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.