-
Notifications
You must be signed in to change notification settings - Fork 88
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
feat: send attempt and timestamp in headers #935
Merged
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2e0fe77
feat: send attempt and timestamp in headers
mutianf e6e53f8
refactor
mutianf 49142dc
update clirr files
mutianf 73cecdd
refactor
mutianf ec37f18
review updates
mutianf 857ebef
remove "x-"
mutianf 875840c
update
mutianf 3d94f6e
Add epoch precision to the header
mutianf 492cdab
use microseconds
mutianf 22a0f62
update micro seconds calculation
mutianf 98d6043
fix formatting
mutianf 69bdbba
Rename headers class
mutianf bee61ed
rename local variables
mutianf 6ec8f12
update comment
mutianf 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 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 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 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 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
46 changes: 46 additions & 0 deletions
46
...va/com/google/cloud/bigtable/data/v2/stub/metrics/ExtraHeadersSeverStreamingCallable.java
This file contains 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,46 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* 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 | ||
* | ||
* https://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.google.cloud.bigtable.data.v2.stub.metrics; | ||
|
||
import com.google.api.core.InternalApi; | ||
import com.google.api.gax.rpc.ApiCallContext; | ||
import com.google.api.gax.rpc.ResponseObserver; | ||
import com.google.api.gax.rpc.ServerStreamingCallable; | ||
|
||
/** | ||
* A callable that injects client timestamp and current attempt number to request headers. Attempt | ||
* number starts from 0. | ||
*/ | ||
@InternalApi("For internal use only") | ||
public final class ExtraHeadersSeverStreamingCallable<RequestT, ResponseT> | ||
extends ServerStreamingCallable<RequestT, ResponseT> { | ||
private final ServerStreamingCallable innerCallable; | ||
|
||
public ExtraHeadersSeverStreamingCallable(ServerStreamingCallable innerCallable) { | ||
this.innerCallable = innerCallable; | ||
} | ||
|
||
@Override | ||
public void call( | ||
RequestT request, | ||
ResponseObserver<ResponseT> responseObserver, | ||
ApiCallContext apiCallContext) { | ||
ApiCallContext newCallContext = | ||
apiCallContext.withExtraHeaders(Util.createExtraHeaders(apiCallContext)); | ||
innerCallable.call(request, responseObserver, newCallContext); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...c/main/java/com/google/cloud/bigtable/data/v2/stub/metrics/ExtraHeadersUnaryCallable.java
This file contains 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,43 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* 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 | ||
* | ||
* https://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.google.cloud.bigtable.data.v2.stub.metrics; | ||
|
||
import com.google.api.core.ApiFuture; | ||
import com.google.api.core.InternalApi; | ||
import com.google.api.gax.rpc.ApiCallContext; | ||
import com.google.api.gax.rpc.UnaryCallable; | ||
|
||
/** | ||
* A callable that injects client timestamp and current attempt number to request headers. Attempt | ||
* number starts from 0. | ||
*/ | ||
@InternalApi("For internal use only") | ||
public final class ExtraHeadersUnaryCallable<RequestT, ResponseT> | ||
extends UnaryCallable<RequestT, ResponseT> { | ||
private final UnaryCallable innerCallable; | ||
|
||
public ExtraHeadersUnaryCallable(UnaryCallable innerCallable) { | ||
this.innerCallable = innerCallable; | ||
} | ||
|
||
@Override | ||
public ApiFuture futureCall(RequestT request, ApiCallContext apiCallContext) { | ||
ApiCallContext newCallContext = | ||
apiCallContext.withExtraHeaders(Util.createExtraHeaders(apiCallContext)); | ||
return innerCallable.futureCall(request, newCallContext); | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -15,20 +15,33 @@ | |
*/ | ||
package com.google.cloud.bigtable.data.v2.stub.metrics; | ||
|
||
import com.google.api.gax.rpc.ApiCallContext; | ||
import com.google.api.gax.rpc.ApiException; | ||
import com.google.api.gax.rpc.StatusCode; | ||
import com.google.api.gax.rpc.StatusCode.Code; | ||
import com.google.common.collect.ImmutableMap; | ||
import io.grpc.Metadata; | ||
import io.grpc.Status; | ||
import io.grpc.StatusException; | ||
import io.grpc.StatusRuntimeException; | ||
import io.opencensus.tags.TagValue; | ||
import java.time.Instant; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.CancellationException; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.Future; | ||
import javax.annotation.Nullable; | ||
|
||
/** Utilities to help integrating with OpenCensus. */ | ||
class Util { | ||
static final Metadata.Key<String> ATTEMPT_HEADER_KEY = | ||
Metadata.Key.of("bigtable-attempt", Metadata.ASCII_STRING_MARSHALLER); | ||
static final Metadata.Key<String> ATTEMPT_EPOCH_KEY = | ||
Metadata.Key.of("bigtable-client-attempt-epoch-usec", Metadata.ASCII_STRING_MARSHALLER); | ||
|
||
private static final TagValue OK_STATUS = TagValue.create(StatusCode.Code.OK.toString()); | ||
|
||
/** Convert an exception into a value that can be used as an OpenCensus tag value. */ | ||
|
@@ -71,4 +84,20 @@ static TagValue extractStatus(Future<?> future) { | |
} | ||
return extractStatus(error); | ||
} | ||
|
||
/** | ||
* Create extra headers with attempt number and client timestamp from api call context. Attempt | ||
* number starts from 0. | ||
*/ | ||
static Map<String, List<String>> createExtraHeaders(ApiCallContext apiCallContext) { | ||
ImmutableMap.Builder headers = ImmutableMap.<String, List<String>>builder(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please out type params on the variable type |
||
headers.put( | ||
ATTEMPT_EPOCH_KEY.name(), | ||
Arrays.asList(String.valueOf(Instant.EPOCH.until(Instant.now(), ChronoUnit.MICROS)))); | ||
if (apiCallContext.getTracer() instanceof BigtableTracer) { | ||
mutianf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int attemptCount = ((BigtableTracer) apiCallContext.getTracer()).getAttempt(); | ||
headers.put(ATTEMPT_HEADER_KEY.name(), Arrays.asList(String.valueOf(attemptCount))); | ||
} | ||
return headers.build(); | ||
} | ||
} |
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.
typo: missing r in server
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.
Maybe rename it to StatsHeader....