@@ -68,30 +68,65 @@ func BuildMetricName(namespace, metricName, statistic string) string {
6868}
6969
7070func BuildNamespaceInfoMetrics (tagData []model.TaggedResourceResult , metrics []* PrometheusMetric , observedMetricLabels map [string ]model.LabelSet , labelsSnakeCase bool , logger * slog.Logger ) ([]* PrometheusMetric , map [string ]model.LabelSet ) {
71+ // Loop through each AWS service result (e.g., discovery results from any service)
7172 for _ , tagResult := range tagData {
73+ // Extract context labels (region, account_id, account_alias, custom_tags) from the scrape context
7274 contextLabels := contextToLabels (tagResult .Context , labelsSnakeCase , logger )
75+
76+ // Loop through each discovered resource (e.g., each table, instance, bucket, etc.)
7377 for _ , d := range tagResult .Data {
78+ // Build the metric name: AWS/ServiceName + "info" + "" → "aws_servicename_info"
7479 metricName := BuildMetricName (d .Namespace , "info" , "" )
7580
76- promLabels := make (map [string ]string , len (d .Tags )+ len (contextLabels )+ 1 )
81+ // Pre-allocate map for all labels: resource tags + context labels + metadata + 1 for "name" label
82+ promLabels := make (map [string ]string , len (d .Tags )+ len (contextLabels )+ len (d .Metadata )+ 1 )
83+
84+ // Copy all context labels (region, account_id, etc.) into the prometheus labels map
7785 maps .Copy (promLabels , contextLabels )
86+
87+ // Add the "name" label containing the full ARN of the resource
88+ // Example: "arn:aws:service:region:account:resource/ResourceName"
7889 promLabels ["name" ] = d .ARN
90+
91+ // Loop through all AWS tags attached to this resource
7992 for _ , tag := range d .Tags {
93+ // Convert AWS tag key to valid Prometheus label name (handles special chars, snake_case)
8094 ok , promTag := PromStringTag (tag .Key , labelsSnakeCase )
8195 if ! ok {
96+ // Skip invalid tag names that can't be converted to Prometheus labels
8297 logger .Warn ("tag name is an invalid prometheus label name" , "tag" , tag .Key )
8398 continue
8499 }
85100
101+ // Create label with "tag_" prefix: "Environment" → "tag_Environment"
86102 labelName := "tag_" + promTag
103+ // Set the label value to the AWS tag value
87104 promLabels [labelName ] = tag .Value
88105 }
89106
107+ // Loop through all metadata attached to this resource (e.g., service-specific attributes)
108+ for metadataKey , metadataValue := range d .Metadata {
109+ // Convert metadata key to valid Prometheus label name (handles special chars, snake_case)
110+ ok , promKey := PromStringTag (metadataKey , labelsSnakeCase )
111+ if ! ok {
112+ // Skip invalid metadata keys that can't be converted to Prometheus labels
113+ logger .Warn ("metadata key is an invalid prometheus label name" , "key" , metadataKey )
114+ continue
115+ }
116+
117+ // Add metadata as labels directly (no prefix needed since they're service-specific)
118+ // Examples: table_class="Standard", instance_type="t3.micro", billing_mode="PAY_PER_REQUEST"
119+ promLabels [promKey ] = metadataValue
120+ }
121+
122+ // Track all label names used by this metric for consistency checking later
90123 observedMetricLabels = recordLabelsForMetric (metricName , promLabels , observedMetricLabels )
124+
125+ // Create the final info metric with all labels and value=0 (info metrics are label carriers)
91126 metrics = append (metrics , & PrometheusMetric {
92- Name : metricName ,
93- Labels : promLabels ,
94- Value : 0 ,
127+ Name : metricName , // e.g., "aws_dynamodb_info", "aws_ec2_info", etc.
128+ Labels : promLabels , // All the labels we built above
129+ Value : 0 , // Info metrics always have value 0
95130 })
96131 }
97132 }
0 commit comments