Skip to content

Commit abd90f6

Browse files
committed
Rename request ID to correlation ID
1 parent 5bada1e commit abd90f6

File tree

20 files changed

+199
-59
lines changed

20 files changed

+199
-59
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ request adding CHANGELOG notes for breaking (!) changes and possibly other secti
4141

4242
### Deprecations
4343

44+
* The property `polaris.log.request-id-header-name` has been renamed to
45+
`polaris.correlation-id.header-name`; the old name is still supported for backwards compatibility,
46+
but will generate a warning.
47+
4448
### Fixes
4549

4650
### Commits

helm/polaris/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ ct install --namespace polaris --charts ./helm/polaris
247247
| livenessProbe.successThreshold | int | `1` | Minimum consecutive successes for the probe to be considered successful after having failed. Minimum value is 1. |
248248
| livenessProbe.terminationGracePeriodSeconds | int | `30` | Optional duration in seconds the pod needs to terminate gracefully upon probe failure. Minimum value is 1. |
249249
| livenessProbe.timeoutSeconds | int | `10` | Number of seconds after which the probe times out. Minimum value is 1. |
250-
| logging | object | `{"categories":{"org.apache.iceberg.rest":"INFO","org.apache.polaris":"INFO"},"console":{"enabled":true,"format":"%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] [%X{requestId},%X{realmId}] [%X{traceId},%X{parentId},%X{spanId},%X{sampled}] (%t) %s%e%n","json":false,"threshold":"ALL"},"file":{"enabled":false,"fileName":"polaris.log","format":"%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] [%X{requestId},%X{realmId}] [%X{traceId},%X{parentId},%X{spanId},%X{sampled}] (%t) %s%e%n","json":false,"logsDir":"/deployments/logs","rotation":{"fileSuffix":null,"maxBackupIndex":5,"maxFileSize":"100Mi"},"storage":{"className":"standard","selectorLabels":{},"size":"512Gi"},"threshold":"ALL"},"level":"INFO","mdc":{},"requestIdHeaderName":"Polaris-Request-Id"}` | Logging configuration. |
250+
| logging | object | `{"categories":{"org.apache.iceberg.rest":"INFO","org.apache.polaris":"INFO"},"console":{"enabled":true,"format":"%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] [%X{requestId},%X{realmId}] [%X{traceId},%X{parentId},%X{spanId},%X{sampled}] (%t) %s%e%n","json":false,"threshold":"ALL"},"file":{"enabled":false,"fileName":"polaris.log","format":"%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] [%X{requestId},%X{realmId}] [%X{traceId},%X{parentId},%X{spanId},%X{sampled}] (%t) %s%e%n","json":false,"logsDir":"/deployments/logs","rotation":{"fileSuffix":null,"maxBackupIndex":5,"maxFileSize":"100Mi"},"storage":{"className":"standard","selectorLabels":{},"size":"512Gi"},"threshold":"ALL"},"level":"INFO","mdc":{},"requestId":{"generator":{"type":"default"},"headerName":"Polaris-Request-Id"}}` | Logging configuration. |
251251
| logging.categories | object | `{"org.apache.iceberg.rest":"INFO","org.apache.polaris":"INFO"}` | Configuration for specific log categories. |
252252
| logging.console | object | `{"enabled":true,"format":"%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] [%X{requestId},%X{realmId}] [%X{traceId},%X{parentId},%X{spanId},%X{sampled}] (%t) %s%e%n","json":false,"threshold":"ALL"}` | Configuration for the console appender. |
253253
| logging.console.enabled | bool | `true` | Whether to enable the console appender. |
@@ -271,7 +271,9 @@ ct install --namespace polaris --charts ./helm/polaris
271271
| logging.file.threshold | string | `"ALL"` | The log level of the file appender. |
272272
| logging.level | string | `"INFO"` | The log level of the root category, which is used as the default log level for all categories. |
273273
| logging.mdc | object | `{}` | Configuration for MDC (Mapped Diagnostic Context). Values specified here will be added to the log context of all incoming requests and can be used in log patterns. |
274-
| logging.requestIdHeaderName | string | `"Polaris-Request-Id"` | The header name to use for the request ID. |
274+
| logging.requestId | object | `{"generator":{"type":"default"},"headerName":"Polaris-Request-Id"}` | Configuration for request IDs. |
275+
| logging.requestId.generator.type | string | `"default"` | The type of the request ID generator to use. |
276+
| logging.requestId.headerName | string | `"Polaris-Request-Id"` | The name of the request header that contains the request ID. If no such header is found, a new ID will be generated using the configured generator. |
275277
| managementService | object | `{"annotations":{},"clusterIP":"None","externalTrafficPolicy":null,"internalTrafficPolicy":null,"ports":[{"name":"polaris-mgmt","nodePort":null,"port":8182,"protocol":null,"targetPort":null}],"sessionAffinity":null,"trafficDistribution":null,"type":"ClusterIP"}` | Management service settings. These settings are used to configure liveness and readiness probes, and to configure the dedicated headless service that will expose health checks and metrics, e.g. for metrics scraping and service monitoring. |
276278
| managementService.annotations | object | `{}` | Annotations to add to the service. |
277279
| managementService.clusterIP | string | `"None"` | By default, the management service is headless, i.e. it does not have a cluster IP. This is generally the right option for exposing health checks and metrics, e.g. for metrics scraping and service monitoring. |

helm/polaris/templates/configmap.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ data:
165165
{{- range $k, $v := $categories -}}
166166
{{- $_ = set $map (printf "quarkus.log.category.\"%s\".level" $k) $v -}}
167167
{{- end -}}
168-
{{- $_ = set $map "polaris.log.request-id-header-name" .Values.logging.requestIdHeaderName -}}
169168
{{- $mdc := dict -}}
170169
{{- list .Values.logging.mdc "" $mdc | include "polaris.mergeConfigTree" -}}
171170
{{- range $k, $v := $mdc -}}
@@ -208,6 +207,10 @@ data:
208207
{{- $_ = set $map "quarkus.micrometer.enabled" "false" -}}
209208
{{- end -}}
210209
210+
{{- /* Correlation ID */ -}}
211+
{{- $_ = set $map "polaris.correlation-id.header-name" .Values.correlationId.headerName -}}
212+
{{- $_ = set $map "polaris.correlation-id.generator.type" .Values.correlationId.generator.type -}}
213+
211214
{{- /* Advanced Configuration (must be done last since it can override any of the settings above) */ -}}
212215
{{- list .Values.advancedConfig "" $map | include "polaris.mergeConfigTree" -}}
213216

helm/polaris/values.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,6 @@ serviceMonitor:
442442
logging:
443443
# -- The log level of the root category, which is used as the default log level for all categories.
444444
level: INFO
445-
# -- The header name to use for the request ID.
446-
requestIdHeaderName: Polaris-Request-Id
447445
# -- Configuration for the console appender.
448446
console:
449447
# -- Whether to enable the console appender.
@@ -518,6 +516,16 @@ realmContext:
518516
realms:
519517
- POLARIS
520518

519+
# -- Configuration for correlation IDs.
520+
correlationId:
521+
# -- The name of the header that contains the correlation ID.
522+
# If a request does not contain this header, it will be assigned a new correlation ID generated
523+
# using the configured generator. All responses will include the correlation ID in this header.
524+
headerName: Polaris-Request-Id
525+
generator:
526+
# -- The type of the correlation ID generator to use.
527+
type: default
528+
521529
# -- Polaris features configuration.
522530
features:
523531
# -- Features to enable or disable globally. If a feature is not present in the map, the default

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ quarkus.oidc.tenant-enabled=false
8989
# quarkus.oidc.idp1.auth-server-url=https://auth.example.com/realms/polaris2
9090
# quarkus.oidc.idp1.client-id=polaris2
9191

92-
# quarkus.otel.sdk.disabled is set to `true` by default to avoid spuriour errors about
92+
# OpenTelemetry settings.
93+
# quarkus.otel.sdk.disabled is set to `true` by default to avoid spurious errors about
9394
# trace collector connections being impossible to establish. This setting can be enabled
9495
# at runtime after configuring other OTel properties for proper trace data collection.
9596
quarkus.otel.sdk.disabled=true
@@ -106,6 +107,9 @@ quarkus.fault-tolerance.global.timeout.enabled=false
106107
# quarkus.fault-tolerance.global.timeout.unit=minutes
107108
# quarkus.fault-tolerance.global.timeout.value=10
108109

110+
polaris.correlation-id.header-name=Polaris-Request-Id
111+
polaris.correlation-id.generator.type=default
112+
109113
polaris.realm-context.type=default
110114
polaris.realm-context.realms=POLARIS
111115
polaris.realm-context.header-name=Polaris-Realm
@@ -137,7 +141,6 @@ polaris.event-listener.type=no-op
137141
# polaris.event-listener.persistence-in-memory-buffer.buffer-time=5000ms
138142
# polaris.event-listener.persistence-in-memory-buffer.max-buffer-size=5
139143

140-
polaris.log.request-id-header-name=Polaris-Request-Id
141144
# polaris.log.mdc.aid=polaris
142145
# polaris.log.mdc.sid=polaris-service
143146

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.correlation-id.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/FilterPriorities.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import jakarta.ws.rs.Priorities;
2222

2323
public final class FilterPriorities {
24-
public static final int REQUEST_ID_FILTER = Priorities.AUTHENTICATION - 101;
25-
public static final int REALM_CONTEXT_FILTER = REQUEST_ID_FILTER + 1;
24+
public static final int CORRELATION_ID_FILTER = Priorities.AUTHENTICATION - 101;
25+
public static final int REALM_CONTEXT_FILTER = CORRELATION_ID_FILTER + 1;
2626
public static final int RATE_LIMITER_FILTER = Priorities.USER;
2727
public static final int MDC_FILTER = REALM_CONTEXT_FILTER + 1;
2828
public static final int TRACING_FILTER = REALM_CONTEXT_FILTER + 2;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
import org.apache.polaris.service.context.RealmContextConfiguration;
7272
import org.apache.polaris.service.context.RealmContextFilter;
7373
import org.apache.polaris.service.context.RealmContextResolver;
74+
import org.apache.polaris.service.correlation.CorrelationIdConfiguration;
75+
import org.apache.polaris.service.correlation.CorrelationIdGenerator;
7476
import org.apache.polaris.service.credentials.PolarisCredentialManagerConfiguration;
7577
import org.apache.polaris.service.events.PolarisEventListenerConfiguration;
7678
import org.apache.polaris.service.events.listeners.PolarisEventListener;
@@ -402,6 +404,14 @@ public PolarisCredentialManager polarisCredentialManager(
402404
return credentialManagers.select(Identifier.Literal.of(config.type())).get();
403405
}
404406

407+
@Produces
408+
@ApplicationScoped
409+
public CorrelationIdGenerator correlationIdGenerator(
410+
CorrelationIdConfiguration config,
411+
@Any Instance<CorrelationIdGenerator> correlationIdGenerators) {
412+
return correlationIdGenerators.select(Identifier.Literal.of(config.generator().type())).get();
413+
}
414+
405415
public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) {
406416
executor.close();
407417
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.correlation;
20+
21+
import io.smallrye.config.ConfigMapping;
22+
23+
@ConfigMapping(prefix = "polaris.correlation-id")
24+
public interface CorrelationIdConfiguration {
25+
26+
/**
27+
* The name of the header that contains the correlation ID.
28+
*
29+
* <p>If a request does not contain this header, it will be assigned a new correlation ID
30+
* generated using the configured {@link #generator()}.
31+
*
32+
* <p>All responses will include the correlation ID in this header.
33+
*/
34+
String headerName();
35+
36+
/**
37+
* The correlation ID generator to use, when a request does not contain the {@link #headerName()}.
38+
*/
39+
Generator generator();
40+
41+
interface Generator {
42+
43+
/**
44+
* The type of the correlation ID generator. Must be a registered {@link CorrelationIdGenerator}
45+
* identifier.
46+
*/
47+
String type();
48+
}
49+
}

runtime/service/src/main/java/org/apache/polaris/service/tracing/RequestIdFilter.java renamed to runtime/service/src/main/java/org/apache/polaris/service/correlation/CorrelationIdFilter.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.apache.polaris.service.tracing;
19+
package org.apache.polaris.service.correlation;
2020

2121
import io.smallrye.mutiny.Uni;
2222
import jakarta.inject.Inject;
@@ -26,39 +26,38 @@
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;
3332
import org.slf4j.LoggerFactory;
3433

35-
public class RequestIdFilter {
34+
public class CorrelationIdFilter {
3635

37-
public static final String REQUEST_ID_KEY = "requestId";
36+
public static final String CORRELATION_ID_KEY = "requestId";
3837

39-
private static final Logger LOGGER = LoggerFactory.getLogger(RequestIdFilter.class);
38+
private static final Logger LOGGER = LoggerFactory.getLogger(CorrelationIdFilter.class);
4039

41-
@Inject LoggingConfiguration loggingConfiguration;
42-
@Inject RequestIdGenerator requestIdGenerator;
40+
@Inject CorrelationIdConfiguration correlationIdConfiguration;
41+
@Inject CorrelationIdGenerator correlationIdGenerator;
4342

44-
@ServerRequestFilter(preMatching = true, priority = FilterPriorities.REQUEST_ID_FILTER)
43+
@ServerRequestFilter(preMatching = true, priority = FilterPriorities.CORRELATION_ID_FILTER)
4544
public Uni<Response> assignRequestId(ContainerRequestContext rc) {
46-
var requestId = rc.getHeaderString(loggingConfiguration.requestIdHeaderName());
45+
var requestId = rc.getHeaderString(correlationIdConfiguration.headerName());
4746
return (requestId != null
4847
? Uni.createFrom().item(requestId)
49-
: requestIdGenerator.generateRequestId(rc))
48+
: correlationIdGenerator.generateCorrelationId(rc))
5049
.onItem()
51-
.invoke(id -> rc.setProperty(REQUEST_ID_KEY, id))
50+
.invoke(id -> rc.setProperty(CORRELATION_ID_KEY, id))
5251
.onItemOrFailure()
5352
.transform((id, error) -> error == null ? null : errorResponse(error));
5453
}
5554

5655
@ServerResponseFilter
5756
public void addResponseHeader(
5857
ContainerRequestContext request, ContainerResponseContext response) {
59-
String requestId = (String) request.getProperty(REQUEST_ID_KEY);
58+
String requestId = (String) request.getProperty(CORRELATION_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(correlationIdConfiguration.headerName(), requestId);
6261
}
6362
}
6463

0 commit comments

Comments
 (0)