Skip to content

Commit

Permalink
fix: Resolve Prometheus target parsing issue with unique node group keys
Browse files Browse the repository at this point in the history
  • Loading branch information
pcfreak30 committed Dec 27, 2024
1 parent 7fa925a commit 86fe3d1
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions cmd/promster/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,34 +186,29 @@ func getScrapeTargets(registry *etcdregistry.EtcdRegistry, etcdPath string) []Se
authKey = username + ":" + password
}

// Create group key
groupKey := serviceName + "|" + authKey

group, exists := groupMap[groupKey]
if !exists {
group = &ServiceGroup{
Name: serviceName,
Targets: make([]string, 0),
MetricsPath: metricsPath,
NodeID: node.Name,
}
// Create unique group key including node name
groupKey := fmt.Sprintf("%s|%s|%s", serviceName, node.Name, authKey)

group := &ServiceGroup{
Name: serviceName,
Targets: []string{address},
MetricsPath: metricsPath,
NodeID: node.Name,
}

// Only set auth if credentials exist
if authKey != "" {
username := node.Info["username"]
if username == "" {
username = "prometheus"
}
group.BasicAuth = &BasicAuth{
Username: username,
Password: node.Info["password"],
}
// Only set auth if credentials exist
if authKey != "" {
username := node.Info["username"]
if username == "" {
username = "prometheus"
}
group.BasicAuth = &BasicAuth{
Username: username,
Password: node.Info["password"],
}

groupMap[groupKey] = group
}

group.Targets = append(group.Targets, address)
groupMap[groupKey] = group
}
}

Expand Down

0 comments on commit 86fe3d1

Please sign in to comment.