Skip to content

Commit

Permalink
chore: improve embedded version handling (#715)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
igorbernstein2 authored Apr 13, 2021
1 parent b61c5ce commit 1af8925
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 18 deletions.
4 changes: 3 additions & 1 deletion .github/release-please.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
releaseType: java-yoshi
bumpMinorPreMajor: true
bumpMinorPreMajor: true
extraFiles:
- google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/ClientVersion.java
10 changes: 0 additions & 10 deletions google-cloud-bigtable/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -427,16 +427,6 @@
</profiles>

<build>
<resources>
<resource>
<directory>src/main/templates</directory>
<includes>
<include>**/*.java</include>
</includes>
<filtering>true</filtering>
<targetPath>${project.build.directory}/generated-sources/java</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020 Google LLC
* 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.
Expand All @@ -19,6 +19,7 @@

@InternalApi("For internal use only")
public final class Version {
// The released version, populated by maven.
public static String VERSION = "${java-bigtable.version}";
// {x-version-update-start:google-cloud-bigtable:current}
public static String VERSION = "1.22.1-SNAPSHOT";
// {x-version-update-end}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.api.gax.batching.FlowController;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.api.gax.core.GaxProperties;
import com.google.api.gax.grpc.GaxGrpcProperties;
import com.google.api.gax.grpc.GrpcCallSettings;
import com.google.api.gax.grpc.GrpcRawCallableFactory;
Expand Down Expand Up @@ -55,6 +54,7 @@
import com.google.bigtable.v2.ReadRowsResponse;
import com.google.bigtable.v2.SampleRowKeysRequest;
import com.google.bigtable.v2.SampleRowKeysResponse;
import com.google.cloud.bigtable.Version;
import com.google.cloud.bigtable.data.v2.internal.RequestContext;
import com.google.cloud.bigtable.data.v2.models.BulkMutation;
import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation;
Expand Down Expand Up @@ -199,9 +199,7 @@ public static EnhancedBigtableStubSettings finalizeSettings(
// Also annotate traces with library versions
.put("gax", GaxGrpcProperties.getGaxGrpcVersion())
.put("grpc", GaxGrpcProperties.getGrpcVersion())
.put(
"gapic",
GaxProperties.getLibraryVersion(EnhancedBigtableStubSettings.class))
.put("gapic", Version.VERSION)
.build()),
// Add OpenCensus Metrics
MetricsTracerFactory.create(tagger, stats, attributes),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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;

import static com.google.common.truth.Truth.assertThat;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** Smoke test to ensure that release tooling doesn't accidentally corrupt the version */
@RunWith(JUnit4.class)
public class VersionTest {
@Test
public void testVersion() {
assertThat(Version.VERSION).matches("\\d+\\.\\d+\\.\\d(?:-SNAPSHOT)?");

assertThat(Version.VERSION).isGreaterThan("1.22.0");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import com.google.api.gax.batching.FlowControlSettings;
import com.google.api.gax.batching.FlowController.LimitExceededBehavior;
import com.google.api.gax.core.NoCredentialsProvider;
import com.google.api.gax.grpc.GaxGrpcProperties;
import com.google.api.gax.rpc.ServerStreamingCallable;
import com.google.bigtable.v2.BigtableGrpc;
import com.google.bigtable.v2.ReadRowsRequest;
import com.google.bigtable.v2.ReadRowsResponse;
import com.google.bigtable.v2.RowSet;
import com.google.cloud.bigtable.Version;
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
import com.google.cloud.bigtable.data.v2.BigtableDataSettings;
import com.google.cloud.bigtable.data.v2.FakeServiceHelper;
Expand All @@ -43,8 +45,17 @@
import io.grpc.ServerCall.Listener;
import io.grpc.ServerCallHandler;
import io.grpc.ServerInterceptor;
import io.grpc.internal.GrpcUtil;
import io.grpc.stub.StreamObserver;
import io.opencensus.common.Scope;
import io.opencensus.trace.AttributeValue;
import io.opencensus.trace.Tracing;
import io.opencensus.trace.export.SpanData;
import io.opencensus.trace.export.SpanExporter.Handler;
import io.opencensus.trace.samplers.Samplers;
import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import org.junit.After;
Expand Down Expand Up @@ -157,6 +168,61 @@ public void testUserAgent() throws InterruptedException {
.containsMatch("bigtable-java/\\d+\\.\\d+\\.\\d+(?:-SNAPSHOT)?");
}

@Test
public void testSpanAttributes() throws InterruptedException {
final BlockingQueue<SpanData> spans = new ArrayBlockingQueue<>(100);

// inject a temporary trace exporter
String handlerName = "stub-test-exporter";

Tracing.getExportComponent()
.getSpanExporter()
.registerHandler(
handlerName,
new Handler() {
@Override
public void export(Collection<SpanData> collection) {
spans.addAll(collection);
}
});

SpanData foundSpanData = null;
// Issue the rpc and grab the span
try {
try (Scope ignored =
Tracing.getTracer()
.spanBuilder("fake-parent-span")
.setSampler(Samplers.alwaysSample())
.startScopedSpan()) {
enhancedBigtableStub.readRowCallable().call(Query.create("table-id").rowKey("row-key"));
}

for (int i = 0; i < 100; i++) {
SpanData spanData = spans.poll(10, TimeUnit.SECONDS);
if ("Bigtable.ReadRow".equals(spanData.getName())) {
foundSpanData = spanData;
break;
}
}
} finally {
// cleanup
Tracing.getExportComponent().getSpanExporter().unregisterHandler(handlerName);
}

// Examine the caught span
assertThat(foundSpanData).isNotNull();
assertThat(foundSpanData.getAttributes().getAttributeMap())
.containsEntry("gapic", AttributeValue.stringAttributeValue(Version.VERSION));
assertThat(foundSpanData.getAttributes().getAttributeMap())
.containsEntry(
"grpc",
AttributeValue.stringAttributeValue(
GrpcUtil.getGrpcBuildVersion().getImplementationVersion()));
assertThat(foundSpanData.getAttributes().getAttributeMap())
.containsEntry(
"gax", AttributeValue.stringAttributeValue(GaxGrpcProperties.getGaxGrpcVersion()));
}

@Test
public void testBulkMutationFlowControllerConfigured() throws Exception {
BigtableDataSettings.Builder settings =
Expand Down
2 changes: 2 additions & 0 deletions synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def main():
'CONTRIBUTING.md',
# exclude autogen
'codecov.yaml'
# needed for extraFiles
'.github/release-please.yml',
])

def generate_data_api(gapic):
Expand Down

0 comments on commit 1af8925

Please sign in to comment.