-
Notifications
You must be signed in to change notification settings - Fork 39
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
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
27f155c
Add metrics exporter
zoercai e799662
Add metrics exporter
zoercai edc832b
Add gcp monitored resource mapping
zoercai 2d8c461
Add gcp monitored resource mapping
zoercai 95c1a81
Add gcp monitored resource mapping
zoercai 16328e6
Refactor
zoercai 4b1126f
Fix MetricConfiguration AutoValue
zoercai 2a78e0c
Refactor & fix
zoercai 3c931d0
Add deadline and fix logging
zoercai 1b64ec0
Review changes
zoercai 711ed05
Correct loggers
zoercai bbb7273
More review changes
zoercai b43572c
Review changes: remove unique identifiers and GCP resource mapping
zoercai 2f99cb7
Still need resource
zoercai b22af4f
Review changes
zoercai fa190d0
Review changes
zoercai ba54f38
Review changes
zoercai 857f362
Review changes
zoercai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
98 changes: 98 additions & 0 deletions
98
...ters/metrics/src/main/java/com.google.cloud.opentelemetry.metric/MetricConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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.