@@ -73,19 +73,6 @@ func (tagmgr *ArmClientTagManager) GetResourceTag(ctx context.Context, resourceI
73
73
74
74
ret := make ([]ResourceTagResult , len (config .Tags ))
75
75
76
- // prefill tag config, this should not be empty in case of error
77
- i := - 1
78
- for _ , tagConfig := range config .Tags {
79
- i ++
80
-
81
- // default
82
- ret [i ] = ResourceTagResult {
83
- TagName : tagConfig .Name ,
84
- TagValue : "" ,
85
- TargetName : tagConfig .TargetName ,
86
- }
87
- }
88
-
89
76
// parse resource id
90
77
resourceID = strings .ToLower (resourceID )
91
78
resourceInfo , err := ParseResourceId (resourceID )
@@ -163,7 +150,7 @@ func (tagmgr *ArmClientTagManager) GetResourceTag(ctx context.Context, resourceI
163
150
return tagValue , nil
164
151
}
165
152
166
- i = - 1
153
+ i : = - 1
167
154
for _ , tagConfig := range config .Tags {
168
155
i ++
169
156
@@ -393,13 +380,21 @@ func (c *ResourceTagManager) AddToPrometheusLabels(labels []string) []string {
393
380
394
381
// AddResourceTagsToPrometheusLabels adds resource tags to prometheus labels
395
382
func (c * ResourceTagManager ) AddResourceTagsToPrometheusLabels (ctx context.Context , labels prometheus.Labels , resourceID string ) prometheus.Labels {
396
- resourceTags , err := c . client . TagManager . GetResourceTag ( ctx , resourceID , c )
397
- if err != nil {
398
- c . client . TagManager . logger . Warnf ( `unable to fetch resource tags for resource "%s": %v` , resourceID , err . Error ())
383
+ // init label value, do not miss a label or we run into problems later
384
+ for _ , tag := range c . Tags {
385
+ labels [ tag . TargetName ] = ""
399
386
}
400
387
401
- for _ , tag := range resourceTags {
402
- labels [tag .TargetName ] = tag .TagValue
388
+ // only run processing if we have a resourceID
389
+ if resourceID != "" {
390
+ resourceTags , err := c .client .TagManager .GetResourceTag (ctx , resourceID , c )
391
+ if err != nil {
392
+ c .client .TagManager .logger .Warnf (`unable to fetch resource tags for resource "%s": %v` , resourceID , err .Error ())
393
+ }
394
+
395
+ for _ , tag := range resourceTags {
396
+ labels [tag .TargetName ] = tag .TagValue
397
+ }
403
398
}
404
399
405
400
return labels
0 commit comments