-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Add logic to include client-id to group requests from same Iceberg client #189
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
subkanthi
wants to merge
5
commits into
master
Choose a base branch
from
10-ice-enable-tracing
base: master
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.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
79bbee0
Added logic to include client-id so calls from the same iceberg clien…
subkanthi 39feb70
Fixed Integration test
subkanthi 99c67d5
Fixed tracing logic
subkanthi c8b95c9
Merge branch 'master' of https://github.com/Altinity/ice into 10-ice-…
subkanthi 878abfd
Added JSON request/response API logging for REST catalog.
subkanthi 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
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
59 changes: 59 additions & 0 deletions
59
...st-catalog/src/main/java/com/altinity/ice/rest/catalog/internal/config/TracingConfig.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,59 @@ | ||
| /* | ||
| * Copyright (c) 2025 Altinity Inc and/or its affiliates. All rights reserved. | ||
| * | ||
| * Licensed 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 | ||
| */ | ||
| package com.altinity.ice.rest.catalog.internal.config; | ||
|
|
||
| import com.altinity.ice.internal.strings.Strings; | ||
| import com.fasterxml.jackson.annotation.JsonPropertyDescription; | ||
|
|
||
| /** | ||
| * Per-request / per-client correlation configuration. | ||
| * | ||
| * <p>Adds a stable {@code clientId} (a deterministic per-identity fingerprint grouping all calls | ||
| * from the same uid + remote address + user-agent, including across separate client runs) and a | ||
| * per-request {@code requestId} to logs (via MDC) and response headers, so a whole client's | ||
| * activity can be grouped from the logs alone. All settings are optional; the feature is on by | ||
| * default and has no external dependencies. | ||
| */ | ||
| public record TracingConfig( | ||
| @JsonPropertyDescription( | ||
| "Enable request/client correlation ids in logs and response headers (true by default)") | ||
| Boolean enabled, | ||
| @JsonPropertyDescription( | ||
| "Header carrying the per-client id echoed by Iceberg clients (X-Ice-Client-Id)") | ||
| String clientIdHeader, | ||
| @JsonPropertyDescription("Header carrying the per-request id (X-Request-Id)") | ||
| String requestIdHeader, | ||
| @JsonPropertyDescription( | ||
| "Advertise the resolved (deterministic fingerprint) client id via the /v1/config response so Iceberg Java/PyIceberg clients echo the same id on every request, keeping it stable across runs (true by default)") | ||
| Boolean advertiseClientId) { | ||
|
|
||
| public static final String DEFAULT_CLIENT_ID_HEADER = "X-Ice-Client-Id"; | ||
| public static final String DEFAULT_REQUEST_ID_HEADER = "X-Request-Id"; | ||
|
|
||
| public static TracingConfig defaults() { | ||
| return new TracingConfig(null, null, null, null); | ||
| } | ||
|
|
||
| public boolean enabledOrDefault() { | ||
| return enabled == null || enabled; | ||
| } | ||
|
|
||
| public String clientIdHeaderOrDefault() { | ||
| return !Strings.isNullOrEmpty(clientIdHeader) ? clientIdHeader : DEFAULT_CLIENT_ID_HEADER; | ||
| } | ||
|
|
||
| public String requestIdHeaderOrDefault() { | ||
| return !Strings.isNullOrEmpty(requestIdHeader) ? requestIdHeader : DEFAULT_REQUEST_ID_HEADER; | ||
| } | ||
|
|
||
| public boolean advertiseClientIdOrDefault() { | ||
| return advertiseClientId == null || advertiseClientId; | ||
| } | ||
| } |
59 changes: 59 additions & 0 deletions
59
...c/main/java/com/altinity/ice/rest/catalog/internal/rest/RESTCatalogMiddlewareTracing.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,59 @@ | ||
| /* | ||
| * Copyright (c) 2025 Altinity Inc and/or its affiliates. All rights reserved. | ||
| * | ||
| * Licensed 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 | ||
| */ | ||
| package com.altinity.ice.rest.catalog.internal.rest; | ||
|
|
||
| import com.altinity.ice.rest.catalog.internal.auth.Session; | ||
| import java.util.Map; | ||
| import org.apache.iceberg.rest.RESTResponse; | ||
| import org.apache.iceberg.rest.responses.ConfigResponse; | ||
| import org.slf4j.MDC; | ||
|
|
||
| /** | ||
| * Advertises the client id to Iceberg clients via the {@code /v1/config} handshake. | ||
| * | ||
| * <p>The advertised value is the id already resolved for the config request (read from the {@link | ||
| * MDC}) - a deterministic per-identity fingerprint ({@code fp-...}) derived from uid + remote | ||
| * address + user-agent. It is returned as a {@code header.<clientIdHeader>} override. Iceberg Java | ||
| * and PyIceberg merge config overrides and re-send matching {@code header.*} properties on every | ||
| * subsequent request, so all calls from that identity share one {@code clientId} - and because the | ||
| * value is deterministic (not a random per-instance id), it stays stable across separate | ||
| * short-lived client runs. Clients that ignore config overrides (e.g. ClickHouse) fall back to the | ||
| * same server-side fingerprint anyway. | ||
| */ | ||
| public class RESTCatalogMiddlewareTracing extends RESTCatalogMiddleware { | ||
|
|
||
| private static final String HEADER_PREFIX = "header."; | ||
|
|
||
| private final String clientIdHeader; | ||
|
|
||
| public RESTCatalogMiddlewareTracing(RESTCatalogHandler next, String clientIdHeader) { | ||
| super(next); | ||
| this.clientIdHeader = clientIdHeader; | ||
| } | ||
|
|
||
| @Override | ||
| public <T extends RESTResponse> T handle( | ||
| Session session, | ||
| Route route, | ||
| Map<String, String> vars, | ||
| Object requestBody, | ||
| Class<T> responseType) { | ||
| T restResponse = this.next.handle(session, route, vars, requestBody, responseType); | ||
| if (restResponse instanceof ConfigResponse configResponse) { | ||
| // Advertise the id already resolved for this config request (the stable fingerprint), so | ||
| // echoing clients keep using the same deterministic id across runs. | ||
| String clientId = MDC.get(RequestTracing.MDC_CLIENT_ID); | ||
| if (clientId != null && !clientId.isEmpty()) { | ||
| configResponse.overrides().putIfAbsent(HEADER_PREFIX + clientIdHeader, clientId); | ||
| } | ||
| } | ||
| return restResponse; | ||
| } | ||
| } |
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.
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.
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.
It seems like the tracing logic always runs even if tracing is disabled. It should check tracing.enabled() first.