File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1414package collectors
1515
1616import (
17+ "encoding/json"
1718 "errors"
1819 "fmt"
1920 "log/slog"
@@ -451,6 +452,34 @@ func (c *MonitoringCollector) reportTimeSeriesMetrics(
451452 labelValues = append (labelValues , value )
452453 }
453454 }
455+
456+ // Add system metadata labels
457+ // @see https://cloud.google.com/monitoring/api/ref_v3/rest/v3/TimeSeries
458+ if timeSeries .Metadata .SystemLabels != nil {
459+ // Marshal the SystemLabels struct to JSON
460+ jsonBytes , err := json .Marshal (timeSeries .Metadata .SystemLabels )
461+ if err != nil {
462+ c .logger .Error ("error marshaling SystemLabels to JSON" , "err" , err )
463+ continue
464+ }
465+
466+ // Unmarshal the JSON into a map[string]interface{}
467+ var systemLabelsMap map [string ]interface {}
468+ err = json .Unmarshal (jsonBytes , & systemLabelsMap )
469+ if err != nil {
470+ c .logger .Error ("error unmarshaling JSON to map" , "err" , err )
471+ continue
472+ }
473+
474+ for key , value := range systemLabelsMap {
475+ valueStr := fmt .Sprintf ("%v" , value )
476+ if ! c .keyExists (labelKeys , key ) {
477+ labelKeys = append (labelKeys , key )
478+ labelValues = append (labelValues , valueStr )
479+ }
480+ }
481+ }
482+
454483
455484 if c .monitoringDropDelegatedProjects {
456485 dropDelegatedProject := false
You can’t perform that action at this time.
0 commit comments