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

Add metrics exporter #33

Merged
merged 18 commits into from
Sep 10, 2020
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ subprojects {
ext {
autoValueVersion = '1.7.4'
googleCloudVersion = '1.0.2'
cloudMonitoringVersion = '2.0.1'
openTelemetryVersion = '0.7.0'
junitVersion = '4.13'
opentelemetryOperationsVersion = "0.7.1" // CURRENT_RELEASE_VERSION
Expand All @@ -29,6 +30,7 @@ subprojects {
google_cloud_core : "com.google.cloud:google-cloud-core:${googleCloudVersion}",
google_cloud_grpc : "com.google.api.grpc:grpc-google-cloud-trace-v2:${googleCloudVersion}",
google_cloud_trace : "com.google.cloud:google-cloud-trace:${googleCloudVersion}",
google_cloud_monitoring : "com.google.cloud:google-cloud-monitoring:${cloudMonitoringVersion}",
Copy link
Contributor

Choose a reason for hiding this comment

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

We are using {googleCloudVersion} for both core and trace dependencies above, but not for Cloud Monitoring client? Might be worth checking if we should also use separate versioning for core and tracing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I used a separate version for cloud monitoring because the 1.0.2 version didn't have much and didn't work. I've added a separate cloudTracingVersion for tracing, kept it to 1.0.2 for this PR though.

opentelemetry_api : "io.opentelemetry:opentelemetry-api:${openTelemetryVersion}",
opentelemetry_sdk : "io.opentelemetry:opentelemetry-sdk:${openTelemetryVersion}",
opentelemetry_operations_java: "com.google.cloud.opentelemetry:exporter-trace:${opentelemetryOperationsVersion}"
Expand Down
Empty file added exporters/metrics/README.md
Empty file.
12 changes: 12 additions & 0 deletions exporters/metrics/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
description = 'Cloud Monitoring Exporter for OpenTelemetry'

dependencies {
api(libraries.auto_value_annotations)
annotationProcessor(libraries.auto_value)
api(libraries.opentelemetry_api)
api(libraries.opentelemetry_sdk)
api(libraries.google_cloud_core)
api(libraries.google_cloud_monitoring)
api(libraries.google_cloud_grpc)
zoercai marked this conversation as resolved.
Show resolved Hide resolved
testImplementation(testLibraries.junit)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.google.cloud.opentelemetry.metric;

import com.google.auth.Credentials;
import com.google.auto.value.AutoValue;
import com.google.cloud.ServiceOptions;
import com.google.cloud.monitoring.v3.MetricServiceClient;
import com.google.cloud.monitoring.v3.stub.MetricServiceStub;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

/** Configurations for {@link MetricExporter}. */
@AutoValue
@Immutable
public abstract class MetricConfiguration {

private static final String DEFAULT_PROJECT_ID =
Strings.nullToEmpty(ServiceOptions.getDefaultProjectId());
private static final boolean DEFAULT_ADD_UNIQUE_IDENTIFIER = false;

MetricConfiguration() {}

/**
* Returns the {@link Credentials}.
*
* @return the {@code Credentials}.
*/
@Nullable
public abstract Credentials getCredentials();

/**
* Returns the cloud project id.
*
* @return the cloud project id.
*/
public abstract String getProjectId();

/**
* Returns the client.
*
* @return the client.
*/
public abstract MetricServiceClient getClient();

/**
* Returns whether a unique identifier will be added.
*
* @return whether a unique identifier will be added.
*/
public abstract boolean getAddUniqueIdentifier();

/**
* Returns a MetricsServiceStub instance used to make RPC calls.
*
* @return the metrics service stub.
*/
@Nullable
public abstract MetricServiceStub getMetricServiceStub();

public static Builder builder() {
return new AutoValue_MetricConfiguration.Builder();
zoercai marked this conversation as resolved.
Show resolved Hide resolved
}

/** Builder for {@link MetricConfiguration}. */
@AutoValue.Builder
public abstract static class Builder {

Builder() {}
zoercai marked this conversation as resolved.
Show resolved Hide resolved

abstract String getProjectId();

abstract MetricServiceClient getClient();

abstract boolean getAddUniqueIdentifier();

abstract MetricConfiguration autoBuild();

public abstract Builder setProjectId(String newProjectId);

public abstract Builder setClient(MetricServiceClient newClient);

/**
* Builds a {@link MetricConfiguration}.
*
* @return a {@code MetricsConfiguration}.
*/
public MetricConfiguration build() {
Preconditions.checkArgument(
!Strings.isNullOrEmpty(getProjectId()),
"Cannot find a project ID from either configurations or application default.");

return autoBuild();
}
}

}
Loading