Skip to content

Commit f0fc1bf

Browse files
fix: improve embedded version handling (#715) (#832)
* chore: improve embedded version handling (#715) * chore: improve embedded version handling Use new feature in releasetool (googleapis/releasetool#317) to manage the client version instead of maven tricks introduced in #451 * migrate to new version scheme * rename back to Version * config release-please for version bumps * make sure file doesnt get clobbered * add a couple of tests * fmt (cherry picked from commit 1af8925) * update version * fix test * fix: add back in extraFiles and fix file path (#833) (cherry picked from commit f914954) * fix test Co-authored-by: Igor Bernstein <[email protected]>
1 parent cf16cfe commit f0fc1bf

File tree

7 files changed

+112
-18
lines changed

7 files changed

+112
-18
lines changed

.github/release-please.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
releaseType: java-yoshi
2-
bumpMinorPreMajor: true
2+
bumpMinorPreMajor: true
3+
extraFiles:
4+
- google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/Version.java

google-cloud-bigtable/pom.xml

-10
Original file line numberDiff line numberDiff line change
@@ -391,16 +391,6 @@
391391
</profiles>
392392

393393
<build>
394-
<resources>
395-
<resource>
396-
<directory>src/main/templates</directory>
397-
<includes>
398-
<include>**/*.java</include>
399-
</includes>
400-
<filtering>true</filtering>
401-
<targetPath>${project.build.directory}/generated-sources/java</targetPath>
402-
</resource>
403-
</resources>
404394
<plugins>
405395
<plugin>
406396
<groupId>org.codehaus.mojo</groupId>

google-cloud-bigtable/src/main/templates/com/google/cloud/bigtable/Version.java renamed to google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/Version.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 Google LLC
2+
* Copyright 2021 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919

2020
@InternalApi("For internal use only")
2121
public final class Version {
22-
// The released version, populated by maven.
23-
public static String VERSION = "${java-bigtable.version}";
22+
// {x-version-update-start:google-cloud-bigtable:current}
23+
public static String VERSION = "1.22.0-sp.1-SNAPSHOT";
24+
// {x-version-update-end}
2425
}

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStub.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.api.gax.batching.BatcherImpl;
2222
import com.google.api.gax.core.BackgroundResource;
2323
import com.google.api.gax.core.FixedCredentialsProvider;
24-
import com.google.api.gax.core.GaxProperties;
2524
import com.google.api.gax.grpc.GaxGrpcProperties;
2625
import com.google.api.gax.grpc.GrpcCallSettings;
2726
import com.google.api.gax.grpc.GrpcRawCallableFactory;
@@ -54,6 +53,7 @@
5453
import com.google.bigtable.v2.ReadRowsResponse;
5554
import com.google.bigtable.v2.SampleRowKeysRequest;
5655
import com.google.bigtable.v2.SampleRowKeysResponse;
56+
import com.google.cloud.bigtable.Version;
5757
import com.google.cloud.bigtable.data.v2.internal.RequestContext;
5858
import com.google.cloud.bigtable.data.v2.models.BulkMutation;
5959
import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation;
@@ -194,9 +194,7 @@ public static EnhancedBigtableStubSettings finalizeSettings(
194194
// Also annotate traces with library versions
195195
.put("gax", GaxGrpcProperties.getGaxGrpcVersion())
196196
.put("grpc", GaxGrpcProperties.getGrpcVersion())
197-
.put(
198-
"gapic",
199-
GaxProperties.getLibraryVersion(EnhancedBigtableStubSettings.class))
197+
.put("gapic", Version.VERSION)
200198
.build()),
201199
// Add OpenCensus Metrics
202200
MetricsTracerFactory.create(tagger, stats, attributes),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.cloud.bigtable;
17+
18+
import static com.google.common.truth.Truth.assertThat;
19+
20+
import org.junit.Test;
21+
import org.junit.runner.RunWith;
22+
import org.junit.runners.JUnit4;
23+
24+
/** Smoke test to ensure that release tooling doesn't accidentally corrupt the version */
25+
@RunWith(JUnit4.class)
26+
public class VersionTest {
27+
@Test
28+
public void testVersion() {
29+
assertThat(Version.VERSION).matches("\\d+\\.\\d+\\.\\d(?:-sp.\\d+)(?:-SNAPSHOT)?");
30+
31+
assertThat(Version.VERSION).isGreaterThan("1.22.0");
32+
}
33+
}

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/stub/EnhancedBigtableStubTest.java

+66
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
import static com.google.common.truth.Truth.assertThat;
1919

2020
import com.google.api.gax.core.NoCredentialsProvider;
21+
import com.google.api.gax.grpc.GaxGrpcProperties;
2122
import com.google.api.gax.rpc.ServerStreamingCallable;
2223
import com.google.bigtable.v2.BigtableGrpc;
2324
import com.google.bigtable.v2.ReadRowsRequest;
2425
import com.google.bigtable.v2.ReadRowsResponse;
2526
import com.google.bigtable.v2.RowSet;
27+
import com.google.cloud.bigtable.Version;
2628
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
2729
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
2830
import com.google.cloud.bigtable.data.v2.FakeServiceHelper;
@@ -39,8 +41,17 @@
3941
import io.grpc.ServerCall.Listener;
4042
import io.grpc.ServerCallHandler;
4143
import io.grpc.ServerInterceptor;
44+
import io.grpc.internal.GrpcUtil;
4245
import io.grpc.stub.StreamObserver;
46+
import io.opencensus.common.Scope;
47+
import io.opencensus.trace.AttributeValue;
48+
import io.opencensus.trace.Tracing;
49+
import io.opencensus.trace.export.SpanData;
50+
import io.opencensus.trace.export.SpanExporter.Handler;
51+
import io.opencensus.trace.samplers.Samplers;
4352
import java.io.IOException;
53+
import java.util.Collection;
54+
import java.util.concurrent.ArrayBlockingQueue;
4455
import java.util.concurrent.BlockingQueue;
4556
import java.util.concurrent.TimeUnit;
4657
import org.junit.After;
@@ -152,6 +163,61 @@ public void testUserAgent() throws InterruptedException {
152163
.containsMatch("bigtable-java/\\d+\\.\\d+\\.\\d+(?:-SNAPSHOT)?");
153164
}
154165

166+
@Test
167+
public void testSpanAttributes() throws InterruptedException {
168+
final BlockingQueue<SpanData> spans = new ArrayBlockingQueue<>(100);
169+
170+
// inject a temporary trace exporter
171+
String handlerName = "stub-test-exporter";
172+
173+
Tracing.getExportComponent()
174+
.getSpanExporter()
175+
.registerHandler(
176+
handlerName,
177+
new Handler() {
178+
@Override
179+
public void export(Collection<SpanData> collection) {
180+
spans.addAll(collection);
181+
}
182+
});
183+
184+
SpanData foundSpanData = null;
185+
// Issue the rpc and grab the span
186+
try {
187+
try (Scope ignored =
188+
Tracing.getTracer()
189+
.spanBuilder("fake-parent-span")
190+
.setSampler(Samplers.alwaysSample())
191+
.startScopedSpan()) {
192+
enhancedBigtableStub.readRowCallable().call(Query.create("table-id").rowKey("row-key"));
193+
}
194+
195+
for (int i = 0; i < 100; i++) {
196+
SpanData spanData = spans.poll(10, TimeUnit.SECONDS);
197+
if ("Bigtable.ReadRow".equals(spanData.getName())) {
198+
foundSpanData = spanData;
199+
break;
200+
}
201+
}
202+
} finally {
203+
// cleanup
204+
Tracing.getExportComponent().getSpanExporter().unregisterHandler(handlerName);
205+
}
206+
207+
// Examine the caught span
208+
assertThat(foundSpanData).isNotNull();
209+
assertThat(foundSpanData.getAttributes().getAttributeMap())
210+
.containsEntry("gapic", AttributeValue.stringAttributeValue(Version.VERSION));
211+
assertThat(foundSpanData.getAttributes().getAttributeMap())
212+
.containsEntry(
213+
"grpc",
214+
AttributeValue.stringAttributeValue(
215+
GrpcUtil.getGrpcBuildVersion().getImplementationVersion()));
216+
assertThat(foundSpanData.getAttributes().getAttributeMap())
217+
.containsEntry(
218+
"gax", AttributeValue.stringAttributeValue(GaxGrpcProperties.getGaxGrpcVersion()));
219+
}
220+
155221
private static class MetadataInterceptor implements ServerInterceptor {
156222
final BlockingQueue<Metadata> headers = Queues.newLinkedBlockingDeque();
157223

synth.py

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ def main():
4141
# todo remove once template is updated
4242
'.github/ISSUE_TEMPLATE/bug_report.md',
4343
'CONTRIBUTING.md',
44+
# exclude autogen
45+
'codecov.yaml'
46+
# needed for extraFiles
47+
'.github/release-please.yml',
4448
])
4549

4650
def generate_data_api(gapic):

0 commit comments

Comments
 (0)