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

feat(metrics): add annotation to have custom address #6289

Merged
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
15 changes: 11 additions & 4 deletions pkg/plugins/runtime/k8s/controllers/pod_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,20 +261,27 @@ func MetricsAggregateFor(pod *kube_core.Pod) ([]*mesh_proto.PrometheusAggregateM
enabled = true
}
path, _ := metadata.Annotations(pod.Annotations).GetStringWithDefault("/metrics", fmt.Sprintf(metadata.KumaMetricsPrometheusAggregatePath, app))
port, exist, err := metadata.Annotations(pod.Annotations).GetUint32(fmt.Sprintf(metadata.KumaMetricsPrometheusAggregatePort, app))

address, addressExists := metadata.Annotations(pod.Annotations).GetString(fmt.Sprintf(metadata.KumaMetricsPrometheusAggregateAddress, app))

port, portExist, err := metadata.Annotations(pod.Annotations).GetUint32(fmt.Sprintf(metadata.KumaMetricsPrometheusAggregatePort, app))
if err != nil {
return nil, err
}
if !exist && enabled {
if !portExist && enabled {
return nil, errors.New("port needs to be specified for metrics scraping")
}

aggregateConfig = append(aggregateConfig, &mesh_proto.PrometheusAggregateMetricsConfig{
config := &mesh_proto.PrometheusAggregateMetricsConfig{
Name: app,
Path: path,
Port: port,
Enabled: util_proto.Bool(enabled),
})
}
if addressExists {
config.Address = address
}
aggregateConfig = append(aggregateConfig, config)
}
return aggregateConfig, nil
}
2 changes: 2 additions & 0 deletions pkg/plugins/runtime/k8s/controllers/pod_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ var _ = Describe("MetricsAggregateFor(..)", func() {
annotations: map[string]string{
"prometheus.metrics.kuma.io/aggregate-my-app-path": "/stats",
"prometheus.metrics.kuma.io/aggregate-my-app-port": "123",
"prometheus.metrics.kuma.io/aggregate-my-app-address": "localhost",
"prometheus.metrics.kuma.io/aggregate-my-app-enabled": "false",
},
expected: []*mesh_proto.PrometheusAggregateMetricsConfig{
Expand All @@ -701,6 +702,7 @@ var _ = Describe("MetricsAggregateFor(..)", func() {
Path: "/stats",
Port: 123,
Enabled: util_proto.Bool(false),
Address: "localhost",
},
},
}),
Expand Down
2 changes: 2 additions & 0 deletions pkg/plugins/runtime/k8s/metadata/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ const (

// KumaMetricsPrometheusAggregatePath allows to specify which path for specific app should request for metrics
KumaMetricsPrometheusAggregatePath = "prometheus.metrics.kuma.io/aggregate-%s-path"
// KumaMetricsPrometheusAggregateAddress allows to specify which address for specific app should request for metrics
KumaMetricsPrometheusAggregateAddress = "prometheus.metrics.kuma.io/aggregate-%s-address"
// KumaMetricsPrometheusAggregatePort allows to specify which port for specific app should request for metrics
KumaMetricsPrometheusAggregatePort = "prometheus.metrics.kuma.io/aggregate-%s-port"
// KumaMetricsPrometheusAggregateEnabled allows to specify if we want to enable specific scraping, default: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ func ApplicationsMetrics() {
testserver.WithNamespace(namespace),
testserver.WithMesh(meshNoAggregate),
testserver.WithName("test-server-dp-metrics"),
testserver.WithoutProbes(), // when application binds to localhost you cannot access it
testserver.WithEchoArgs("--ip", "localhost"),
testserver.WithPodAnnotations(map[string]string{
"prometheus.metrics.kuma.io/aggregate-app-path": "/my-app",
"prometheus.metrics.kuma.io/aggregate-app-port": "80",
"prometheus.metrics.kuma.io/aggregate-app-address": "localhost",
"prometheus.metrics.kuma.io/aggregate-other-app-path": "/other-app",
"prometheus.metrics.kuma.io/aggregate-other-app-port": "80",
}))).
Expand Down Expand Up @@ -222,8 +225,8 @@ func ApplicationsMetrics() {

// overridden by pod
Expect(stdout).To(ContainSubstring("my-app"))
// overridden by pod
Expect(stdout).To(ContainSubstring("other-app"))
// overridden by pod but binding to localhost so it's not available
Expect(stdout).ToNot(ContainSubstring("other-app"))
// metric from envoy
Expect(stdout).To(ContainSubstring("envoy_server_concurrency"))
})
Expand Down