Skip to content

Commit

Permalink
Fix getPrometheusExporterPorts incorrectly matching to prometheusremo…
Browse files Browse the repository at this point in the history
…tewrite exporter (#2016) (#2017)

* Fix getPrometheusExporterPorts incorrectly matching to prometheusremotewrite exporter

* add unit test for collector prometheus rw exporter

* standardized code format
  • Loading branch information
hzhhong authored Aug 17, 2023
1 parent 2788853 commit 0492819
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/manifests/collector/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ func getPrometheusExporterPorts(c map[interface{}]interface{}) ([]corev1.Contain
if exporters, ok := c["exporters"]; ok && exporters != nil {
for e, exporterConfig := range exporters.(map[interface{}]interface{}) {
exporterName := e.(string)
if strings.Contains(exporterName, "prometheus") {
// Note that receivers, processors, exporters and/or pipelines are defined via component identifiers in type[/name] format (e.g. otlp or otlp/2). Components of a given type can be defined more than once as long as the identifiers are unique.
if strings.Split(exporterName, "/")[0] == "prometheus" {
containerPort, err := getPrometheusExporterPort(exporterConfig.(map[interface{}]interface{}))
if err != nil {
errors = append(errors,
Expand Down
32 changes: 32 additions & 0 deletions internal/manifests/collector/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,38 @@ service:
},
},
},
{
description: "prometheus RW exporter",
specConfig: `exporters:
prometheusremotewrite/prometheus:
endpoint: http://prometheus-server.monitoring/api/v1/write`,
specPorts: []corev1.ServicePort{},
expectedPorts: []corev1.ContainerPort{metricContainerPort},
},
{
description: "multiple prometheus exporters and prometheus RW exporter",
specConfig: `exporters:
prometheus/prod:
endpoint: "0.0.0.0:9090"
prometheus/dev:
endpoint: "0.0.0.0:9091"
prometheusremotewrite/prometheus:
endpoint: http://prometheus-server.monitoring/api/v1/write`,
specPorts: []corev1.ServicePort{},
expectedPorts: []corev1.ContainerPort{
metricContainerPort,
{
Name: "prometheus-prod",
ContainerPort: 9090,
Protocol: corev1.ProtocolTCP,
},
{
Name: "prometheus-dev",
ContainerPort: 9091,
Protocol: corev1.ProtocolTCP,
},
},
},
}

for _, testCase := range tests {
Expand Down

0 comments on commit 0492819

Please sign in to comment.