-
Notifications
You must be signed in to change notification settings - Fork 328
Add test for TracingFilter #2847
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
adutra
wants to merge
2
commits into
apache:main
Choose a base branch
from
adutra:tracing-filter-test
base: main
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.
+119
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
117 changes: 117 additions & 0 deletions
117
runtime/service/src/test/java/org/apache/polaris/service/tracing/TracingFilterTest.java
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,117 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.polaris.service.tracing; | ||
|
|
||
| import static io.opentelemetry.api.common.AttributeKey.stringKey; | ||
| import static io.restassured.RestAssured.given; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.awaitility.Awaitility.await; | ||
|
|
||
| import io.opentelemetry.api.common.AttributeKey; | ||
| import io.opentelemetry.api.trace.SpanContext; | ||
| import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter; | ||
| import io.opentelemetry.sdk.trace.data.SpanData; | ||
| import io.quarkus.test.common.http.TestHTTPEndpoint; | ||
| import io.quarkus.test.junit.QuarkusTest; | ||
| import io.quarkus.test.junit.QuarkusTestProfile; | ||
| import io.quarkus.test.junit.TestProfile; | ||
| import io.restassured.http.ContentType; | ||
| import jakarta.enterprise.inject.Produces; | ||
| import jakarta.inject.Inject; | ||
| import jakarta.inject.Singleton; | ||
| import java.time.Duration; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.apache.polaris.service.catalog.api.IcebergRestOAuth2Api; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| @QuarkusTest | ||
| @TestProfile(TracingFilterTest.Profile.class) | ||
| @TestHTTPEndpoint(IcebergRestOAuth2Api.class) | ||
| public class TracingFilterTest { | ||
|
|
||
| public static class Profile implements QuarkusTestProfile { | ||
|
|
||
| @Produces | ||
| @Singleton | ||
| InMemorySpanExporter inMemorySpanExporter() { | ||
| return InMemorySpanExporter.create(); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, String> getConfigOverrides() { | ||
| return Map.of("quarkus.otel.sdk.disabled", "false"); | ||
| } | ||
| } | ||
|
|
||
| @Inject InMemorySpanExporter inMemorySpanExporter; | ||
|
|
||
| @Test | ||
| void testW3CTraceContextPropagation() { | ||
|
|
||
| // Emulate an incoming request with a W3C trace context | ||
| // Example taken from: | ||
| // https://www.w3.org/TR/trace-context/#traceparent-header-field-values | ||
| String traceId = "4bf92f3577b34da6a3ce929d0e0e4736"; | ||
| String spanId = "00f067aa0ba902b7"; | ||
| String traceparent = "00-" + traceId + "-" + spanId + "-01"; | ||
| String rojoState = spanId; | ||
| String congoState = "t61rcWkgMzE"; | ||
| String tracestate = "rojo=" + rojoState + ",congo=" + congoState; | ||
|
|
||
| given() | ||
| .contentType(ContentType.URLENC) | ||
| .formParam("grant_type", "client_credentials") | ||
| .formParam("scope", "PRINCIPAL_ROLE:ALL") | ||
| .formParam("client_id", "test-admin") | ||
| .formParam("client_secret", "test-secret") | ||
| // W3C headers | ||
| .header("traceparent", traceparent) | ||
| .header("tracestate", tracestate) | ||
| // Polaris request ID | ||
| .header("X-Request-ID", "12345") | ||
| .when() | ||
| .post() | ||
| .then() | ||
| .statusCode(200) | ||
| .header("X-Request-ID", "12345"); | ||
|
|
||
| List<SpanData> spans = | ||
| await() | ||
| .atMost(Duration.ofSeconds(30)) | ||
| .until(inMemorySpanExporter::getFinishedSpanItems, sp -> !sp.isEmpty()); | ||
|
|
||
| SpanData span = spans.getFirst(); | ||
|
|
||
| Map<AttributeKey<?>, Object> attributes = span.getAttributes().asMap(); | ||
| assertThat(attributes) | ||
| .containsEntry(stringKey(TracingFilter.REALM_ID_ATTRIBUTE), "POLARIS") | ||
| .containsEntry(stringKey(TracingFilter.REQUEST_ID_ATTRIBUTE), "12345"); | ||
|
|
||
| SpanContext parent = span.getParentSpanContext(); | ||
| assertThat(parent.getTraceId()).isEqualTo(traceId); | ||
| assertThat(parent.getSpanId()).isEqualTo(spanId); | ||
| assertThat(parent.isRemote()).isTrue(); | ||
| assertThat(parent.getTraceFlags().asByte()).isEqualTo((byte) 1); | ||
| assertThat(parent.getTraceState().asMap()) | ||
| .containsEntry("rojo", rojoState) | ||
| .containsEntry("congo", congoState); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
side note: my thinking was to reuse request ID from OTel (e.g. trace ID + span ID). Since we're moving towards "correlation", I think it makes sense to integrate with the existing OTel standard. In that case it should not be necessary to add
REQUEST_ID_ATTRIBUTEto the span, but someone inspecting the response headers would be able to correlate them to the trace.If OTel is present, what is the value of Polaris accepting / generating yet another request ID?
Are we considering the Polaris request ID as a first class feature of the protocol (REST API flowing into Events) as opposed to a "helper" or "observability" feature?
If OTel is not present, we can certainly generate a fresh request ID.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, let's move this conversation to the dev ML:
https://lists.apache.org/thread/bb1qyxjt827t3tomv2xp0s1kovxjsp94