Skip to content
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

chore: make version embedding more robust #451

Merged
merged 3 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2020 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 com.google.api.core.InternalApi;

/** Utility to get the current version of the Bigtable client. */
@InternalApi("For internal use only")
// Note: this file MUST be named GoogleUtils.java so that it can be picked up by releasetool
public class GoogleUtils {
public static final String BIGTABLE_CLIENT_VERSION =
"1.16.1-SNAPSHOT"; // {x-version-update:google-cloud-bigtable:current}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chingor13, to get this to work, I'm guessing we need to add a path here? https://github.com/googleapis/release-please/blob/master/src/releasers/java-yoshi.ts#L182 Any thing else?

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.api.gax.batching.BatchingSettings;
import com.google.api.gax.batching.FlowControlSettings;
import com.google.api.gax.batching.FlowController.LimitExceededBehavior;
import com.google.api.gax.core.GaxProperties;
import com.google.api.gax.core.GoogleCredentialsProvider;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
import com.google.api.gax.retrying.RetrySettings;
Expand All @@ -30,6 +29,7 @@
import com.google.api.gax.rpc.StubSettings;
import com.google.api.gax.rpc.TransportChannelProvider;
import com.google.api.gax.rpc.UnaryCallSettings;
import com.google.cloud.bigtable.GoogleUtils;
import com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation;
import com.google.cloud.bigtable.data.v2.models.KeyOffset;
import com.google.cloud.bigtable.data.v2.models.Query;
Expand Down Expand Up @@ -544,10 +544,7 @@ private Builder() {
.putAll(
BigtableStubSettings.defaultApiClientHeaderProviderBuilder().build().getHeaders())
// GrpcHeaderInterceptor treats the `user-agent` as a magic string
.put(
"user-agent",
"bigtable-java/"
+ GaxProperties.getLibraryVersion(EnhancedBigtableStubSettings.class))
.put("user-agent", "bigtable-java/" + GoogleUtils.BIGTABLE_CLIENT_VERSION)
.build();
setInternalHeaderProvider(FixedHeaderProvider.create(headers));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void testUserAgent() throws InterruptedException {
assertThat(metadataInterceptor.headers).hasSize(1);
Metadata metadata = metadataInterceptor.headers.take();
assertThat(metadata.get(Metadata.Key.of("user-agent", Metadata.ASCII_STRING_MARSHALLER)))
.contains("bigtable-java/");
.containsMatch("bigtable-java/\\d+\\.\\d+\\.\\d+(?:-SNAPSHOT)?");
}

private static class MetadataInterceptor implements ServerInterceptor {
Expand Down