Skip to content

Commit c27ed8f

Browse files
authored
Bump otel version and get ready for stable metrics release. (#154)
* Bump to stable OTEL metrics version and start cleaning up javadoc/public API for stable metrics exporter release. * Remove -alpha qualifier from metrics exporter release. * Fix build breakage, need semconv for tests. * Update metric config to use endpoint instead of stub for alternative endpoints. * Expose endpoint config for trace exporter. * cleanups. * Spotless apply * Fix CI build failure. * Fix other test failure. * Fix code review comments. * Rename metric exporter to avoid name clash. * Fix e2e test docker file. * Run spotless.
1 parent a635ba1 commit c27ed8f

File tree

23 files changed

+251
-260
lines changed

23 files changed

+251
-260
lines changed

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ subprojects {
109109
googleCloudVersion = '2.0.5'
110110
googleTraceVersion = '2.0.0'
111111
cloudMonitoringVersion = '3.0.0'
112-
openTelemetryVersion = '1.13.0'
113-
openTelemetryInstrumentationVersion = '1.13.0'
112+
openTelemetryVersion = '1.15.0'
113+
openTelemetryInstrumentationVersion = '1.14.0'
114114
junitVersion = '4.13'
115115
mockitoVersion = '3.5.10'
116116
pubSubVersion = '1.111.2'
@@ -139,7 +139,7 @@ subprojects {
139139
opentelemetry_autoconfigure_spi : "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure-spi:${openTelemetryVersion}",
140140
opentelemetry_autoconfigure : "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:${openTelemetryVersion}-alpha",
141141
opentelemetry_semconv : "io.opentelemetry:opentelemetry-semconv:${openTelemetryVersion}-alpha",
142-
opentelemetry_sdk_metrics : "io.opentelemetry:opentelemetry-sdk-metrics:${openTelemetryVersion}-alpha",
142+
opentelemetry_sdk_metrics : "io.opentelemetry:opentelemetry-sdk-metrics:${openTelemetryVersion}",
143143
opentelemetry_sdk_autoconf : "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:${openTelemetryVersion}-alpha",
144144
opentelemetry_sdk_resources : "io.opentelemetry:opentelemetry-sdk-extension-resources:${openTelemetryVersion}",
145145
opentelemetry_agent_extension: "io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:${openTelemetryInstrumentationVersion}-alpha",

examples/metrics/src/main/java/com/google/cloud/opentelemetry/example/metrics/MetricsExporterExample.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.google.cloud.opentelemetry.example.metrics;
1717

18-
import com.google.cloud.opentelemetry.metric.MetricExporter;
18+
import com.google.cloud.opentelemetry.metric.GoogleCloudMetricExporter;
1919
import io.opentelemetry.api.metrics.LongCounter;
2020
import io.opentelemetry.api.metrics.Meter;
2121
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
@@ -31,7 +31,8 @@ public class MetricsExporterExample {
3131

3232
private static void setupMetricExporter() {
3333
try {
34-
MetricExporter metricExporter = MetricExporter.createWithDefaultConfiguration();
34+
GoogleCloudMetricExporter metricExporter =
35+
GoogleCloudMetricExporter.createWithDefaultConfiguration();
3536
METER_PROVIDER =
3637
SdkMeterProvider.builder()
3738
.registerMetricReader(

exporters/auto/src/main/java/com/google/cloud/opentelemetry/auto/GoogleCloudMetricExporterFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
package com.google.cloud.opentelemetry.auto;
1717

1818
import com.google.auto.service.AutoService;
19-
import com.google.cloud.opentelemetry.metric.MetricExporter;
19+
import com.google.cloud.opentelemetry.metric.GoogleCloudMetricExporter;
2020
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
2121
import io.opentelemetry.sdk.autoconfigure.spi.metrics.ConfigurableMetricExporterProvider;
2222
import java.io.IOException;
2323

2424
@AutoService(ConfigurableMetricExporterProvider.class)
2525
public class GoogleCloudMetricExporterFactory implements ConfigurableMetricExporterProvider {
2626
@Override
27-
public MetricExporter createExporter(ConfigProperties config) {
27+
public GoogleCloudMetricExporter createExporter(ConfigProperties config) {
2828
try {
29-
return MetricExporter.createWithDefaultConfiguration();
29+
return GoogleCloudMetricExporter.createWithDefaultConfiguration();
3030
} catch (IOException ex) {
3131
throw new RuntimeException(ex);
3232
}

exporters/metrics/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ import io.opentelemetry.sdk.metrics.SdkMeterProvider;
3535

3636
import com.google.cloud.opentelemetry.metric.MetricConfiguration;
3737
import com.google.cloud.opentelemetry.metric.MetricDescriptorStrategy;
38+
import com.google.cloud.opentelemetry.metric.GoogleCloudMetricExporter;
3839

3940
import java.util.Collections;
4041

4142
// Configure the exporter in code.
4243
MetricExporter cloudMonitoringExporter =
43-
com.google.cloud.opentelemetry.metric.MetricExporter.createWithConfiguration(
44+
GoogleCloudMetricExporter.createWithConfiguration(
4445
MetricConfiguration.builder()
4546
// Configure the cloud project id. Note: this is autodiscovered by default.
4647
.setProjectId(...)
@@ -59,7 +60,9 @@ MeterProvider provider = SdkMeterProvider.builder()
5960
// See https://cloud.google.com/monitoring/quotas#custom_metrics_quotas
6061
// Rate at which data can be written to a single time series: one point each 10
6162
// seconds.
62-
PeriodicMetricReader.create(metricExporter, java.time.Duration.ofSeconds(20)))
63+
PeriodicMetricReader.builder(metricExporter)
64+
.setImterval(java.time.Duration.ofSeconds(20))
65+
.build())
6366
.build();
6467
```
6568

exporters/metrics/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ dependencies {
2424
api(libraries.google_cloud_core)
2525
api(libraries.google_cloud_monitoring)
2626
implementation(project(':shared-resourcemapping'))
27-
implementation(libraries.opentelemetry_semconv)
27+
testImplementation(libraries.opentelemetry_semconv)
2828
testImplementation(testLibraries.junit)
2929
testImplementation(testLibraries.mockito)
3030
testImplementation(testLibraries.slf4j_simple)
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
release.qualifier=alpha
21
release.enabled=true

exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/AggregateByLabelMetricTimeSeriesBuilder.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import static com.google.cloud.opentelemetry.metric.ResourceTranslator.mapResource;
2323

2424
import com.google.api.MetricDescriptor;
25-
import com.google.cloud.opentelemetry.metric.MetricExporter.MetricWithLabels;
25+
import com.google.cloud.opentelemetry.metric.GoogleCloudMetricExporter.MetricWithLabels;
2626
import com.google.monitoring.v3.TimeSeries;
2727
import com.google.monitoring.v3.TypedValue;
2828
import io.opentelemetry.api.common.Attributes;
@@ -36,7 +36,11 @@
3636
import java.util.Map;
3737
import java.util.stream.Collectors;
3838

39-
public class AggregateByLabelMetricTimeSeriesBuilder implements MetricTimeSeriesBuilder {
39+
/**
40+
* Builds GCM TimeSeries from each OTEL metric point, creating metric descriptors based on the
41+
* "first" seen point for any given metric.
42+
*/
43+
public final class AggregateByLabelMetricTimeSeriesBuilder implements MetricTimeSeriesBuilder {
4044

4145
private final Map<String, MetricDescriptor> descriptors = new HashMap<>();
4246
private final Map<MetricWithLabels, TimeSeries.Builder> pendingTimeSeries = new HashMap<>();

exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/CloudMetricClient.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,24 @@
2121
import com.google.monitoring.v3.TimeSeries;
2222
import java.util.List;
2323

24+
/** Wrapper interface for writing to Google Cloud Monitoring. */
2425
public interface CloudMetricClient {
26+
/**
27+
* Construct a metric descriptor.
28+
*
29+
* <p>This informs Cloud Monitoring of label descriptions, metric descriptions, units, etc.
30+
*/
2531
MetricDescriptor createMetricDescriptor(CreateMetricDescriptorRequest request);
2632

33+
/**
34+
* Send a timeseries to Cloud Monitoring.
35+
*
36+
* @param name The name of the project where we write the timeseries.
37+
* @param timeSeries The list of timeseries to write.
38+
* <p>Note: This can only take one point at per timeseries.
39+
*/
2740
void createTimeSeries(ProjectName name, List<TimeSeries> timeSeries);
2841

42+
/** Shutdown this client, cleaning up any resources. */
2943
void shutdown();
3044
}

exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/CloudMetricClientImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import com.google.monitoring.v3.TimeSeries;
2323
import java.util.List;
2424

25-
public class CloudMetricClientImpl implements CloudMetricClient {
25+
/** Directly talks to Cloud Monitoring. */
26+
public final class CloudMetricClientImpl implements CloudMetricClient {
2627
private final MetricServiceClient metricServiceClient;
2728

2829
public CloudMetricClientImpl(MetricServiceClient metricServiceClient) {

exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/MetricExporter.java renamed to exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/GoogleCloudMetricExporter.java

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@
1919

2020
import com.google.api.MetricDescriptor;
2121
import com.google.api.gax.core.FixedCredentialsProvider;
22+
import com.google.api.gax.core.NoCredentialsProvider;
23+
import com.google.api.gax.grpc.GrpcTransportChannel;
24+
import com.google.api.gax.rpc.FixedTransportChannelProvider;
2225
import com.google.auth.Credentials;
2326
import com.google.auth.oauth2.GoogleCredentials;
2427
import com.google.cloud.monitoring.v3.MetricServiceClient;
2528
import com.google.cloud.monitoring.v3.MetricServiceSettings;
26-
import com.google.cloud.monitoring.v3.stub.MetricServiceStub;
2729
import com.google.common.annotations.VisibleForTesting;
2830
import com.google.common.collect.Lists;
2931
import com.google.monitoring.v3.CreateMetricDescriptorRequest;
3032
import com.google.monitoring.v3.ProjectName;
3133
import com.google.monitoring.v3.TimeSeries;
34+
import io.grpc.ManagedChannelBuilder;
3235
import io.opentelemetry.api.common.Attributes;
3336
import io.opentelemetry.sdk.common.CompletableResultCode;
3437
import io.opentelemetry.sdk.metrics.InstrumentType;
@@ -38,17 +41,17 @@
3841
import io.opentelemetry.sdk.metrics.data.LongPointData;
3942
import io.opentelemetry.sdk.metrics.data.MetricData;
4043
import java.io.IOException;
41-
import java.time.Duration;
4244
import java.util.ArrayList;
4345
import java.util.Collection;
4446
import java.util.List;
4547
import java.util.Objects;
4648
import org.slf4j.Logger;
4749
import org.slf4j.LoggerFactory;
4850

49-
public class MetricExporter implements io.opentelemetry.sdk.metrics.export.MetricExporter {
51+
public class GoogleCloudMetricExporter
52+
implements io.opentelemetry.sdk.metrics.export.MetricExporter {
5053

51-
private static final Logger logger = LoggerFactory.getLogger(MetricExporter.class);
54+
private static final Logger logger = LoggerFactory.getLogger(GoogleCloudMetricExporter.class);
5255

5356
private static final String PROJECT_NAME_PREFIX = "projects/";
5457
private static final int MAX_BATCH_SIZE = 200;
@@ -57,67 +60,59 @@ public class MetricExporter implements io.opentelemetry.sdk.metrics.export.Metri
5760
private final String projectId;
5861
private final MetricDescriptorStrategy metricDescriptorStrategy;
5962

60-
MetricExporter(
63+
GoogleCloudMetricExporter(
6164
String projectId, CloudMetricClient client, MetricDescriptorStrategy descriptorStrategy) {
6265
this.projectId = projectId;
6366
this.metricServiceClient = client;
6467
this.metricDescriptorStrategy = descriptorStrategy;
6568
}
6669

67-
public static MetricExporter createWithDefaultConfiguration() throws IOException {
70+
public static GoogleCloudMetricExporter createWithDefaultConfiguration() throws IOException {
6871
MetricConfiguration configuration = MetricConfiguration.builder().build();
69-
return MetricExporter.createWithConfiguration(configuration);
72+
return GoogleCloudMetricExporter.createWithConfiguration(configuration);
7073
}
7174

72-
public static MetricExporter createWithConfiguration(MetricConfiguration configuration)
75+
public static GoogleCloudMetricExporter createWithConfiguration(MetricConfiguration configuration)
7376
throws IOException {
7477
String projectId = configuration.getProjectId();
75-
MetricServiceStub stub = configuration.getMetricServiceStub();
76-
77-
if (stub == null) {
78+
MetricServiceSettings.Builder builder = MetricServiceSettings.newBuilder();
79+
// For testing, we need to hack around our gRPC config.
80+
if (configuration.getInsecureEndpoint()) {
81+
builder.setCredentialsProvider(NoCredentialsProvider.create());
82+
builder.setTransportChannelProvider(
83+
FixedTransportChannelProvider.create(
84+
GrpcTransportChannel.create(
85+
ManagedChannelBuilder.forTarget(configuration.getMetricServiceEndpoint())
86+
.usePlaintext()
87+
.build())));
88+
} else {
89+
// For any other endpoint, we force credentials to exist.
7890
Credentials credentials =
7991
configuration.getCredentials() == null
8092
? GoogleCredentials.getApplicationDefault()
8193
: configuration.getCredentials();
8294

83-
return MetricExporter.createWithCredentials(
84-
projectId,
85-
credentials,
86-
configuration.getDeadline(),
87-
configuration.getDescriptorStrategy());
95+
builder.setCredentialsProvider(
96+
FixedCredentialsProvider.create(checkNotNull(credentials, "Credentials not provided.")));
97+
builder.setEndpoint(configuration.getMetricServiceEndpoint());
8898
}
89-
return MetricExporter.createWithClient(
99+
builder
100+
.createMetricDescriptorSettings()
101+
.setSimpleTimeoutNoRetries(
102+
org.threeten.bp.Duration.ofMillis(configuration.getDeadline().toMillis()));
103+
104+
return new GoogleCloudMetricExporter(
90105
projectId,
91-
new CloudMetricClientImpl(MetricServiceClient.create(stub)),
106+
new CloudMetricClientImpl(MetricServiceClient.create(builder.build())),
92107
configuration.getDescriptorStrategy());
93108
}
94109

95110
@VisibleForTesting
96-
static MetricExporter createWithClient(
111+
static GoogleCloudMetricExporter createWithClient(
97112
String projectId,
98113
CloudMetricClient metricServiceClient,
99114
MetricDescriptorStrategy descriptorStrategy) {
100-
return new MetricExporter(projectId, metricServiceClient, descriptorStrategy);
101-
}
102-
103-
private static MetricExporter createWithCredentials(
104-
String projectId,
105-
Credentials credentials,
106-
Duration deadline,
107-
MetricDescriptorStrategy descriptorStrategy)
108-
throws IOException {
109-
MetricServiceSettings.Builder builder =
110-
MetricServiceSettings.newBuilder()
111-
.setCredentialsProvider(
112-
FixedCredentialsProvider.create(
113-
checkNotNull(credentials, "Credentials not provided.")));
114-
builder
115-
.createMetricDescriptorSettings()
116-
.setSimpleTimeoutNoRetries(org.threeten.bp.Duration.ofMillis(deadline.toMillis()));
117-
return new MetricExporter(
118-
projectId,
119-
new CloudMetricClientImpl(MetricServiceClient.create(builder.build())),
120-
descriptorStrategy);
115+
return new GoogleCloudMetricExporter(projectId, metricServiceClient, descriptorStrategy);
121116
}
122117

123118
private void exportDescriptor(MetricDescriptor descriptor) {

0 commit comments

Comments
 (0)