Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add gccl-invocation-id interceptor (#1309)
add gccl-invocation-id to all HTTP requests to allow identifying operation attempts across multiple rpcs. Excludes signed urls. Co-authored-by: BenWhitehead <BenWhitehead@users.noreply.github.com>
- Loading branch information
1 parent
9d8c520
commit 335c267
Showing
7 changed files
with
375 additions
and
2 deletions.
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
72 changes: 72 additions & 0 deletions
72
google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpRpcContext.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,72 @@ | ||
/* | ||
* Copyright 2022 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 | ||
* | ||
* 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.google.cloud.storage.spi.v1; | ||
|
||
import com.google.api.core.InternalApi; | ||
import java.util.UUID; | ||
import java.util.function.Supplier; | ||
import javax.annotation.Nullable; | ||
|
||
@InternalApi | ||
public final class HttpRpcContext { | ||
|
||
private static final Object GET_INSTANCE_LOCK = new Object(); | ||
|
||
private static volatile HttpRpcContext instance; | ||
|
||
private final ThreadLocal<UUID> invocationId; | ||
private final Supplier<UUID> supplier; | ||
|
||
HttpRpcContext(Supplier<UUID> randomUUID) { | ||
this.invocationId = new InheritableThreadLocal<>(); | ||
this.supplier = randomUUID; | ||
} | ||
|
||
@InternalApi | ||
@Nullable | ||
public UUID getInvocationId() { | ||
return invocationId.get(); | ||
} | ||
|
||
@InternalApi | ||
public UUID newInvocationId() { | ||
invocationId.set(supplier.get()); | ||
return getInvocationId(); | ||
} | ||
|
||
@InternalApi | ||
public void clearInvocationId() { | ||
invocationId.remove(); | ||
} | ||
|
||
@InternalApi | ||
public static HttpRpcContext init() { | ||
return new HttpRpcContext(UUID::randomUUID); | ||
} | ||
|
||
@InternalApi | ||
public static HttpRpcContext getInstance() { | ||
if (instance == null) { | ||
synchronized (GET_INSTANCE_LOCK) { | ||
if (instance == null) { | ||
instance = init(); | ||
} | ||
} | ||
} | ||
return instance; | ||
} | ||
} |
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
Oops, something went wrong.