-
Notifications
You must be signed in to change notification settings - Fork 884
CASSJAVA-97: Let users inject an ID for each request and write to the custom payload #2037
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
Merged
Merged
Changes from all commits
Commits
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
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
77 changes: 77 additions & 0 deletions
77
core/src/main/java/com/datastax/oss/driver/api/core/tracker/RequestIdGenerator.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,77 @@ | ||
| /* | ||
| * 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 com.datastax.oss.driver.api.core.tracker; | ||
|
|
||
| import com.datastax.oss.driver.api.core.cql.Statement; | ||
| import com.datastax.oss.driver.api.core.session.Request; | ||
| import com.datastax.oss.protocol.internal.util.collection.NullAllowingImmutableMap; | ||
| import edu.umd.cs.findbugs.annotations.NonNull; | ||
| import java.nio.ByteBuffer; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Interface responsible for generating request IDs. | ||
| * | ||
| * <p>Note that all request IDs have a parent/child relationship. A "parent ID" can loosely be | ||
| * thought of as encompassing a sequence of a request + any attendant retries, speculative | ||
| * executions etc. It's scope is identical to that of a {@link | ||
| * com.datastax.oss.driver.internal.core.cql.CqlRequestHandler}. A "request ID" represents a single | ||
| * request within this larger scope. Note that a request corresponding to a request ID may be | ||
| * retried; in that case the retry count will be appended to the corresponding identifier in the | ||
| * logs. | ||
| */ | ||
| public interface RequestIdGenerator { | ||
|
|
||
| String DEFAULT_PAYLOAD_KEY = "request-id"; | ||
|
|
||
| /** | ||
| * Generates a unique identifier for the session request. This will be the identifier for the | ||
| * entire `session.execute()` call. This identifier will be added to logs, and propagated to | ||
| * request trackers. | ||
| * | ||
| * @return a unique identifier for the session request | ||
| */ | ||
| String getSessionRequestId(); | ||
|
|
||
| /** | ||
| * Generates a unique identifier for the node request. This will be the identifier for the CQL | ||
| * request against a particular node. There can be one or more node requests for a single session | ||
| * request, due to retries or speculative executions. This identifier will be added to logs, and | ||
| * propagated to request trackers. | ||
| * | ||
| * @param statement the statement to be executed | ||
| * @param parentId the session request identifier | ||
| * @return a unique identifier for the node request | ||
| */ | ||
| String getNodeRequestId(@NonNull Request statement, @NonNull String parentId); | ||
|
|
||
| default String getCustomPayloadKey() { | ||
| return DEFAULT_PAYLOAD_KEY; | ||
| } | ||
|
|
||
| default Statement<?> getDecoratedStatement( | ||
| @NonNull Statement<?> statement, @NonNull String requestId) { | ||
| Map<String, ByteBuffer> customPayload = | ||
| NullAllowingImmutableMap.<String, ByteBuffer>builder() | ||
| .putAll(statement.getCustomPayload()) | ||
| .put(getCustomPayloadKey(), ByteBuffer.wrap(requestId.getBytes(StandardCharsets.UTF_8))) | ||
| .build(); | ||
| return statement.setCustomPayload(customPayload); | ||
| } | ||
| } |
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.
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.
@absurdfarce the meeting today agreed that Astra will use
traceparentas the key. We should change the default key for Astra totraceparent. It isrequest-idright now.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.
Agreed we should update to match the requirement for the Astra case @SiyaoIsHiding but I don't think we need to change the default in RequestIdGenerator. We should be able to address that by updating W3CContextRequestIdGenerator constructors:
new W3CContextRequestIdGenerator() == use the default key
new W3CContextRequestIdGenerator(String key) == use the provided key
Here we're in the Astra case so we'd clearly want to provide an arg.
Remember, W3CContextRequestidGenerator != AstraRequestIdGenerator. Just because the Astra requirements change doesn't mean we change the defaults.
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.
Bret and Andy and Jane agreed in the Sep 22 meeting that we will change the default key to
traceparentand allow overrideThere 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.
This update should now be in place