Skip to content

Commit

Permalink
fix possible issues
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Blaschke <mblaschke82@gmail.com>
  • Loading branch information
mblaschke committed Jun 19, 2024
1 parent 5d89809 commit 0aab23d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions loganalytics/prober.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(
Expand Down Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit 0aab23d

Please sign in to comment.