Skip to content

Commit

Permalink
fix dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mutianf committed Jul 12, 2022
1 parent d7d59d0 commit 9a2e054
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 110 deletions.
53 changes: 44 additions & 9 deletions google-cloud-bigtable-stats/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-exporter-metrics-util</artifactId>
<version>0.31.1</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-monitoring</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-monitoring-v3</artifactId>
<version>3.3.1</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand All @@ -40,32 +55,52 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-monitoring</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-api</artifactId>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-credentials</artifactId>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-monitoring-v3</artifactId>
</dependency>
<dependency>
<groupId>com.google.api</groupId>
<artifactId>gax-grpc</artifactId>
</dependency>
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-exporter-stats-stackdriver</artifactId>
<exclusions>
<exclusion>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-monitoring</artifactId>
</exclusion>
</exclusions>
<artifactId>opencensus-exporter-metrics-util</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-common-protos</artifactId>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-impl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</dependency>
<dependency>
<groupId>com.google.truth</groupId>
<artifactId>truth</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Google LLC
* Copyright 2022 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 Down Expand Up @@ -34,10 +34,12 @@
final class BigtableCreateTimeSeriesExporter extends MetricExporter {
private static final Logger logger =
Logger.getLogger(BigtableCreateTimeSeriesExporter.class.getName());

private static final String DOMAIN = "bigtable.googleapis.com/internal/client/";

private final ProjectName projectName;
private final MetricServiceClient metricServiceClient;
private final MonitoredResource monitoredResource;
private final String domain;

BigtableCreateTimeSeriesExporter(
String projectId,
Expand All @@ -46,7 +48,6 @@ final class BigtableCreateTimeSeriesExporter extends MetricExporter {
this.projectName = ProjectName.newBuilder().setProject(projectId).build();
this.metricServiceClient = metricServiceClient;
this.monitoredResource = monitoredResource;
this.domain = "bigtable.googleapis.com/client/";
}

public void export(Collection<Metric> metrics) {
Expand Down Expand Up @@ -101,8 +102,7 @@ public void export(Collection<Metric> metrics) {
updatedValues,
timeSeries,
monitoredResourceBuilder.build(),
this.domain,
this.projectName.getProject()));
DOMAIN));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Google LLC
* Copyright 2022 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 @@ -26,9 +26,7 @@
import com.google.monitoring.v3.TypedValue;
import com.google.protobuf.Any;
import com.google.protobuf.ByteString;
import io.opencensus.common.Function;
import io.opencensus.common.Functions;
import io.opencensus.contrib.exemplar.util.AttachmentValueSpanContext;
import io.opencensus.metrics.LabelKey;
import io.opencensus.metrics.LabelValue;
import io.opencensus.metrics.data.AttachmentValue;
Expand Down Expand Up @@ -115,8 +113,7 @@ static TimeSeries convertTimeSeries(
List<LabelValue> labelValues,
io.opencensus.metrics.export.TimeSeries timeSeries,
MonitoredResource monitoredResource,
String domain,
String projectId) {
String domain) {

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

for (int i = 0; i < labelValues.size(); ++i) {
String value = ((LabelValue) labelValues.get(i)).getValue();
String value = labelValues.get(i).getValue();
if (value != null) {
stringTagMap.put(((LabelKey) labelKeys.get(i)).getKey(), value);
stringTagMap.put(labelKeys.get(i).getKey(), value);
}
}

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

@VisibleForTesting
static TypedValue createTypedValue(Value value) {
return (TypedValue)
value.match(
typedValueDoubleFunction,
typedValueLongFunction,
typedValueDistributionFunction,
typedValueSummaryFunction,
Functions.throwIllegalArgumentException());
return value.match(
typedValueDoubleFunction,
typedValueLongFunction,
typedValueDistributionFunction,
typedValueSummaryFunction,
Functions.throwIllegalArgumentException());
}

@VisibleForTesting
Expand All @@ -197,9 +193,8 @@ static BucketOptions createBucketOptions(
com.google.api.Distribution.BucketOptions.Builder builder = BucketOptions.newBuilder();
return bucketOptions == null
? builder.build()
: (BucketOptions)
bucketOptions.match(
bucketOptionsExplicitFunction, Functions.throwIllegalArgumentException());
: bucketOptions.match(
bucketOptionsExplicitFunction, Functions.throwIllegalArgumentException());
}

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

for (Map.Entry<String, AttachmentValue> attachment : exemplar.getAttachments().entrySet()) {
String key = (String) attachment.getKey();
AttachmentValue value = (AttachmentValue) attachment.getValue();
if ("SpanContext".equals(key)) {
spanContext = ((AttachmentValueSpanContext) value).getSpanContext();
} else {
builder.addAttachments(toProtoStringAttachment(value));
}
String key = attachment.getKey();
AttachmentValue value = attachment.getValue();
builder.addAttachments(toProtoStringAttachment(value));
}

return builder.build();
Expand All @@ -249,25 +239,6 @@ private static Any toProtoStringAttachment(AttachmentValue attachmentValue) {
.build();
}

private static Any toProtoSpanContextAttachment(
com.google.monitoring.v3.SpanContext protoSpanContext) {
return Any.newBuilder()
.setTypeUrl("type.googleapis.com/google.monitoring.v3.SpanContext")
.setValue(protoSpanContext.toByteString())
.build();
}

private static com.google.monitoring.v3.SpanContext toProtoSpanContext(
io.opencensus.trace.SpanContext spanContext, String projectId) {
String spanName =
String.format(
"projects/%s/traces/%s/spans/%s",
projectId,
spanContext.getTraceId().toLowerBase16(),
spanContext.getSpanId().toLowerBase16());
return com.google.monitoring.v3.SpanContext.newBuilder().setSpanName(spanName).build();
}

@VisibleForTesting
static com.google.protobuf.Timestamp convertTimestamp(
io.opencensus.common.Timestamp censusTimestamp) {
Expand All @@ -284,48 +255,37 @@ private BigtableStackdriverExportUtils() {}
static {
logger = Logger.getLogger(BigtableStackdriverExportUtils.class.getName());
typedValueDoubleFunction =
new io.opencensus.common.Function<Double, TypedValue>() {
public TypedValue apply(Double arg) {
com.google.monitoring.v3.TypedValue.Builder builder = TypedValue.newBuilder();
builder.setDoubleValue(arg);
return builder.build();
}
arg -> {
TypedValue.Builder builder = TypedValue.newBuilder();
builder.setDoubleValue(arg);
return builder.build();
};
typedValueLongFunction =
new io.opencensus.common.Function<Long, TypedValue>() {
public TypedValue apply(Long arg) {
com.google.monitoring.v3.TypedValue.Builder builder = TypedValue.newBuilder();
builder.setInt64Value(arg);
return builder.build();
}
arg -> {
TypedValue.Builder builder = TypedValue.newBuilder();
builder.setInt64Value(arg);
return builder.build();
};
typedValueDistributionFunction =
new io.opencensus.common.Function<io.opencensus.metrics.export.Distribution, TypedValue>() {
public TypedValue apply(io.opencensus.metrics.export.Distribution arg) {
com.google.monitoring.v3.TypedValue.Builder builder = TypedValue.newBuilder();
return builder
.setDistributionValue(BigtableStackdriverExportUtils.createDistribution(arg))
.build();
}
arg -> {
TypedValue.Builder builder = TypedValue.newBuilder();
return builder
.setDistributionValue(BigtableStackdriverExportUtils.createDistribution(arg))
.build();
};
typedValueSummaryFunction =
new io.opencensus.common.Function<Summary, TypedValue>() {
public TypedValue apply(Summary arg) {
com.google.monitoring.v3.TypedValue.Builder builder = TypedValue.newBuilder();
return builder.build();
}
arg -> {
TypedValue.Builder builder = TypedValue.newBuilder();
return builder.build();
};
bucketOptionsExplicitFunction =
new Function<ExplicitOptions, BucketOptions>() {
public BucketOptions apply(ExplicitOptions arg) {
com.google.api.Distribution.BucketOptions.Builder builder = BucketOptions.newBuilder();
com.google.api.Distribution.BucketOptions.Explicit.Builder explicitBuilder =
Explicit.newBuilder();
explicitBuilder.addBounds(0.0D);
explicitBuilder.addAllBounds(arg.getBucketBoundaries());
builder.setExplicitBuckets(explicitBuilder.build());
return builder.build();
}
arg -> {
BucketOptions.Builder builder = BucketOptions.newBuilder();
Explicit.Builder explicitBuilder = Explicit.newBuilder();
explicitBuilder.addBounds(0.0D);
explicitBuilder.addAllBounds(arg.getBucketBoundaries());
builder.setExplicitBuckets(explicitBuilder.build());
return builder.build();
};
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 Google LLC
* Copyright 2022 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 Down Expand Up @@ -36,17 +36,14 @@
@ThreadSafe
@InternalApi
public class BigtableStackdriverStatsExporter {
@VisibleForTesting static final Object monitor = new Object();
static final Object monitor = new Object();

@Nullable
@GuardedBy("monitor")
private static BigtableStackdriverStatsExporter instance = null;

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

private BigtableStackdriverStatsExporter(
Expand All @@ -72,13 +69,14 @@ private BigtableStackdriverStatsExporter(
public static void register(@Nullable Credentials credentials, String projectId)
throws IOException {
synchronized (monitor) {
Preconditions.checkState(instance == null, "Stackdriver stats exporter is already created");
Preconditions.checkState(
instance == null, "Bigtable Stackdriver stats exporter is already created");
MetricServiceClient client = createMetricServiceClient(credentials, Duration.create(60L, 0));
instance =
new BigtableStackdriverStatsExporter(
projectId,
client,
Duration.create(600, 0),
EXPORT_INTERVAL,
BigtableStackdriverExportUtils.getDefaultResource());
}
}
Expand All @@ -88,13 +86,8 @@ public static void register(@Nullable Credentials credentials, String projectId)
static MetricServiceClient createMetricServiceClient(
@Nullable Credentials credentials, Duration deadline) throws IOException {
com.google.cloud.monitoring.v3.MetricServiceSettings.Builder settingsBuilder =
(com.google.cloud.monitoring.v3.MetricServiceSettings.Builder)
MetricServiceSettings.newBuilder()
.setTransportChannelProvider(
InstantiatingGrpcChannelProvider.newBuilder()
//
// .setHeaderProvider(OPENCENSUS_USER_AGENT_HEADER_PROVIDER)
.build());
MetricServiceSettings.newBuilder()
.setTransportChannelProvider(InstantiatingGrpcChannelProvider.newBuilder().build());
if (credentials != null) {
settingsBuilder.setCredentialsProvider(FixedCredentialsProvider.create(credentials));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import com.google.api.MonitoredResource;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.bigtable.stats.BigtableCreateTimeSeriesExporter;
import com.google.cloud.bigtable.stats.BuiltinMeasureConstants;
import com.google.cloud.monitoring.v3.MetricServiceClient;
import com.google.cloud.monitoring.v3.stub.MetricServiceStub;
import com.google.monitoring.v3.CreateTimeSeriesRequest;
Expand Down
8 changes: 8 additions & 0 deletions google-cloud-bigtable/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,17 @@
<dependencies>
<!-- NOTE: Dependencies are organized into two groups, production and test.
Within a group, dependencies are sorted by (groupId, artifactId) -->

<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bigtable-stats</artifactId>
<!-- Exclude all the shaded artifacts -->
<exclusions>
<exclusion>
<groupId>io.opencensus</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Production dependencies -->
<dependency>
Expand Down
Loading

0 comments on commit 9a2e054

Please sign in to comment.