Skip to content

Commit

Permalink
fix(prometheus-sd) namespace source names for v1 API (#1896)
Browse files Browse the repository at this point in the history
* fix(prometheus-sd) namespace source names for v1 API

Signed-off-by: austin ce <austin.cawley@gmail.com>

* feat(kuma-prometheus-sd) make v1 default

Signed-off-by: austin ce <austin.cawley@gmail.com>
  • Loading branch information
austince authored Apr 29, 2021
1 parent 5cc59d9 commit 095557e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
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

0 comments on commit 095557e

Please sign in to comment.