Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(prometheus-sd) namespace source names for v1 API #1896

Merged
merged 2 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app/kuma-prometheus-sd/pkg/discovery/xds/v1/converter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v1

import (
"fmt"

"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/discovery/targetgroup"
"github.com/prometheus/prometheus/util/strutil"
Expand Down Expand Up @@ -79,7 +81,7 @@ func (c Converter) Convert(assignment *observability_v1.MonitoringAssignment) []

var groups []*targetgroup.Group

for _, target := range assignment.Targets {
for i, target := range assignment.Targets {
targetLabels := convertLabels(target.Labels).Merge(commonLabels)

targetLabels[dataplaneLabel] = model.LabelValue(target.Name)
Expand All @@ -89,7 +91,7 @@ func (c Converter) Convert(assignment *observability_v1.MonitoringAssignment) []
targetLabels[model.JobLabel] = model.LabelValue(assignment.Service)

group := &targetgroup.Group{
Source: "kuma",
Source: sourceName(assignment, target, i),
Targets: []model.LabelSet{{
model.AddressLabel: model.LabelValue(target.Address),
}},
Expand All @@ -109,3 +111,8 @@ func convertLabels(labels map[string]string) model.LabelSet {
}
return labelSet
}

func sourceName(assignment *observability_v1.MonitoringAssignment, target *observability_v1.MonitoringAssignment_Target, i int) string {
// unique name, e.g. REST API uri
return fmt.Sprintf("/meshes/%s/targets/%s/%d", assignment.GetMesh(), target.GetName(), i)
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var _ = Describe("Converter", func() {
}},
},
expected: []*targetgroup.Group{{
Source: "kuma",
Source: "/meshes/demo/targets/backend-01/0",
Targets: []model.LabelSet{
{
"__address__": "192.168.0.1:1234",
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/app/kuma-prometheus-sd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func DefaultConfig() Config {
Client: MonitoringAssignmentClientConfig{
Name: "kuma_sd",
URL: "grpc://localhost:5676",
ApiVersion: mads.API_V1_ALPHA1,
ApiVersion: mads.API_V1,
},
},
Prometheus: PrometheusConfig{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ monitoringAssignment:
client:
name: kuma_sd
url: grpc://localhost:5676
apiVersion: v1alpha1
apiVersion: v1
prometheus:
outputFile: kuma.file_sd.json