stackdriver_exporter icon indicating copy to clipboard operation
stackdriver_exporter copied to clipboard

feat: Add metric aggregation configuration for hydrating system_labels

Open adityastic opened this issue 5 months ago • 0 comments

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:

  • #78
  • #115

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 avatar Jun 19 '25 08:06 adityastic