diff --git a/CHANGELOG.md b/CHANGELOG.md index ee808f8dff..d703326397 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,10 @@ request adding CHANGELOG notes for breaking (!) changes and possibly other secti ### Deprecations +* The property `polaris.log.request-id-header-name` is deprecated and has been renamed to + `polaris.correlation-id.header-name`; the old name is still supported for backwards compatibility, + but will generate a warning. + ### Fixes ### Commits diff --git a/helm/polaris/README.md b/helm/polaris/README.md index bbfc8557df..052afa83f4 100644 --- a/helm/polaris/README.md +++ b/helm/polaris/README.md @@ -214,6 +214,9 @@ ct install --namespace polaris --charts ./helm/polaris | configMapLabels | object | `{}` | Additional Labels to apply to polaris configmap. | | containerSecurityContext | object | `{"allowPrivilegeEscalation":false,"capabilities":{"drop":["ALL"]},"runAsNonRoot":true,"runAsUser":10000,"seccompProfile":{"type":"RuntimeDefault"}}` | Security context for the polaris container. See https://kubernetes.io/docs/tasks/configure-pod-container/security-context/. | | containerSecurityContext.runAsUser | int | `10000` | UID 10000 is compatible with Polaris OSS default images; change this if you are using a different image. | +| correlationId | object | `{"generator":{"type":"default"},"headerName":"Polaris-Request-Id"}` | Configuration for correlation IDs. | +| correlationId.generator.type | string | `"default"` | The type of the correlation ID generator to use. | +| correlationId.headerName | string | `"Polaris-Request-Id"` | The name of the header that contains the correlation ID. If a request does not contain this header, it will be assigned a new correlation ID generated using the configured generator. All responses will include the correlation ID in this header. | | cors | object | `{"accessControlAllowCredentials":null,"accessControlMaxAge":null,"allowedHeaders":[],"allowedMethods":[],"allowedOrigins":[],"exposedHeaders":[]}` | Polaris CORS configuration. | | cors.accessControlAllowCredentials | string | `nil` | The `Access-Control-Allow-Credentials` response header. The value of this header will default to `true` if `allowedOrigins` property is set and there is a match with the precise `Origin` header. | | cors.accessControlMaxAge | string | `nil` | The `Access-Control-Max-Age` response header value indicating how long the results of a pre-flight request can be cached. Must be a valid duration. | @@ -247,7 +250,7 @@ ct install --namespace polaris --charts ./helm/polaris | livenessProbe.successThreshold | int | `1` | Minimum consecutive successes for the probe to be considered successful after having failed. Minimum value is 1. | | livenessProbe.terminationGracePeriodSeconds | int | `30` | Optional duration in seconds the pod needs to terminate gracefully upon probe failure. Minimum value is 1. | | livenessProbe.timeoutSeconds | int | `10` | Number of seconds after which the probe times out. Minimum value is 1. | -| 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. | +| 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":{}}` | Logging configuration. | | logging.categories | object | `{"org.apache.iceberg.rest":"INFO","org.apache.polaris":"INFO"}` | Configuration for specific log categories. | | 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. | | logging.console.enabled | bool | `true` | Whether to enable the console appender. | @@ -271,7 +274,6 @@ ct install --namespace polaris --charts ./helm/polaris | logging.file.threshold | string | `"ALL"` | The log level of the file appender. | | logging.level | string | `"INFO"` | The log level of the root category, which is used as the default log level for all categories. | | 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. | -| logging.requestIdHeaderName | string | `"Polaris-Request-Id"` | The header name to use for the request ID. | | 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. | | managementService.annotations | object | `{}` | Annotations to add to the service. | | 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. | diff --git a/helm/polaris/templates/configmap.yaml b/helm/polaris/templates/configmap.yaml index 3e120765a1..08371ccf1d 100644 --- a/helm/polaris/templates/configmap.yaml +++ b/helm/polaris/templates/configmap.yaml @@ -165,7 +165,6 @@ data: {{- range $k, $v := $categories -}} {{- $_ = set $map (printf "quarkus.log.category.\"%s\".level" $k) $v -}} {{- end -}} - {{- $_ = set $map "polaris.log.request-id-header-name" .Values.logging.requestIdHeaderName -}} {{- $mdc := dict -}} {{- list .Values.logging.mdc "" $mdc | include "polaris.mergeConfigTree" -}} {{- range $k, $v := $mdc -}} @@ -208,6 +207,10 @@ data: {{- $_ = set $map "quarkus.micrometer.enabled" "false" -}} {{- end -}} + {{- /* Correlation ID */ -}} + {{- $_ = set $map "polaris.correlation-id.header-name" .Values.correlationId.headerName -}} + {{- $_ = set $map "polaris.correlation-id.generator.type" .Values.correlationId.generator.type -}} + {{- /* Advanced Configuration (must be done last since it can override any of the settings above) */ -}} {{- list .Values.advancedConfig "" $map | include "polaris.mergeConfigTree" -}} diff --git a/helm/polaris/values.yaml b/helm/polaris/values.yaml index 9cecf0a275..b38d9e2a66 100644 --- a/helm/polaris/values.yaml +++ b/helm/polaris/values.yaml @@ -442,8 +442,6 @@ serviceMonitor: logging: # -- The log level of the root category, which is used as the default log level for all categories. level: INFO - # -- The header name to use for the request ID. - requestIdHeaderName: Polaris-Request-Id # -- Configuration for the console appender. console: # -- Whether to enable the console appender. @@ -518,6 +516,16 @@ realmContext: realms: - POLARIS +# -- Configuration for correlation IDs. +correlationId: + # -- The name of the header that contains the correlation ID. + # If a request does not contain this header, it will be assigned a new correlation ID generated + # using the configured generator. All responses will include the correlation ID in this header. + headerName: Polaris-Request-Id + generator: + # -- The type of the correlation ID generator to use. + type: default + # -- Polaris features configuration. features: # -- Features to enable or disable globally. If a feature is not present in the map, the default diff --git a/runtime/defaults/src/main/resources/application.properties b/runtime/defaults/src/main/resources/application.properties index 0358eb4b50..541f6ed147 100644 --- a/runtime/defaults/src/main/resources/application.properties +++ b/runtime/defaults/src/main/resources/application.properties @@ -89,7 +89,8 @@ quarkus.oidc.tenant-enabled=false # quarkus.oidc.idp1.auth-server-url=https://auth.example.com/realms/polaris2 # quarkus.oidc.idp1.client-id=polaris2 -# quarkus.otel.sdk.disabled is set to `true` by default to avoid spuriour errors about +# OpenTelemetry settings. +# quarkus.otel.sdk.disabled is set to `true` by default to avoid spurious errors about # trace collector connections being impossible to establish. This setting can be enabled # at runtime after configuring other OTel properties for proper trace data collection. quarkus.otel.sdk.disabled=true @@ -106,6 +107,9 @@ quarkus.fault-tolerance.global.timeout.enabled=false # quarkus.fault-tolerance.global.timeout.unit=minutes # quarkus.fault-tolerance.global.timeout.value=10 +polaris.correlation-id.header-name=Polaris-Request-Id +polaris.correlation-id.generator.type=default + polaris.realm-context.type=default polaris.realm-context.realms=POLARIS polaris.realm-context.header-name=Polaris-Realm @@ -146,7 +150,6 @@ polaris.event-listener.type=no-op # polaris.event-listener.aws-cloudwatch.region=us-east-1 # polaris.event-listener.aws-cloudwatch.synchronous-mode=false -polaris.log.request-id-header-name=Polaris-Request-Id # polaris.log.mdc.aid=polaris # polaris.log.mdc.sid=polaris-service diff --git a/runtime/service/src/main/java/org/apache/polaris/service/config/ConfigRelocationInterceptor.java b/runtime/service/src/main/java/org/apache/polaris/service/config/ConfigRelocationInterceptor.java new file mode 100644 index 0000000000..ceedf86032 --- /dev/null +++ b/runtime/service/src/main/java/org/apache/polaris/service/config/ConfigRelocationInterceptor.java @@ -0,0 +1,42 @@ +/* + * 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.config; + +import io.smallrye.config.RelocateConfigSourceInterceptor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ConfigRelocationInterceptor extends RelocateConfigSourceInterceptor { + + private static final Logger LOGGER = LoggerFactory.getLogger(ConfigRelocationInterceptor.class); + + public ConfigRelocationInterceptor() { + super(ConfigRelocationInterceptor::applyRelocations); + } + + private static String applyRelocations(String name) { + if (name.equals("polaris.log.request-id-header-name")) { + String replacement = "polaris.correlation-id.header-name"; + LOGGER.warn("Property '{}' is deprecated, use '{}' instead", name, replacement); + return replacement; + } + return name; + } +} diff --git a/runtime/service/src/main/java/org/apache/polaris/service/config/FilterPriorities.java b/runtime/service/src/main/java/org/apache/polaris/service/config/FilterPriorities.java index 5ce1664092..22723f8559 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/config/FilterPriorities.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/config/FilterPriorities.java @@ -21,8 +21,8 @@ import jakarta.ws.rs.Priorities; public final class FilterPriorities { - public static final int REQUEST_ID_FILTER = Priorities.AUTHENTICATION - 101; - public static final int REALM_CONTEXT_FILTER = REQUEST_ID_FILTER + 1; + public static final int CORRELATION_ID_FILTER = Priorities.AUTHENTICATION - 101; + public static final int REALM_CONTEXT_FILTER = CORRELATION_ID_FILTER + 1; public static final int RATE_LIMITER_FILTER = Priorities.USER; public static final int MDC_FILTER = REALM_CONTEXT_FILTER + 1; public static final int TRACING_FILTER = REALM_CONTEXT_FILTER + 2; diff --git a/runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java b/runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java index 6e25dbfc18..b5ae917d1c 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/config/ServiceProducers.java @@ -71,6 +71,8 @@ import org.apache.polaris.service.context.RealmContextConfiguration; import org.apache.polaris.service.context.RealmContextFilter; import org.apache.polaris.service.context.RealmContextResolver; +import org.apache.polaris.service.correlation.CorrelationIdConfiguration; +import org.apache.polaris.service.correlation.CorrelationIdGenerator; import org.apache.polaris.service.credentials.PolarisCredentialManagerConfiguration; import org.apache.polaris.service.events.PolarisEventListenerConfiguration; import org.apache.polaris.service.events.listeners.PolarisEventListener; @@ -402,6 +404,14 @@ public PolarisCredentialManager polarisCredentialManager( return credentialManagers.select(Identifier.Literal.of(config.type())).get(); } + @Produces + @ApplicationScoped + public CorrelationIdGenerator correlationIdGenerator( + CorrelationIdConfiguration config, + @Any Instance correlationIdGenerators) { + return correlationIdGenerators.select(Identifier.Literal.of(config.generator().type())).get(); + } + public void closeTaskExecutor(@Disposes @Identifier("task-executor") ManagedExecutor executor) { executor.close(); } diff --git a/runtime/service/src/main/java/org/apache/polaris/service/correlation/CorrelationIdConfiguration.java b/runtime/service/src/main/java/org/apache/polaris/service/correlation/CorrelationIdConfiguration.java new file mode 100644 index 0000000000..69e7d377f3 --- /dev/null +++ b/runtime/service/src/main/java/org/apache/polaris/service/correlation/CorrelationIdConfiguration.java @@ -0,0 +1,49 @@ +/* + * 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.correlation; + +import io.smallrye.config.ConfigMapping; + +@ConfigMapping(prefix = "polaris.correlation-id") +public interface CorrelationIdConfiguration { + + /** + * The name of the header that contains the correlation ID. + * + *

If a request does not contain this header, it will be assigned a new correlation ID + * generated using the configured {@link #generator()}. + * + *

All responses will include the correlation ID in this header. + */ + String headerName(); + + /** + * The correlation ID generator to use, when a request does not contain the {@link #headerName()}. + */ + Generator generator(); + + interface Generator { + + /** + * The type of the correlation ID generator. Must be a registered {@link CorrelationIdGenerator} + * identifier. + */ + String type(); + } +} diff --git a/runtime/service/src/main/java/org/apache/polaris/service/tracing/RequestIdFilter.java b/runtime/service/src/main/java/org/apache/polaris/service/correlation/CorrelationIdFilter.java similarity index 71% rename from runtime/service/src/main/java/org/apache/polaris/service/tracing/RequestIdFilter.java rename to runtime/service/src/main/java/org/apache/polaris/service/correlation/CorrelationIdFilter.java index 460a732331..0b3d6fb325 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/tracing/RequestIdFilter.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/correlation/CorrelationIdFilter.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.polaris.service.tracing; +package org.apache.polaris.service.correlation; import io.smallrye.mutiny.Uni; import jakarta.inject.Inject; @@ -26,29 +26,28 @@ import jakarta.ws.rs.core.Response; import org.apache.iceberg.rest.responses.ErrorResponse; import org.apache.polaris.service.config.FilterPriorities; -import org.apache.polaris.service.logging.LoggingConfiguration; import org.jboss.resteasy.reactive.server.ServerRequestFilter; import org.jboss.resteasy.reactive.server.ServerResponseFilter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class RequestIdFilter { +public class CorrelationIdFilter { - public static final String REQUEST_ID_KEY = "requestId"; + public static final String CORRELATION_ID_KEY = "requestId"; - private static final Logger LOGGER = LoggerFactory.getLogger(RequestIdFilter.class); + private static final Logger LOGGER = LoggerFactory.getLogger(CorrelationIdFilter.class); - @Inject LoggingConfiguration loggingConfiguration; - @Inject RequestIdGenerator requestIdGenerator; + @Inject CorrelationIdConfiguration correlationIdConfiguration; + @Inject CorrelationIdGenerator correlationIdGenerator; - @ServerRequestFilter(preMatching = true, priority = FilterPriorities.REQUEST_ID_FILTER) + @ServerRequestFilter(preMatching = true, priority = FilterPriorities.CORRELATION_ID_FILTER) public Uni assignRequestId(ContainerRequestContext rc) { - var requestId = rc.getHeaderString(loggingConfiguration.requestIdHeaderName()); - return (requestId != null - ? Uni.createFrom().item(requestId) - : requestIdGenerator.generateRequestId(rc)) + var correlationId = rc.getHeaderString(correlationIdConfiguration.headerName()); + return (correlationId != null + ? Uni.createFrom().item(correlationId) + : correlationIdGenerator.generateCorrelationId(rc)) .onItem() - .invoke(id -> rc.setProperty(REQUEST_ID_KEY, id)) + .invoke(id -> rc.setProperty(CORRELATION_ID_KEY, id)) .onItemOrFailure() .transform((id, error) -> error == null ? null : errorResponse(error)); } @@ -56,9 +55,9 @@ public Uni assignRequestId(ContainerRequestContext rc) { @ServerResponseFilter public void addResponseHeader( ContainerRequestContext request, ContainerResponseContext response) { - String requestId = (String) request.getProperty(REQUEST_ID_KEY); - if (requestId != null) { // can be null if request ID generation fails - response.getHeaders().add(loggingConfiguration.requestIdHeaderName(), requestId); + String correlationId = (String) request.getProperty(CORRELATION_ID_KEY); + if (correlationId != null) { // can be null if request ID generation fails + response.getHeaders().add(correlationIdConfiguration.headerName(), correlationId); } } diff --git a/runtime/service/src/main/java/org/apache/polaris/service/tracing/RequestIdGenerator.java b/runtime/service/src/main/java/org/apache/polaris/service/correlation/CorrelationIdGenerator.java similarity index 76% rename from runtime/service/src/main/java/org/apache/polaris/service/tracing/RequestIdGenerator.java rename to runtime/service/src/main/java/org/apache/polaris/service/correlation/CorrelationIdGenerator.java index 4264f0e381..5c9bb2da56 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/tracing/RequestIdGenerator.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/correlation/CorrelationIdGenerator.java @@ -17,22 +17,22 @@ * under the License. */ -package org.apache.polaris.service.tracing; +package org.apache.polaris.service.correlation; import io.smallrye.mutiny.Uni; import jakarta.ws.rs.container.ContainerRequestContext; /** - * A generator for request IDs. + * A generator for correlation IDs. * - * @see RequestIdFilter + * @see CorrelationIdFilter */ -public interface RequestIdGenerator { +public interface CorrelationIdGenerator { /** - * Generates a new request ID. IDs must be fast to generate and unique. + * Generates a new correlation ID. IDs must be fast to generate and unique. * * @param requestContext The JAX-RS request context */ - Uni generateRequestId(ContainerRequestContext requestContext); + Uni generateCorrelationId(ContainerRequestContext requestContext); } diff --git a/runtime/service/src/main/java/org/apache/polaris/service/tracing/DefaultRequestIdGenerator.java b/runtime/service/src/main/java/org/apache/polaris/service/correlation/DefaultCorrelationIdGenerator.java similarity index 83% rename from runtime/service/src/main/java/org/apache/polaris/service/tracing/DefaultRequestIdGenerator.java rename to runtime/service/src/main/java/org/apache/polaris/service/correlation/DefaultCorrelationIdGenerator.java index 47f17291fa..3e4071586b 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/tracing/DefaultRequestIdGenerator.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/correlation/DefaultCorrelationIdGenerator.java @@ -17,8 +17,9 @@ * under the License. */ -package org.apache.polaris.service.tracing; +package org.apache.polaris.service.correlation; +import io.smallrye.common.annotation.Identifier; import io.smallrye.mutiny.Uni; import jakarta.annotation.Nonnull; import jakarta.enterprise.context.ApplicationScoped; @@ -27,8 +28,8 @@ import java.util.concurrent.atomic.AtomicReference; /** - * Default implementation of {@link RequestIdGenerator}, striking a balance between randomness and - * performance. + * Default implementation of {@link CorrelationIdGenerator}, striking a balance between randomness + * and performance. * *

The IDs generated by this generator are of the form: {@code UUID_COUNTER}. The UUID part is * randomly generated at startup, and the counter is incremented for each request. @@ -37,7 +38,8 @@ * reset to 1. */ @ApplicationScoped -public class DefaultRequestIdGenerator implements RequestIdGenerator { +@Identifier("default") +public class DefaultCorrelationIdGenerator implements CorrelationIdGenerator { record RequestId(UUID uuid, long counter) { @@ -59,7 +61,7 @@ RequestId increment() { final AtomicReference state = new AtomicReference<>(new RequestId()); @Override - public Uni generateRequestId(ContainerRequestContext requestContext) { + public Uni generateCorrelationId(ContainerRequestContext requestContext) { return Uni.createFrom().item(nextRequestId().toString()); } diff --git a/runtime/service/src/main/java/org/apache/polaris/service/events/listeners/inmemory/InMemoryBufferEventListener.java b/runtime/service/src/main/java/org/apache/polaris/service/events/listeners/inmemory/InMemoryBufferEventListener.java index 533e983ae5..98fc306d53 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/events/listeners/inmemory/InMemoryBufferEventListener.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/events/listeners/inmemory/InMemoryBufferEventListener.java @@ -19,7 +19,7 @@ package org.apache.polaris.service.events.listeners.inmemory; -import static org.apache.polaris.service.tracing.RequestIdFilter.REQUEST_ID_KEY; +import static org.apache.polaris.service.correlation.CorrelationIdFilter.CORRELATION_ID_KEY; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; @@ -94,7 +94,7 @@ protected ContextSpecificInformation getContextSpecificInformation() { @Nullable @Override protected String getRequestId() { - return (String) requestContext.getProperty(REQUEST_ID_KEY); + return (String) requestContext.getProperty(CORRELATION_ID_KEY); } @PreDestroy diff --git a/runtime/service/src/main/java/org/apache/polaris/service/logging/LoggingConfiguration.java b/runtime/service/src/main/java/org/apache/polaris/service/logging/LoggingConfiguration.java index 26c0a1efe4..ce89ffc6be 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/logging/LoggingConfiguration.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/logging/LoggingConfiguration.java @@ -24,9 +24,6 @@ @ConfigMapping(prefix = "polaris.log") public interface LoggingConfiguration { - /** The name of the header that contains the request ID. */ - String requestIdHeaderName(); - /** Additional MDC values to include in the log context. */ Map mdc(); } diff --git a/runtime/service/src/main/java/org/apache/polaris/service/logging/LoggingMDCFilter.java b/runtime/service/src/main/java/org/apache/polaris/service/logging/LoggingMDCFilter.java index fb0112cbb6..3ec9bc0f90 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/logging/LoggingMDCFilter.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/logging/LoggingMDCFilter.java @@ -19,7 +19,7 @@ package org.apache.polaris.service.logging; import static org.apache.polaris.service.context.RealmContextFilter.REALM_CONTEXT_KEY; -import static org.apache.polaris.service.tracing.RequestIdFilter.REQUEST_ID_KEY; +import static org.apache.polaris.service.correlation.CorrelationIdFilter.CORRELATION_ID_KEY; import jakarta.annotation.Priority; import jakarta.enterprise.context.ApplicationScoped; @@ -49,7 +49,7 @@ public void filter(ContainerRequestContext rc) { // Also put the MDC values in the request context for use by other filters and handlers loggingConfiguration.mdc().forEach(MDC::put); loggingConfiguration.mdc().forEach(rc::setProperty); - MDC.put(REQUEST_ID_KEY, (String) rc.getProperty(REQUEST_ID_KEY)); + MDC.put(CORRELATION_ID_KEY, (String) rc.getProperty(CORRELATION_ID_KEY)); RealmContext realmContext = (RealmContext) rc.getProperty(REALM_CONTEXT_KEY); MDC.put(REALM_ID_KEY, realmContext.getRealmIdentifier()); } diff --git a/runtime/service/src/main/java/org/apache/polaris/service/tracing/TracingFilter.java b/runtime/service/src/main/java/org/apache/polaris/service/tracing/TracingFilter.java index d794317d47..f2714b608a 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/tracing/TracingFilter.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/tracing/TracingFilter.java @@ -28,6 +28,7 @@ import org.apache.polaris.core.context.RealmContext; import org.apache.polaris.service.config.FilterPriorities; import org.apache.polaris.service.context.RealmContextFilter; +import org.apache.polaris.service.correlation.CorrelationIdFilter; import org.eclipse.microprofile.config.inject.ConfigProperty; @PreMatching @@ -46,7 +47,7 @@ public class TracingFilter implements ContainerRequestFilter { public void filter(ContainerRequestContext rc) { if (!sdkDisabled) { Span span = Span.current(); - String requestId = (String) rc.getProperty(RequestIdFilter.REQUEST_ID_KEY); + String requestId = (String) rc.getProperty(CorrelationIdFilter.CORRELATION_ID_KEY); span.setAttribute(REQUEST_ID_ATTRIBUTE, requestId); RealmContext realmContext = (RealmContext) rc.getProperty(RealmContextFilter.REALM_CONTEXT_KEY); diff --git a/runtime/service/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor b/runtime/service/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor new file mode 100644 index 0000000000..6e17ae8a92 --- /dev/null +++ b/runtime/service/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor @@ -0,0 +1,20 @@ +# +# 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. +# + +org.apache.polaris.service.config.ConfigRelocationInterceptor diff --git a/runtime/service/src/test/java/org/apache/polaris/service/tracing/RequestIdFilterTest.java b/runtime/service/src/test/java/org/apache/polaris/service/correlation/CorrelationIdFilterTest.java similarity index 86% rename from runtime/service/src/test/java/org/apache/polaris/service/tracing/RequestIdFilterTest.java rename to runtime/service/src/test/java/org/apache/polaris/service/correlation/CorrelationIdFilterTest.java index ddcf5894ba..e5c0c1e4c0 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/tracing/RequestIdFilterTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/correlation/CorrelationIdFilterTest.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.polaris.service.tracing; +package org.apache.polaris.service.correlation; import static io.restassured.RestAssured.given; import static org.hamcrest.CoreMatchers.anything; @@ -43,13 +43,13 @@ @QuarkusTest @TestHTTPEndpoint(IcebergRestOAuth2Api.class) @SuppressWarnings("UastIncorrectHttpHeaderInspection") -public class RequestIdFilterTest { +public class CorrelationIdFilterTest { - @InjectSpy RequestIdGenerator requestIdGenerator; + @InjectSpy CorrelationIdGenerator correlationIdGenerator; @BeforeEach void resetMocks() { - Mockito.reset(requestIdGenerator); + Mockito.reset(correlationIdGenerator); } @Test @@ -61,7 +61,7 @@ void testSuccessWithGeneratedRequestId() { .statusCode(200) .body(containsString("access_token")) .header("Polaris-Request-Id", anything()); - verify(requestIdGenerator, times(1)).generateRequestId(any()); + verify(correlationIdGenerator, times(1)).generateCorrelationId(any()); } @Test @@ -74,14 +74,14 @@ void testSuccessWithCustomRequestId() { .statusCode(200) .body(containsString("access_token")) .header("Polaris-Request-Id", "custom-request-id"); - verify(requestIdGenerator, never()).generateRequestId(any()); + verify(correlationIdGenerator, never()).generateCorrelationId(any()); } @Test void testError() { doReturn(Uni.createFrom().failure(new RuntimeException("test error"))) - .when(requestIdGenerator) - .generateRequestId(any()); + .when(correlationIdGenerator) + .generateCorrelationId(any()); givenTokenRequest() .when() .post() @@ -90,7 +90,7 @@ void testError() { .body("error.message", is("Request ID generation failed")) .body("error.type", is("RequestIdGenerationError")) .body("error.code", is(500)); - verify(requestIdGenerator, times(1)).generateRequestId(any()); + verify(correlationIdGenerator, times(1)).generateCorrelationId(any()); } private static RequestSpecification givenTokenRequest() { diff --git a/runtime/service/src/test/java/org/apache/polaris/service/tracing/RequestIdHeaderTest.java b/runtime/service/src/test/java/org/apache/polaris/service/correlation/CorrelationIdHeaderTest.java similarity index 95% rename from runtime/service/src/test/java/org/apache/polaris/service/tracing/RequestIdHeaderTest.java rename to runtime/service/src/test/java/org/apache/polaris/service/correlation/CorrelationIdHeaderTest.java index 8a653476df..1228a4e7c0 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/tracing/RequestIdHeaderTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/correlation/CorrelationIdHeaderTest.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.polaris.service.tracing; +package org.apache.polaris.service.correlation; import static org.assertj.core.api.Assertions.assertThat; @@ -36,13 +36,13 @@ import org.junit.jupiter.api.Test; @QuarkusTest -@TestProfile(RequestIdHeaderTest.Profile.class) -public class RequestIdHeaderTest { +@TestProfile(CorrelationIdHeaderTest.Profile.class) +public class CorrelationIdHeaderTest { public static class Profile implements QuarkusTestProfile { @Override public Map getConfigOverrides() { return Map.of( - "polaris.log.request-id-header-name", + "polaris.correlation-id.header-name", REQUEST_ID_HEADER, "polaris.realm-context.header-name", REALM_HEADER, diff --git a/runtime/service/src/test/java/org/apache/polaris/service/tracing/DefaultRequestIdGeneratorTest.java b/runtime/service/src/test/java/org/apache/polaris/service/correlation/DefaultCorrelationIdGeneratorTest.java similarity index 90% rename from runtime/service/src/test/java/org/apache/polaris/service/tracing/DefaultRequestIdGeneratorTest.java rename to runtime/service/src/test/java/org/apache/polaris/service/correlation/DefaultCorrelationIdGeneratorTest.java index 13dc54baed..be2638dd89 100644 --- a/runtime/service/src/test/java/org/apache/polaris/service/tracing/DefaultRequestIdGeneratorTest.java +++ b/runtime/service/src/test/java/org/apache/polaris/service/correlation/DefaultCorrelationIdGeneratorTest.java @@ -17,7 +17,7 @@ * under the License. */ -package org.apache.polaris.service.tracing; +package org.apache.polaris.service.correlation; import static org.assertj.core.api.Assertions.assertThat; @@ -26,17 +26,17 @@ import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import org.apache.polaris.service.tracing.DefaultRequestIdGenerator.RequestId; +import org.apache.polaris.service.correlation.DefaultCorrelationIdGenerator.RequestId; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -public class DefaultRequestIdGeneratorTest { +public class DefaultCorrelationIdGeneratorTest { - private DefaultRequestIdGenerator requestIdGenerator; + private DefaultCorrelationIdGenerator requestIdGenerator; @BeforeEach void setUp() { - requestIdGenerator = new DefaultRequestIdGenerator(); + requestIdGenerator = new DefaultCorrelationIdGenerator(); } @Test