-
Notifications
You must be signed in to change notification settings - Fork 72
feat(obs): introduce gpc.client.repo span attribute #4111
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
base: observability/initial-tracing-impl
Are you sure you want to change the base?
Changes from all commits
ba3c080
caead0d
58f72d2
5a5d9d6
015aa88
0907e93
1eeb197
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,6 +71,7 @@ protected static CodeGeneratorResponse write( | |
|
|
||
| writeMetadataFile(context, writePackageInfo(gapicPackageInfo, codeWriter, jos), jos); | ||
| writeReflectConfigFile(gapicPackageInfo.packageInfo().pakkage(), reflectConfigInfo, jos); | ||
| writeGapicPropertiesFile(context, jos); | ||
|
|
||
| jos.finish(); | ||
| jos.flush(); | ||
|
|
@@ -212,6 +213,22 @@ private static void writeMetadataFile(GapicContext context, String path, JarOutp | |
| } | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| static void writeGapicPropertiesFile(GapicContext context, JarOutputStream jos) { | ||
| context | ||
| .repo() | ||
| .ifPresent( | ||
| repo -> { | ||
| JarEntry jarEntry = new JarEntry("src/main/resources/gapic.properties"); | ||
| try { | ||
| jos.putNextEntry(jarEntry); | ||
| jos.write(String.format("repo=%s\n", repo).getBytes(StandardCharsets.UTF_8)); | ||
|
Contributor
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. The |
||
| } catch (IOException e) { | ||
| throw new GapicWriterException("Could not write repo file", e); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private static String getPath(String pakkage, String className) { | ||
| String path = pakkage.replaceAll("\\.", "/"); | ||
| if (className.startsWith("Mock") || className.endsWith("Test")) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,12 @@ | |
|
|
||
| import com.google.api.core.InternalApi; | ||
| import com.google.auto.value.AutoValue; | ||
| import com.google.common.annotations.VisibleForTesting; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.util.Properties; | ||
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
| import javax.annotation.Nullable; | ||
|
|
||
| /** | ||
|
|
@@ -43,18 +49,52 @@ | |
| @InternalApi | ||
| @AutoValue | ||
| public abstract class ApiTracerContext { | ||
| private static final Logger LOGGER = Logger.getLogger(ApiTracerContext.class.getName()); | ||
| private static final String GAPIC_PROPERTIES_FILE = "/gapic.properties"; | ||
| private static final String REPO_KEY = "repo"; | ||
|
|
||
| @Nullable | ||
| public abstract String getServerAddress(); | ||
|
|
||
| @Nullable | ||
| public abstract String getRepo(); | ||
|
|
||
| public static Builder newBuilder() { | ||
| return new AutoValue_ApiTracerContext.Builder(); | ||
| return newBuilder(ApiTracerContext.class.getResourceAsStream(GAPIC_PROPERTIES_FILE)); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| static Builder newBuilder(@Nullable InputStream inputStream) { | ||
| Builder builder = new AutoValue_ApiTracerContext.Builder(); | ||
| loadRepoFromProperties(builder, inputStream); | ||
| return builder; | ||
| } | ||
|
|
||
| private static void loadRepoFromProperties(Builder builder, @Nullable InputStream is) { | ||
| if (is == null) { | ||
| return; | ||
| } | ||
| try { | ||
| Properties properties = new Properties(); | ||
| properties.load(is); | ||
| builder.setRepo(properties.getProperty(REPO_KEY)); | ||
| } catch (IOException e) { | ||
| LOGGER.log(Level.WARNING, "Could not load gapic.properties", e); | ||
| } finally { | ||
| try { | ||
| is.close(); | ||
| } catch (IOException e) { | ||
| LOGGER.log(Level.WARNING, "Could not close gapic.properties stream", e); | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+73
to
90
Contributor
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. The private static void loadRepoFromProperties(Builder builder, @Nullable InputStream is) {
if (is == null) {
return;
}
try (InputStream inputStream = is) {
Properties properties = new Properties();
properties.load(inputStream);
builder.setRepo(properties.getProperty(REPO_KEY));
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Could not load or close gapic.properties", e);
}
} |
||
|
|
||
| @AutoValue.Builder | ||
| public abstract static class Builder { | ||
| public abstract Builder setServerAddress(String serverAddress); | ||
|
|
||
| public abstract Builder setRepo(String repo); | ||
|
|
||
| public abstract ApiTracerContext build(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are | ||
| * met: | ||
| * | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * * Redistributions in binary form must reproduce the above | ||
| * copyright notice, this list of conditions and the following disclaimer | ||
| * in the documentation and/or other materials provided with the | ||
| * distribution. | ||
| * * Neither the name of Google LLC nor the names of its | ||
| * contributors may be used to endorse or promote products derived from | ||
| * this software without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
|
|
||
| package com.google.api.gax.tracing; | ||
|
|
||
| import static com.google.common.truth.Truth.assertThat; | ||
|
|
||
| import java.io.ByteArrayInputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.nio.charset.StandardCharsets; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.mockito.Mockito; | ||
|
|
||
| class ApiTracerContextTest { | ||
|
|
||
| @Test | ||
| void testNewBuilderWithNoPropertiesFile() { | ||
| ApiTracerContext context = | ||
| ApiTracerContext.newBuilder(null).setServerAddress("test-address").build(); | ||
|
|
||
| assertThat(context.getServerAddress()).isEqualTo("test-address"); | ||
| assertThat(context.getRepo()).isNull(); | ||
| } | ||
|
|
||
| @Test | ||
| void testNewBuilderWithPropertiesFile() { | ||
| String propertiesContent = "repo=test-repo"; | ||
| InputStream inputStream = | ||
| new ByteArrayInputStream(propertiesContent.getBytes(StandardCharsets.UTF_8)); | ||
|
|
||
| ApiTracerContext context = | ||
| ApiTracerContext.newBuilder(inputStream).setServerAddress("test-address").build(); | ||
|
|
||
| assertThat(context.getServerAddress()).isEqualTo("test-address"); | ||
| assertThat(context.getRepo()).isEqualTo("test-repo"); | ||
| } | ||
|
|
||
| @Test | ||
| void testNewBuilderWithPropertiesFileAndNoRepoKey() { | ||
| String propertiesContent = "somekey=somevalue"; | ||
| InputStream inputStream = | ||
| new ByteArrayInputStream(propertiesContent.getBytes(StandardCharsets.UTF_8)); | ||
|
|
||
| ApiTracerContext context = | ||
| ApiTracerContext.newBuilder(inputStream).setServerAddress("test-address").build(); | ||
|
|
||
| assertThat(context.getServerAddress()).isEqualTo("test-address"); | ||
| assertThat(context.getRepo()).isNull(); | ||
| } | ||
|
|
||
| @Test | ||
| void testNewBuilderWithPropertiesFileLoadingError() throws IOException { | ||
| InputStream mockInputStream = Mockito.mock(InputStream.class); | ||
| Mockito.doThrow(new IOException("Test IO Exception")) | ||
| .when(mockInputStream) | ||
| .read(Mockito.any(byte[].class)); | ||
|
|
||
| ApiTracerContext context = | ||
| ApiTracerContext.newBuilder(mockInputStream).setServerAddress("test-address").build(); | ||
|
|
||
| assertThat(context.getServerAddress()).isEqualTo("test-address"); | ||
| assertThat(context.getRepo()).isNull(); | ||
| } | ||
| } |
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.
The
parseRepomethod usesparseConfigArgument, which parses plugin arguments by splitting the input string by commas. If therepovalue contains a comma, it will be split, potentially allowing an attacker to inject additional plugin flags or options (e.g., injecting,metadatato enable metadata generation).