From 0aab23d4a4bef3f5bf11c4e0fdb9ec7f917ac783 Mon Sep 17 00:00:00 2001 From: Markus Blaschke Date: Wed, 19 Jun 2024 19:44:29 +0200 Subject: [PATCH] fix possible issues Signed-off-by: Markus Blaschke --- loganalytics/prober.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/loganalytics/prober.go b/loganalytics/prober.go index 98616d1..548a0c1 100644 --- a/loganalytics/prober.go +++ b/loganalytics/prober.go @@ -159,6 +159,8 @@ func (p *LogAnalyticsProber) translateWorkspaceIntoConfig(val string) WorkspaceC Labels: map[string]string{}, } + val = strings.TrimSpace(val) + if strings.HasPrefix(val, "/subscriptions/") { workspaceResource, err := p.ServiceDiscovery.GetWorkspace(p.ctx, val) if err != nil { @@ -169,9 +171,9 @@ func (p *LogAnalyticsProber) translateWorkspaceIntoConfig(val string) WorkspaceC workspaceConfig.CustomerID = to.String(workspaceResource.Properties.CustomerID) if resourceInfo, err := armclient.ParseResourceId(workspaceConfig.ResourceID); err == nil { - workspaceConfig.Labels["resourceID"] = workspaceConfig.ResourceID - workspaceConfig.Labels["resourceGroup"] = resourceInfo.ResourceGroup - workspaceConfig.Labels["resourceName"] = resourceInfo.ResourceName + workspaceConfig.Labels["workspaceResourceID"] = workspaceConfig.ResourceID + workspaceConfig.Labels["workspaceResourceGroup"] = resourceInfo.ResourceGroup + workspaceConfig.Labels["workspaceResourceName"] = resourceInfo.ResourceName // add custom labels workspaceConfig.Labels = p.tagManagerConfig.AddResourceTagsToPrometheusLabels( @@ -507,8 +509,10 @@ func (p *LogAnalyticsProber) sendQueryToSingleWorkspace(logger *zap.SugaredLogge metric[num].Labels["workspaceID"] = workspaceConfig.CustomerID // add labels from resource config - for labelName, labelValue := range workspaceConfig.Labels { - metric[num].Labels[labelName] = labelValue + if workspaceConfig.Labels != nil { + for labelName, labelValue := range workspaceConfig.Labels { + metric[num].Labels[labelName] = labelValue + } } }