Skip to content

Commit 9a2e054

Browse files
committed
fix dependency
1 parent d7d59d0 commit 9a2e054

File tree

7 files changed

+106
-110
lines changed

7 files changed

+106
-110
lines changed

google-cloud-bigtable-stats/pom.xml

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@
2525
<type>pom</type>
2626
<scope>import</scope>
2727
</dependency>
28+
<dependency>
29+
<groupId>io.opencensus</groupId>
30+
<artifactId>opencensus-exporter-metrics-util</artifactId>
31+
<version>0.31.1</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>com.google.cloud</groupId>
35+
<artifactId>google-cloud-monitoring</artifactId>
36+
<version>3.3.1</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>com.google.api.grpc</groupId>
40+
<artifactId>proto-google-cloud-monitoring-v3</artifactId>
41+
<version>3.3.1</version>
42+
</dependency>
2843
</dependencies>
2944
</dependencyManagement>
3045

@@ -40,32 +55,52 @@
4055
<dependency>
4156
<groupId>com.google.cloud</groupId>
4257
<artifactId>google-cloud-monitoring</artifactId>
43-
<version>3.3.1</version>
4458
</dependency>
4559
<dependency>
4660
<groupId>io.opencensus</groupId>
4761
<artifactId>opencensus-api</artifactId>
4862
</dependency>
63+
<dependency>
64+
<groupId>com.google.auth</groupId>
65+
<artifactId>google-auth-library-credentials</artifactId>
66+
</dependency>
67+
<dependency>
68+
<groupId>com.google.api.grpc</groupId>
69+
<artifactId>proto-google-cloud-monitoring-v3</artifactId>
70+
</dependency>
71+
<dependency>
72+
<groupId>com.google.api</groupId>
73+
<artifactId>gax-grpc</artifactId>
74+
</dependency>
75+
<dependency>
76+
<groupId>org.threeten</groupId>
77+
<artifactId>threetenbp</artifactId>
78+
</dependency>
79+
<dependency>
80+
<groupId>com.google.protobuf</groupId>
81+
<artifactId>protobuf-java</artifactId>
82+
</dependency>
4983
<dependency>
5084
<groupId>io.opencensus</groupId>
51-
<artifactId>opencensus-exporter-stats-stackdriver</artifactId>
52-
<exclusions>
53-
<exclusion>
54-
<groupId>com.google.cloud</groupId>
55-
<artifactId>google-cloud-monitoring</artifactId>
56-
</exclusion>
57-
</exclusions>
85+
<artifactId>opencensus-exporter-metrics-util</artifactId>
5886
</dependency>
5987
<dependency>
6088
<groupId>com.google.guava</groupId>
6189
<artifactId>guava</artifactId>
6290
</dependency>
63-
91+
<dependency>
92+
<groupId>com.google.api.grpc</groupId>
93+
<artifactId>proto-google-common-protos</artifactId>
94+
</dependency>
6495
<dependency>
6596
<groupId>io.opencensus</groupId>
6697
<artifactId>opencensus-impl</artifactId>
6798
<scope>runtime</scope>
6899
</dependency>
100+
<dependency>
101+
<groupId>com.google.code.findbugs</groupId>
102+
<artifactId>jsr305</artifactId>
103+
</dependency>
69104
<dependency>
70105
<groupId>com.google.truth</groupId>
71106
<artifactId>truth</artifactId>

google-cloud-bigtable-stats/src/main/java/com/google/cloud/bigtable/stats/BigtableCreateTimeSeriesExporter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 Google LLC
2+
* Copyright 2022 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.
@@ -34,10 +34,12 @@
3434
final class BigtableCreateTimeSeriesExporter extends MetricExporter {
3535
private static final Logger logger =
3636
Logger.getLogger(BigtableCreateTimeSeriesExporter.class.getName());
37+
38+
private static final String DOMAIN = "bigtable.googleapis.com/internal/client/";
39+
3740
private final ProjectName projectName;
3841
private final MetricServiceClient metricServiceClient;
3942
private final MonitoredResource monitoredResource;
40-
private final String domain;
4143

4244
BigtableCreateTimeSeriesExporter(
4345
String projectId,
@@ -46,7 +48,6 @@ final class BigtableCreateTimeSeriesExporter extends MetricExporter {
4648
this.projectName = ProjectName.newBuilder().setProject(projectId).build();
4749
this.metricServiceClient = metricServiceClient;
4850
this.monitoredResource = monitoredResource;
49-
this.domain = "bigtable.googleapis.com/client/";
5051
}
5152

5253
public void export(Collection<Metric> metrics) {
@@ -101,8 +102,7 @@ public void export(Collection<Metric> metrics) {
101102
updatedValues,
102103
timeSeries,
103104
monitoredResourceBuilder.build(),
104-
this.domain,
105-
this.projectName.getProject()));
105+
DOMAIN));
106106
}
107107
}
108108

google-cloud-bigtable-stats/src/main/java/com/google/cloud/bigtable/stats/BigtableStackdriverExportUtils.java

Lines changed: 38 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 Google LLC
2+
* Copyright 2022 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.
@@ -26,9 +26,7 @@
2626
import com.google.monitoring.v3.TypedValue;
2727
import com.google.protobuf.Any;
2828
import com.google.protobuf.ByteString;
29-
import io.opencensus.common.Function;
3029
import io.opencensus.common.Functions;
31-
import io.opencensus.contrib.exemplar.util.AttachmentValueSpanContext;
3230
import io.opencensus.metrics.LabelKey;
3331
import io.opencensus.metrics.LabelValue;
3432
import io.opencensus.metrics.data.AttachmentValue;
@@ -115,8 +113,7 @@ static TimeSeries convertTimeSeries(
115113
List<LabelValue> labelValues,
116114
io.opencensus.metrics.export.TimeSeries timeSeries,
117115
MonitoredResource monitoredResource,
118-
String domain,
119-
String projectId) {
116+
String domain) {
120117

121118
TimeSeries.Builder builder = TimeSeries.newBuilder();
122119
builder.setMetricKind(createMetricKind(metricType));
@@ -138,9 +135,9 @@ static com.google.api.Metric createMetric(
138135
Map<String, String> stringTagMap = Maps.newHashMap();
139136

140137
for (int i = 0; i < labelValues.size(); ++i) {
141-
String value = ((LabelValue) labelValues.get(i)).getValue();
138+
String value = labelValues.get(i).getValue();
142139
if (value != null) {
143-
stringTagMap.put(((LabelKey) labelKeys.get(i)).getKey(), value);
140+
stringTagMap.put(labelKeys.get(i).getKey(), value);
144141
}
145142
}
146143

@@ -166,13 +163,12 @@ static com.google.monitoring.v3.Point createPoint(
166163

167164
@VisibleForTesting
168165
static TypedValue createTypedValue(Value value) {
169-
return (TypedValue)
170-
value.match(
171-
typedValueDoubleFunction,
172-
typedValueLongFunction,
173-
typedValueDistributionFunction,
174-
typedValueSummaryFunction,
175-
Functions.throwIllegalArgumentException());
166+
return value.match(
167+
typedValueDoubleFunction,
168+
typedValueLongFunction,
169+
typedValueDistributionFunction,
170+
typedValueSummaryFunction,
171+
Functions.throwIllegalArgumentException());
176172
}
177173

178174
@VisibleForTesting
@@ -197,9 +193,8 @@ static BucketOptions createBucketOptions(
197193
com.google.api.Distribution.BucketOptions.Builder builder = BucketOptions.newBuilder();
198194
return bucketOptions == null
199195
? builder.build()
200-
: (BucketOptions)
201-
bucketOptions.match(
202-
bucketOptionsExplicitFunction, Functions.throwIllegalArgumentException());
196+
: bucketOptions.match(
197+
bucketOptionsExplicitFunction, Functions.throwIllegalArgumentException());
203198
}
204199

205200
static MonitoredResource getDefaultResource() {
@@ -227,16 +222,11 @@ private static com.google.api.Distribution.Exemplar toProtoExemplar(
227222
com.google.api.Distribution.Exemplar.newBuilder()
228223
.setValue(exemplar.getValue())
229224
.setTimestamp(convertTimestamp(exemplar.getTimestamp()));
230-
io.opencensus.trace.SpanContext spanContext = null;
231225

232226
for (Map.Entry<String, AttachmentValue> attachment : exemplar.getAttachments().entrySet()) {
233-
String key = (String) attachment.getKey();
234-
AttachmentValue value = (AttachmentValue) attachment.getValue();
235-
if ("SpanContext".equals(key)) {
236-
spanContext = ((AttachmentValueSpanContext) value).getSpanContext();
237-
} else {
238-
builder.addAttachments(toProtoStringAttachment(value));
239-
}
227+
String key = attachment.getKey();
228+
AttachmentValue value = attachment.getValue();
229+
builder.addAttachments(toProtoStringAttachment(value));
240230
}
241231

242232
return builder.build();
@@ -249,25 +239,6 @@ private static Any toProtoStringAttachment(AttachmentValue attachmentValue) {
249239
.build();
250240
}
251241

252-
private static Any toProtoSpanContextAttachment(
253-
com.google.monitoring.v3.SpanContext protoSpanContext) {
254-
return Any.newBuilder()
255-
.setTypeUrl("type.googleapis.com/google.monitoring.v3.SpanContext")
256-
.setValue(protoSpanContext.toByteString())
257-
.build();
258-
}
259-
260-
private static com.google.monitoring.v3.SpanContext toProtoSpanContext(
261-
io.opencensus.trace.SpanContext spanContext, String projectId) {
262-
String spanName =
263-
String.format(
264-
"projects/%s/traces/%s/spans/%s",
265-
projectId,
266-
spanContext.getTraceId().toLowerBase16(),
267-
spanContext.getSpanId().toLowerBase16());
268-
return com.google.monitoring.v3.SpanContext.newBuilder().setSpanName(spanName).build();
269-
}
270-
271242
@VisibleForTesting
272243
static com.google.protobuf.Timestamp convertTimestamp(
273244
io.opencensus.common.Timestamp censusTimestamp) {
@@ -284,48 +255,37 @@ private BigtableStackdriverExportUtils() {}
284255
static {
285256
logger = Logger.getLogger(BigtableStackdriverExportUtils.class.getName());
286257
typedValueDoubleFunction =
287-
new io.opencensus.common.Function<Double, TypedValue>() {
288-
public TypedValue apply(Double arg) {
289-
com.google.monitoring.v3.TypedValue.Builder builder = TypedValue.newBuilder();
290-
builder.setDoubleValue(arg);
291-
return builder.build();
292-
}
258+
arg -> {
259+
TypedValue.Builder builder = TypedValue.newBuilder();
260+
builder.setDoubleValue(arg);
261+
return builder.build();
293262
};
294263
typedValueLongFunction =
295-
new io.opencensus.common.Function<Long, TypedValue>() {
296-
public TypedValue apply(Long arg) {
297-
com.google.monitoring.v3.TypedValue.Builder builder = TypedValue.newBuilder();
298-
builder.setInt64Value(arg);
299-
return builder.build();
300-
}
264+
arg -> {
265+
TypedValue.Builder builder = TypedValue.newBuilder();
266+
builder.setInt64Value(arg);
267+
return builder.build();
301268
};
302269
typedValueDistributionFunction =
303-
new io.opencensus.common.Function<io.opencensus.metrics.export.Distribution, TypedValue>() {
304-
public TypedValue apply(io.opencensus.metrics.export.Distribution arg) {
305-
com.google.monitoring.v3.TypedValue.Builder builder = TypedValue.newBuilder();
306-
return builder
307-
.setDistributionValue(BigtableStackdriverExportUtils.createDistribution(arg))
308-
.build();
309-
}
270+
arg -> {
271+
TypedValue.Builder builder = TypedValue.newBuilder();
272+
return builder
273+
.setDistributionValue(BigtableStackdriverExportUtils.createDistribution(arg))
274+
.build();
310275
};
311276
typedValueSummaryFunction =
312-
new io.opencensus.common.Function<Summary, TypedValue>() {
313-
public TypedValue apply(Summary arg) {
314-
com.google.monitoring.v3.TypedValue.Builder builder = TypedValue.newBuilder();
315-
return builder.build();
316-
}
277+
arg -> {
278+
TypedValue.Builder builder = TypedValue.newBuilder();
279+
return builder.build();
317280
};
318281
bucketOptionsExplicitFunction =
319-
new Function<ExplicitOptions, BucketOptions>() {
320-
public BucketOptions apply(ExplicitOptions arg) {
321-
com.google.api.Distribution.BucketOptions.Builder builder = BucketOptions.newBuilder();
322-
com.google.api.Distribution.BucketOptions.Explicit.Builder explicitBuilder =
323-
Explicit.newBuilder();
324-
explicitBuilder.addBounds(0.0D);
325-
explicitBuilder.addAllBounds(arg.getBucketBoundaries());
326-
builder.setExplicitBuckets(explicitBuilder.build());
327-
return builder.build();
328-
}
282+
arg -> {
283+
BucketOptions.Builder builder = BucketOptions.newBuilder();
284+
Explicit.Builder explicitBuilder = Explicit.newBuilder();
285+
explicitBuilder.addBounds(0.0D);
286+
explicitBuilder.addAllBounds(arg.getBucketBoundaries());
287+
builder.setExplicitBuckets(explicitBuilder.build());
288+
return builder.build();
329289
};
330290
}
331291
}

google-cloud-bigtable-stats/src/main/java/com/google/cloud/bigtable/stats/BigtableStackdriverStatsExporter.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 Google LLC
2+
* Copyright 2022 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.
@@ -36,17 +36,14 @@
3636
@ThreadSafe
3737
@InternalApi
3838
public class BigtableStackdriverStatsExporter {
39-
@VisibleForTesting static final Object monitor = new Object();
39+
static final Object monitor = new Object();
4040

4141
@Nullable
4242
@GuardedBy("monitor")
4343
private static BigtableStackdriverStatsExporter instance = null;
4444

45-
private static final String EXPORTER_SPAN_NAME = "ExportMetricsToStackdriver";
46-
// private static final String USER_AGENT_KEY = "user-agent";
47-
// private static final String USER_AGENT = "bigtable-java" + Version.VERSION;
48-
// private static final HeaderProvider OPENCENSUS_USER_AGENT_HEADER_PROVIDER =
49-
// FixedHeaderProvider.create(new String[] {USER_AGENT_KEY, USER_AGENT});
45+
private static final String EXPORTER_SPAN_NAME = "BigtableExportMetricsToStackdriver";
46+
private static final Duration EXPORT_INTERVAL = Duration.create(600, 0);
5047
private final IntervalMetricReader intervalMetricReader;
5148

5249
private BigtableStackdriverStatsExporter(
@@ -72,13 +69,14 @@ private BigtableStackdriverStatsExporter(
7269
public static void register(@Nullable Credentials credentials, String projectId)
7370
throws IOException {
7471
synchronized (monitor) {
75-
Preconditions.checkState(instance == null, "Stackdriver stats exporter is already created");
72+
Preconditions.checkState(
73+
instance == null, "Bigtable Stackdriver stats exporter is already created");
7674
MetricServiceClient client = createMetricServiceClient(credentials, Duration.create(60L, 0));
7775
instance =
7876
new BigtableStackdriverStatsExporter(
7977
projectId,
8078
client,
81-
Duration.create(600, 0),
79+
EXPORT_INTERVAL,
8280
BigtableStackdriverExportUtils.getDefaultResource());
8381
}
8482
}
@@ -88,13 +86,8 @@ public static void register(@Nullable Credentials credentials, String projectId)
8886
static MetricServiceClient createMetricServiceClient(
8987
@Nullable Credentials credentials, Duration deadline) throws IOException {
9088
com.google.cloud.monitoring.v3.MetricServiceSettings.Builder settingsBuilder =
91-
(com.google.cloud.monitoring.v3.MetricServiceSettings.Builder)
92-
MetricServiceSettings.newBuilder()
93-
.setTransportChannelProvider(
94-
InstantiatingGrpcChannelProvider.newBuilder()
95-
//
96-
// .setHeaderProvider(OPENCENSUS_USER_AGENT_HEADER_PROVIDER)
97-
.build());
89+
MetricServiceSettings.newBuilder()
90+
.setTransportChannelProvider(InstantiatingGrpcChannelProvider.newBuilder().build());
9891
if (credentials != null) {
9992
settingsBuilder.setCredentialsProvider(FixedCredentialsProvider.create(credentials));
10093
}

google-cloud-bigtable-stats/src/test/java/com/google/cloud/bigtable/stats/BigtableCreateTimeSeriesExporterTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121

2222
import com.google.api.MonitoredResource;
2323
import com.google.api.gax.rpc.UnaryCallable;
24-
import com.google.cloud.bigtable.stats.BigtableCreateTimeSeriesExporter;
25-
import com.google.cloud.bigtable.stats.BuiltinMeasureConstants;
2624
import com.google.cloud.monitoring.v3.MetricServiceClient;
2725
import com.google.cloud.monitoring.v3.stub.MetricServiceStub;
2826
import com.google.monitoring.v3.CreateTimeSeriesRequest;

google-cloud-bigtable/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,17 @@
6060
<dependencies>
6161
<!-- NOTE: Dependencies are organized into two groups, production and test.
6262
Within a group, dependencies are sorted by (groupId, artifactId) -->
63+
6364
<dependency>
6465
<groupId>com.google.cloud</groupId>
6566
<artifactId>google-cloud-bigtable-stats</artifactId>
67+
<!-- Exclude all the shaded artifacts -->
68+
<exclusions>
69+
<exclusion>
70+
<groupId>io.opencensus</groupId>
71+
<artifactId>*</artifactId>
72+
</exclusion>
73+
</exclusions>
6674
</dependency>
6775
<!-- Production dependencies -->
6876
<dependency>

0 commit comments

Comments
 (0)