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 support for custom MR mapping #854

Merged
merged 3 commits into from
Jun 4, 2024

Conversation

psx95
Copy link
Contributor

@psx95 psx95 commented Jun 3, 2024

Description

Provides a configuration option for the metrics exporter allowing users to specify mappings for custom MonitoredResource type.

The mapping logic for the custom MR type is activated based on the presence of gcp.resource_type resource attribute in the underlying OpenTelemetry resource.

Sample usage with the proposed config changes

exporterOpts := []Option {
                WithProjectID(projectID),
		WithMonitoringClientOptions(clientOpts...),
		WithMetricDescriptorTypeFormatter(formatter),
		WithMonitoredResourceDescription("custom_mr", []string{"service_instance_id", "host_id", "location"}),
}

exporter, err := New(opts...)
... 
// If the OTel resource now has the Attribute label `gcp.resource_type` with value 
// `custom_mr` the exporter will attempt to map the OTel resource to the set MR type.

Testing

  • Tested this newly added configuration with the existing metrics example.
  • Used the configuration to override MR type to dataflow-job.
  • The program returned valid error when all required labels were not present in the resource attributes.
  • When all required labels were present, metric was successfully written against the correct MR type.

Configuration code for reference

// create the exporter with the Monitored Resource Description
exporter, err := mexporter.New(mexporter.WithProjectID(os.Getenv("GOOGLE_PROJECT_ID")), mexporter.WithMonitoredResourceDescription("dataflow_job", []string{"job_name", "project_id", "region"}))
	if err != nil {
		log.Fatalf("Failed to create exporter: %v", err)
	}

...

// Make sure the OTel resource has the `gcp.resoure_type` along with the required labels configured.
 res, err := resource.New(
		ctx,
		// Use the GCP resource detector to detect information about the GCP platform
		resource.WithDetectors(gcp.NewDetector()),
		// Keep the default detectors
		resource.WithTelemetrySDK(),
		// Add attributes from environment variables
		resource.WithFromEnv(),
		// Add your own custom attributes to identify your application
		resource.WithAttributes(
			semconv.ServiceNameKey.String("example-application"),
			attribute.KeyValue{Key: "gcp.resource_type", Value: attribute.StringValue("dataflow_job")},
			attribute.KeyValue{Key: "job_name", Value: attribute.StringValue("some-job")},
			attribute.KeyValue{Key: "region", Value: attribute.StringValue("us1")},
		),
	)

// Construct the exporter using the above config
provider := sdkmetric.NewMeterProvider(
		sdkmetric.WithReader(sdkmetric.NewPeriodicReader(exporter)),
		sdkmetric.WithResource(res),
	)

Copy link

codecov bot commented Jun 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.92%. Comparing base (4caace7) to head (0f9bfad).
Report is 20 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #854      +/-   ##
==========================================
+ Coverage   61.03%   62.92%   +1.88%     
==========================================
  Files          56       57       +1     
  Lines        5903     4955     -948     
==========================================
- Hits         3603     3118     -485     
+ Misses       2143     1677     -466     
- Partials      157      160       +3     

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

@psx95 psx95 marked this pull request as ready for review June 3, 2024 22:44
@psx95 psx95 requested a review from a team as a code owner June 3, 2024 22:44
@psx95 psx95 requested a review from dashpole June 3, 2024 22:45
@psx95 psx95 force-pushed the support-custom-mr branch 3 times, most recently from 55728dc to 88878e9 Compare June 4, 2024 15:04
@psx95 psx95 merged commit 2007b6e into GoogleCloudPlatform:main Jun 4, 2024
28 checks passed
@psx95 psx95 deleted the support-custom-mr branch June 4, 2024 16:00
codeboten referenced this pull request in open-telemetry/opentelemetry-collector-contrib Jun 19, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-go)
| `v1.23.0` -> `v1.24.0` |
[![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fGoogleCloudPlatform%2fopentelemetry-operations-go%2fdetectors%2fgcp/v1.24.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2fGoogleCloudPlatform%2fopentelemetry-operations-go%2fdetectors%2fgcp/v1.24.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2fGoogleCloudPlatform%2fopentelemetry-operations-go%2fdetectors%2fgcp/v1.23.0/v1.24.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fGoogleCloudPlatform%2fopentelemetry-operations-go%2fdetectors%2fgcp/v1.23.0/v1.24.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
|
[github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-go)
| `v0.47.0` -> `v0.48.0` |
[![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fGoogleCloudPlatform%2fopentelemetry-operations-go%2fexporter%2fcollector/v0.48.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2fGoogleCloudPlatform%2fopentelemetry-operations-go%2fexporter%2fcollector/v0.48.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2fGoogleCloudPlatform%2fopentelemetry-operations-go%2fexporter%2fcollector/v0.47.0/v0.48.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fGoogleCloudPlatform%2fopentelemetry-operations-go%2fexporter%2fcollector/v0.47.0/v0.48.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
|
[github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector/googlemanagedprometheus](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-go)
| `v0.47.0` -> `v0.48.0` |
[![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fGoogleCloudPlatform%2fopentelemetry-operations-go%2fexporter%2fcollector%2fgooglemanagedprometheus/v0.48.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/go/github.com%2fGoogleCloudPlatform%2fopentelemetry-operations-go%2fexporter%2fcollector%2fgooglemanagedprometheus/v0.48.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/go/github.com%2fGoogleCloudPlatform%2fopentelemetry-operations-go%2fexporter%2fcollector%2fgooglemanagedprometheus/v0.47.0/v0.48.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fGoogleCloudPlatform%2fopentelemetry-operations-go%2fexporter%2fcollector%2fgooglemanagedprometheus/v0.47.0/v0.48.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>GoogleCloudPlatform/opentelemetry-operations-go
(github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/collector)</summary>

###
[`v0.48.0`](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-go/releases/tag/v0.48.0):
v1.24.0 and v0.48.0

[Compare
Source](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-go/compare/v0.47.0...v0.48.0)

##### What's Changed

- Updating packages by
[@&#8203;avilevy18](https://togithub.com/avilevy18) in
[https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/846](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/846)
- Bump go to v1.22.3 in ci by
[@&#8203;dashpole](https://togithub.com/dashpole) in
[https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/849](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/849)
- Run e2e tests on GAE standard by
[@&#8203;aabmass](https://togithub.com/aabmass) in
[https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/848](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/848)
- Add host.id as a fallback for instance by
[@&#8203;dashpole](https://togithub.com/dashpole) in
[https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/852](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/852)
- feat(extension/googleclientauth): support id-token by
[@&#8203;rinx](https://togithub.com/rinx) in
[https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/851](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/851)
- Add support for exponential histograms in the GMP exporter by
[@&#8203;dashpole](https://togithub.com/dashpole) in
[https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/853](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/853)
- Add support for custom MR mapping by
[@&#8203;psx95](https://togithub.com/psx95) in
[https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/854](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/854)
- Update CI go version to 1.22.4 by
[@&#8203;psx95](https://togithub.com/psx95) in
[https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/859](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/859)
- prepare for v1.24.0/v0.48.0
([#&#8203;858](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-go/issues/858))
by [@&#8203;psx95](https://togithub.com/psx95) in
[https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/860](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/860)

##### New Contributors

- [@&#8203;rinx](https://togithub.com/rinx) made their first
contribution in
[https://github.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/851](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-go/pull/851)

**Full Changelog**:
GoogleCloudPlatform/opentelemetry-operations-go@v0.47.0...v0.48.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "on tuesday" (UTC), Automerge - At any
time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config help](https://togithub.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/open-telemetry/opentelemetry-collector-contrib).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MTAuMSIsInVwZGF0ZWRJblZlciI6IjM3LjQxMC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZWJvdCJdfQ==-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: opentelemetrybot <[email protected]>
Co-authored-by: Alex Boten <[email protected]>
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.

2 participants