Skip to content

Conversation

@psx95
Copy link
Contributor

@psx95 psx95 commented May 19, 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.

Some methods were marked with @Deprecated but no breaking changes were made in this PR.

Sample usage with the proposed changes

 // MetricConfiguration object for the metrics exporter -  MetricConfiguration configuration = MetricConfiguration.builder() .setProjectId(PROJECT_ID) .setCredentials(CREDENTIALS) .setResourceAttributesFilter(allowAllPredicate) .setMonitoredResourceDescription( new MonitoredResourceDescription( "custom_mr", Set.of("instance_id", "api", "host_id"))) .setUseServiceTimeSeries(true) .build(); // 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
// MeterProvider and OTel Resource setup MonitoredResourceDescription monitoredResourceDescription = new MonitoredResourceDescription( "dataflow_job", Set.of("job_name", "project_id", "region")); MetricExporter metricExporter = GoogleCloudMetricExporter.createWithConfiguration( MetricConfiguration.builder() .setMonitoredResourceDescription(monitoredResourceDescription) .build()); // project_id inferred from env variables Attributes attrs = Attributes.builder() .put("gcp.resource_type", "dataflow_job") // required to trigger platform mapping .put("network_id", "random-id") // was ignored .put("job_name", "some-job") .put("region", "us1") .build(); METER_PROVIDER = SdkMeterProvider.builder() .setResource(Resource.create(attrs)) .registerMetricReader( PeriodicMetricReader.builder(metricExporter) .setInterval(java.time.Duration.ofSeconds(30)) .build()) .build(); ... // Standard OpenTelemetry code to record metric
@psx95 psx95 force-pushed the custom-mr-mapping-3 branch from ec40375 to df2dbd5 Compare May 19, 2024 20:47
@psx95 psx95 force-pushed the custom-mr-mapping-3 branch from 8878ae5 to 919de1b Compare May 21, 2024 15:29
@psx95 psx95 self-assigned this May 21, 2024
@psx95 psx95 marked this pull request as ready for review May 21, 2024 16:28
@psx95 psx95 requested a review from a team as a code owner May 21, 2024 16:28
@psx95 psx95 requested review from dashpole and jsuereth May 21, 2024 16:29
Copy link
Contributor

@dashpole dashpole left a comment

Choose a reason for hiding this comment

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

lgtm after comment is addressed

@psx95 psx95 requested a review from dashpole May 22, 2024 19:19
@psx95 psx95 merged commit b0caafd into GoogleCloudPlatform:main May 23, 2024
@psx95 psx95 deleted the custom-mr-mapping-3 branch May 23, 2024 15:07
diegomarquezp referenced this pull request in googleapis/sdk-platform-java May 31, 2024
…rces-support to v0.29.0 (#2831) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [com.google.cloud.opentelemetry:detector-resources-support](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java) | `0.28.0` -> `0.29.0` | [![age](https://developer.mend.io/api/mc/badges/age/maven/com.google.cloud.opentelemetry:detector-resources-support/0.29.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/com.google.cloud.opentelemetry:detector-resources-support/0.29.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/com.google.cloud.opentelemetry:detector-resources-support/0.28.0/0.29.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/com.google.cloud.opentelemetry:detector-resources-support/0.28.0/0.29.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-java (com.google.cloud.opentelemetry:detector-resources-support)</summary> ### [`v0.29.0`](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/releases/tag/v0.29.0) [Compare Source](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/compare/v0.28.0...v0.29.0) #### Release Highlights - Non-GKE resource now map to `k8s_*` monitored resource ([#&#8203;340](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/issues/340) , [#&#8203;342](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/issues/342)) - Support for mapping to custom Monitored Resources ([#&#8203;346](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/issues/346)) - Newly deprecated APIs: [mapResource](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/blob/b0caafdaceb2b7418d256cecc05fa8fce9bafecc/exporters/metrics/src/main/java/com/google/cloud/opentelemetry/metric/ResourceTranslator.java#L36) #### What's Changed - Update maven-badges to link to sonatype central by [@&#8203;psx95](https://togithub.com/psx95) in [https://github.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/322](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/322) - Add auth support for gRPC by [@&#8203;psx95](https://togithub.com/psx95) in [https://github.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/323](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/323) - Switch to ConcurrentMap for thread-safety by [@&#8203;psx95](https://togithub.com/psx95) in [https://github.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/328](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/328) - Add otlp with spring boot sample by [@&#8203;psx95](https://togithub.com/psx95) in [https://github.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/327](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/327) - Change OTel quickstart to use log4j2 instead of logback by [@&#8203;aabmass](https://togithub.com/aabmass) in [https://github.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/330](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/330) - Always output logging.googleapis.com/trace_sampled as true by [@&#8203;aabmass](https://togithub.com/aabmass) in [https://github.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/332](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/332) - Update JVM flag otel.java.experimental.extension by [@&#8203;psx95](https://togithub.com/psx95) in [https://github.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/338](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/338) - Add test case for zone resource detection on GAE standard by [@&#8203;aabmass](https://togithub.com/aabmass) in [https://github.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/341](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/341) - Fix [#&#8203;258](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/issues/258) enable mapping when not gcp kubernetes by [@&#8203;tkmsaaaam](https://togithub.com/tkmsaaaam) in [https://github.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/340](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/340) - Fix [#&#8203;340](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/issues/340) bug by [@&#8203;tkmsaaaam](https://togithub.com/tkmsaaaam) in [https://github.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/342](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/342) - Make all AttributeMappings final by [@&#8203;psx95](https://togithub.com/psx95) in [https://github.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/347](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/347) - Add support for custom MR mappings by [@&#8203;psx95](https://togithub.com/psx95) in [https://github.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/346](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/346) #### New Contributors - [@&#8203;tkmsaaaam](https://togithub.com/tkmsaaaam) made their first contribution in [https://github.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/340](https://togithub.com/GoogleCloudPlatform/opentelemetry-operations-java/pull/340) **Full Changelog**: GoogleCloudPlatform/opentelemetry-operations-java@v0.28.0...v0.29.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), 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. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- 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/googleapis/sdk-platform-java). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zNzcuOCIsInVwZGF0ZWRJblZlciI6IjM3LjM3Ny44IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants