Skip to content

feat: Add metric aggregation configuration for hydrating system_labels #443

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adityastic
Copy link

@adityastic adityastic commented Jun 19, 2025

This PR takes over #416

This commit addresses the need to access GCP Monitoring's system_labels metadata
(like machine_type) which are not returned by default through the APIs. By adding
support for metric aggregation configuration, users can now explicitly instruct
the API to include system labels in the response.

Related issues which could use this feature:

Changes:

  • System Labels Access: GCP Monitoring's system_labels metadata (e.g., machine_type)
    are not returned by default through the APIs
  • Metrics Enhancement: Enables better visibility with system labels

New Features:

  • Metric Aggregation Configuration: Add support for specifying custom aggregation
    options per metric prefix using --monitoring.metrics-with-aggregations flag
  • System Labels Integration: Automatically include system labels from Stackdriver
    metadata in exported metrics
  • Enhanced Configuration Format: Support for alignment period, cross-series
    reducer, group-by fields, and per-series aligner configuration

Technical Implementation:

  • Add MetricAggregationConfig struct to handle aggregation configuration
  • Implement aggregation logic in monitoring collector with proper API integration
  • Add JSON unmarshaling for system labels from Stackdriver metadata
  • Extend command-line interface with new aggregation configuration flag

Configuration Format:

The new aggregation configuration uses the format:
metric_name:alignment_period:cross_series_reducer:group_by_fields:per_series_aligner

Example for machine_type access:
compute.googleapis.com/reservation/used:60s:REDUCE_SUM:resource.label."resource_container",resource.label."location",resource.label."reservation_id",metadata.system_labels."machine_type",metric.label."reserved_resource_type":ALIGN_MEAN

Use Case Example:

To expose machine_type dimension for reservation metrics:

--monitoring.metrics-with-aggregations="compute.googleapis.com/reservation/used:60s:REDUCE_SUM:resource.label.\"resource_container\",resource.label.\"location\",resource.label.\"reservation_id\",metadata.system_labels.\"machine_type\",metric.label.\"reserved_resource_type\":ALIGN_MEAN"

Documentation:

  • Update README.md with new configuration option and usage examples

@adityastic
Copy link
Author

@SuperQ mind giving it a review! Thanks!

@terryyanko
Copy link

@adityastic Thank you for this! Would it be possible to grab the user defined labels as part of this PR as well? 🙏 https://cloud.google.com/monitoring/api/ref_v3/rest/v3/TimeSeries#MonitoredResourceMetadata

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