-
Notifications
You must be signed in to change notification settings - Fork 84
fix: update grpc client side metrics detection to be graceful when not running on gcp #3097
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
97 changes: 97 additions & 0 deletions
97
...d-storage/src/test/java/com/google/cloud/storage/OpenTelemetryBootstrappingUtilsTest.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,97 @@ | ||
/* | ||
* Copyright 2025 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; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static org.junit.Assume.assumeFalse; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import com.google.cloud.storage.OpenTelemetryBootstrappingUtils.ChannelConfigurator; | ||
import io.grpc.ManagedChannelBuilder; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import org.junit.Test; | ||
|
||
public final class OpenTelemetryBootstrappingUtilsTest { | ||
|
||
@Test | ||
public void noErrorIfNotRunningOnGcp() { | ||
assumeFalse("Skipping because running on GCP", TestUtils.isOnComputeEngine()); | ||
|
||
ChannelConfigurator cc = ChannelConfigurator.identity(); | ||
|
||
String endpoint = "storage.googleapis.com:443"; | ||
String projectId = null; | ||
String universeDomain = null; | ||
ChannelConfigurator actual = | ||
OpenTelemetryBootstrappingUtils.enableGrpcMetrics( | ||
cc, endpoint, projectId, universeDomain, true); | ||
|
||
assertThat(actual).isSameInstanceAs(cc); | ||
} | ||
|
||
@SuppressWarnings("rawtypes") // ManagedChannelBuilder | ||
@Test | ||
public void channelConfigurator_andThen() { | ||
ManagedChannelBuilder b1 = mock(ManagedChannelBuilder.class, "b1"); | ||
ManagedChannelBuilder b2 = mock(ManagedChannelBuilder.class, "b2"); | ||
ManagedChannelBuilder b3 = mock(ManagedChannelBuilder.class, "b2"); | ||
|
||
ChannelConfigurator cc1 = | ||
b -> { | ||
assertThat(b).isSameInstanceAs(b1); | ||
return b2; | ||
}; | ||
ChannelConfigurator cc2 = | ||
b -> { | ||
assertThat(b).isSameInstanceAs(b2); | ||
return b3; | ||
}; | ||
|
||
ChannelConfigurator cc3 = cc1.andThen(cc2); | ||
|
||
ManagedChannelBuilder apply = cc3.apply(b1); | ||
assertThat(apply).isSameInstanceAs(b3); | ||
} | ||
|
||
@Test | ||
public void channelConfigurator_lift_nullToIdentity() { | ||
ChannelConfigurator actual = ChannelConfigurator.lift(null); | ||
assertThat(actual).isSameInstanceAs(ChannelConfigurator.identity()); | ||
} | ||
|
||
@SuppressWarnings("rawtypes") // ManagedChannelBuilder | ||
@Test | ||
public void channelConfigurator_lift_plumbingWorks() { | ||
ManagedChannelBuilder b1 = mock(ManagedChannelBuilder.class, "b1"); | ||
AtomicBoolean called = new AtomicBoolean(false); | ||
ChannelConfigurator lifted = | ||
ChannelConfigurator.lift( | ||
b -> { | ||
called.compareAndSet(false, true); | ||
return b; | ||
}); | ||
ManagedChannelBuilder actual = lifted.apply(b1); | ||
assertThat(actual).isSameInstanceAs(b1); | ||
assertThat(called.get()).isTrue(); | ||
} | ||
|
||
@Test | ||
public void channelConfigurator_andThen_nullsafe() { | ||
ChannelConfigurator actual = ChannelConfigurator.identity().andThen(null); | ||
assertThat(actual).isSameInstanceAs(ChannelConfigurator.identity()); | ||
} | ||
} |
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.
qq: is this the case of not running on GCP?
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.
In a round about manner yes. The metrics reporting relies on application default credentials for initialization, and if the project can't be determined either as a passed in value from the Storage client, or resolved from the GCP resolved otel attributes there isn't any way to bootstrap.