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

feat: WithMonitoredResourceAttributes and WithMonitoredResourceDescription #850

Closed

Conversation

bhshkh
Copy link

@bhshkh bhshkh commented May 8, 2024

Context: googleapis/google-cloud-go#10046

I'm working on exporting Bigtable client metrics to Google Cloud Monitoring.
I have tried using the exporter in its current form:

CBT client side metrics
In step 15 in the above diagram, the monitored resource in CreateServiceTimeSeries request has 2 fields:

  1. Type: OpenTelemetry resource with attributes gets created in step 5. The exporter uses the “cloud.platform” resource attribute value to determine the monitored resource type. Complete logic can be seen here.
    Problem 1: The CBT client side metrics need to be written to ‘bigtable_client_raw’ monitored resource type but the exporter does not allow writing to resource types other than the ones mentioned here
  2. Labels: OpenTelemetry resource with attributes gets created in step 5. The exporter adds these resource attributes as labels to the monitored resource. The ‘bigtable_client_raw’ monitored resource needs to written with labels: project, instance, table, cluster and zone
    Problem 2: Only project and instance values are known at step 5 point in time. Table is not known until data operation such as ReadRows is invoked.
    A Bigtable instance is a container for user's data. Instances have one or more clusters, located in different zones. When library sends requests to a Bigtable instance, those requests are handled by one of the clusters in the instance. The cluster is not known while sending the request. Cluster and zone need to be read from response headers of data operation. Thus, the existing metric exporter cannot add these labels to the monitored resource.

To resolve problem 1, solution similar to GoogleCloudPlatform/opentelemetry-operations-java#346 is being included in this PR.

How to include monitored resource labels?

  1. While recording the metrics, add the required labels to the metrics
  2. Exporter will use the function provided in the WithMonitoredResourceAttributes to extract the resource labels from the metric labels and add them to monitored resource. Example usage:

https://github.com/bhshkh/google-cloud-go/blob/bc1d79ae1a71a774b96ab94b875b8a29c0046501/bigtable/metric_monitoring_exporter.go#L72-L75

Copy link

codecov bot commented May 8, 2024

Codecov Report

Attention: Patch coverage is 37.50000% with 10 lines in your changes are missing coverage. Please review.

Project coverage is 62.52%. Comparing base (4caace7) to head (290e9f8).
Report is 19 commits behind head on main.

Current head 290e9f8 differs from pull request most recent head 116bd2b

Please upload reports for the commit 116bd2b to get more accurate results.

Files Patch % Lines
exporter/metric/option.go 0.00% 6 Missing ⚠️
exporter/metric/metric.go 60.00% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #850      +/-   ##
==========================================
+ Coverage   61.03%   62.52%   +1.48%     
==========================================
  Files          56       57       +1     
  Lines        5903     4931     -972     
==========================================
- Hits         3603     3083     -520     
+ Misses       2143     1688     -455     
- Partials      157      160       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bhshkh bhshkh changed the title feat: Allow filtering resources and creating custom monitored resource feat: Allow filtering metric attributes and creating custom monitored resource May 8, 2024

// metricAttributesFilter determinies which metric attributes to
// add to metrics as metric labels
metricAttributesFilter attribute.Filter
Copy link
Contributor

Choose a reason for hiding this comment

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

You shouldn't need this config in the exporter. Use https://pkg.go.dev/go.opentelemetry.io/otel/sdk/metric#WithView to pass views to the metrics SDK, which allow filtering attributes on metrics.

Copy link
Author

Choose a reason for hiding this comment

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

with views, the metric attributes do not reach the exporter at all. The attributes need to reach the exporter. Then, the exporter can add them to resource

@dashpole
Copy link
Contributor

dashpole commented May 8, 2024

cc @psx95

@psx95
Copy link
Contributor

psx95 commented May 9, 2024

cc @psx95

This looks similar to the recent request we had for the Java exporter, I will take a look into this PR.

@psx95
Copy link
Contributor

psx95 commented May 26, 2024

A similar change to the Java exporter was just approved and merged in GoogleCloudPlatform/opentelemetry-operations-java#346. We would likely want to follow similar logic here.

@bhshkh bhshkh changed the title feat: Allow filtering metric attributes and creating custom monitored resource feat: WithMonitoredResourceAttributes and WithMonitoredResourceDescription May 28, 2024
@psx95
Copy link
Contributor

psx95 commented Jun 4, 2024

Similar functionality has been added in #854.

@dashpole dashpole closed this Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants