Skip to content

Commit 8d8ac7c

Browse files
committed
Move request ID generator configuration to polaris.tracing
1 parent d2a607a commit 8d8ac7c

File tree

9 files changed

+126
-8
lines changed

9 files changed

+126
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ request adding CHANGELOG notes for breaking (!) changes and possibly other secti
5353
### Deprecations
5454

5555
* The property `polaris.active-roles-provider.type` is deprecated and has no effect anymore.
56+
* The property `polaris.log.request-id-header-name` has been renamed to
57+
`polaris.tracing.request-id-generator.header-name`; the old name is still supported for backwards
58+
compatibility, but will generate a warning.
5659

5760
### Fixes
5861

runtime/defaults/src/main/resources/application.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ polaris.event-listener.type=no-op
137137
# polaris.event-listener.persistence-in-memory-buffer.buffer-time=5000ms
138138
# polaris.event-listener.persistence-in-memory-buffer.max-buffer-size=5
139139

140-
polaris.log.request-id-header-name=Polaris-Request-Id
141140
# polaris.log.mdc.aid=polaris
142141
# polaris.log.mdc.sid=polaris-service
143142

@@ -146,6 +145,9 @@ polaris.metrics.tags.application=Polaris
146145
# polaris.metrics.tags.environment=prod
147146
# polaris.metrics.tags.region=us-west-2
148147

148+
polaris.tracing.request-id-generator.type=default
149+
polaris.tracing.request-id-generator.header-name=Polaris-Request-Id
150+
149151
# polaris.tasks.max-concurrent-tasks=100
150152
# polaris.tasks.max-queued-tasks=1000
151153

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.polaris.service.config;
21+
22+
import io.smallrye.config.RelocateConfigSourceInterceptor;
23+
import org.slf4j.Logger;
24+
import org.slf4j.LoggerFactory;
25+
26+
public class ConfigRelocationInterceptor extends RelocateConfigSourceInterceptor {
27+
28+
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigRelocationInterceptor.class);
29+
30+
public ConfigRelocationInterceptor() {
31+
super(ConfigRelocationInterceptor::applyRelocations);
32+
}
33+
34+
private static String applyRelocations(String name) {
35+
if (name.equals("polaris.log.request-id-header-name")) {
36+
String replacement = "polaris.tracing.request-id-generator.header-name";
37+
LOGGER.warn("Property '{}' is deprecated, use '{}' instead", name, replacement);
38+
return replacement;
39+
}
40+
return name;
41+
}
42+
}

runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
import org.apache.polaris.service.storage.aws.S3AccessConfig;
8282
import org.apache.polaris.service.storage.aws.StsClientsPool;
8383
import org.apache.polaris.service.task.TaskHandlerConfiguration;
84+
import org.apache.polaris.service.tracing.RequestIdGenerator;
85+
import org.apache.polaris.service.tracing.TracingConfiguration;
8486
import org.eclipse.microprofile.context.ManagedExecutor;
8587
import org.eclipse.microprofile.context.ThreadContext;
8688
import org.slf4j.Logger;
@@ -392,6 +394,15 @@ public OidcTenantResolver oidcTenantResolver(
392394
return resolvers.select(Identifier.Literal.of(config.tenantResolver())).get();
393395
}
394396

397+
@Produces
398+
@ApplicationScoped
399+
public RequestIdGenerator requestIdGenerator(
400+
TracingConfiguration config, @Any Instance<RequestIdGenerator> requestIdGenerators) {
401+
return requestIdGenerators
402+
.select(Identifier.Literal.of(config.requestIdGenerator().type()))
403+
.get();
404+
}
405+
395406
public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) {
396407
executor.close();
397408
}

runtime/service/src/main/java/org/apache/polaris/service/logging/LoggingConfiguration.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
@ConfigMapping(prefix = "polaris.log")
2525
public interface LoggingConfiguration {
2626

27-
/** The name of the header that contains the request ID. */
28-
String requestIdHeaderName();
29-
3027
/** Additional MDC values to include in the log context. */
3128
Map<String, String> mdc();
3229
}

runtime/service/src/main/java/org/apache/polaris/service/tracing/DefaultRequestIdGenerator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.apache.polaris.service.tracing;
2121

22+
import io.smallrye.common.annotation.Identifier;
2223
import io.smallrye.mutiny.Uni;
2324
import jakarta.annotation.Nonnull;
2425
import jakarta.enterprise.context.ApplicationScoped;
@@ -37,6 +38,7 @@
3738
* reset to 1.
3839
*/
3940
@ApplicationScoped
41+
@Identifier("default")
4042
public class DefaultRequestIdGenerator implements RequestIdGenerator {
4143

4244
record RequestId(UUID uuid, long counter) {

runtime/service/src/main/java/org/apache/polaris/service/tracing/RequestIdFilter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import jakarta.ws.rs.core.Response;
2727
import org.apache.iceberg.rest.responses.ErrorResponse;
2828
import org.apache.polaris.service.config.FilterPriorities;
29-
import org.apache.polaris.service.logging.LoggingConfiguration;
3029
import org.jboss.resteasy.reactive.server.ServerRequestFilter;
3130
import org.jboss.resteasy.reactive.server.ServerResponseFilter;
3231
import org.slf4j.Logger;
@@ -38,12 +37,12 @@ public class RequestIdFilter {
3837

3938
private static final Logger LOGGER = LoggerFactory.getLogger(RequestIdFilter.class);
4039

41-
@Inject LoggingConfiguration loggingConfiguration;
40+
@Inject TracingConfiguration tracingConfiguration;
4241
@Inject RequestIdGenerator requestIdGenerator;
4342

4443
@ServerRequestFilter(preMatching = true, priority = FilterPriorities.REQUEST_ID_FILTER)
4544
public Uni<Response> assignRequestId(ContainerRequestContext rc) {
46-
var requestId = rc.getHeaderString(loggingConfiguration.requestIdHeaderName());
45+
var requestId = rc.getHeaderString(tracingConfiguration.requestIdGenerator().headerName());
4746
return (requestId != null
4847
? Uni.createFrom().item(requestId)
4948
: requestIdGenerator.generateRequestId(rc))
@@ -58,7 +57,7 @@ public void addResponseHeader(
5857
ContainerRequestContext request, ContainerResponseContext response) {
5958
String requestId = (String) request.getProperty(REQUEST_ID_KEY);
6059
if (requestId != null) { // can be null if request ID generation fails
61-
response.getHeaders().add(loggingConfiguration.requestIdHeaderName(), requestId);
60+
response.getHeaders().add(tracingConfiguration.requestIdGenerator().headerName(), requestId);
6261
}
6362
}
6463

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.polaris.service.tracing;
20+
21+
import io.smallrye.config.ConfigMapping;
22+
23+
@ConfigMapping(prefix = "polaris.tracing")
24+
public interface TracingConfiguration {
25+
26+
RequestIdGenerator requestIdGenerator();
27+
28+
interface RequestIdGenerator {
29+
30+
/**
31+
* The type of the request ID generator. Must be a registered {@link RequestIdGenerator}
32+
* identifier.
33+
*/
34+
String type();
35+
36+
/**
37+
* The name of the request header that contains the request ID. Used by the default request ID
38+
* generator.
39+
*/
40+
String headerName();
41+
}
42+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
org.apache.polaris.service.config.ConfigRelocationInterceptor

0 commit comments

Comments
 (0)