Skip to content

Commit

Permalink
Add missing label for Service/Pod Monitors
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Sa <[email protected]>

Add missing label for Service/Pod Monitors

Signed-off-by: Yuri Sa <[email protected]>

Add missing label for Service/Pod Monitors

Signed-off-by: Yuri Sa <[email protected]>
  • Loading branch information
yuriolisa committed Jan 29, 2024
1 parent 6ea5f7f commit ea1e00a
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 4 deletions.
16 changes: 16 additions & 0 deletions .chloggen/add-missing-label-servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action)
component: operator

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Added missing label for Service/Pod Monitors

# One or more tracking issues related to the change
issues: [2251]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
1 change: 1 addition & 0 deletions internal/manifests/collector/podmonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func PodMonitor(params manifests.Params) (*monitoringv1.PodMonitor, error) {
MatchLabels: map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
"app.kubernetes.io/instance": fmt.Sprintf("%s.%s", params.OtelCol.Namespace, params.OtelCol.Name),
"app.kubernetes.io/name": "otel-collector-monitoring",
},
},
PodMetricsEndpoints: append(
Expand Down
18 changes: 16 additions & 2 deletions internal/manifests/collector/podmonitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,31 @@ func TestDesiredPodMonitors(t *testing.T) {
assert.Equal(t, fmt.Sprintf("%s-collector", params.OtelCol.Name), actual.Name)
assert.Equal(t, params.OtelCol.Namespace, actual.Namespace)
assert.Equal(t, "monitoring", actual.Spec.PodMetricsEndpoints[0].Port)
expectedSelectorLabels := map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
"app.kubernetes.io/instance": fmt.Sprintf("%s.%s", params.OtelCol.Namespace, params.OtelCol.Name),
"app.kubernetes.io/name": "otel-collector-monitoring",
}
assert.Equal(t, expectedSelectorLabels, actual.Spec.Selector.MatchLabels)
}

params, err = newParams("", "testdata/prometheus-exporter.yaml")
func TestDesiredPodMonitorsWithPrometheus(t *testing.T) {
params, err := newParams("", "testdata/prometheus-exporter.yaml")
assert.NoError(t, err)
params.OtelCol.Spec.Mode = v1alpha1.ModeSidecar
params.OtelCol.Spec.Observability.Metrics.EnableMetrics = true
actual, err = PodMonitor(params)
actual, err := PodMonitor(params)
assert.NoError(t, err)
assert.NotNil(t, actual)
assert.Equal(t, fmt.Sprintf("%s-collector", params.OtelCol.Name), actual.Name)
assert.Equal(t, params.OtelCol.Namespace, actual.Namespace)
assert.Equal(t, "monitoring", actual.Spec.PodMetricsEndpoints[0].Port)
assert.Equal(t, "prometheus-dev", actual.Spec.PodMetricsEndpoints[1].Port)
assert.Equal(t, "prometheus-prod", actual.Spec.PodMetricsEndpoints[2].Port)
expectedSelectorLabels := map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
"app.kubernetes.io/instance": fmt.Sprintf("%s.%s", params.OtelCol.Namespace, params.OtelCol.Name),
"app.kubernetes.io/name": "otel-collector-monitoring",
}
assert.Equal(t, expectedSelectorLabels, actual.Spec.Selector.MatchLabels)
}
1 change: 1 addition & 0 deletions internal/manifests/collector/servicemonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func ServiceMonitor(params manifests.Params) (*monitoringv1.ServiceMonitor, erro
MatchLabels: map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
"app.kubernetes.io/instance": fmt.Sprintf("%s.%s", params.OtelCol.Namespace, params.OtelCol.Name),
"app.kubernetes.io/name": "otel-collector-monitoring",
},
},
},
Expand Down
18 changes: 16 additions & 2 deletions internal/manifests/collector/servicemonitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,30 @@ func TestDesiredServiceMonitors(t *testing.T) {
assert.Equal(t, fmt.Sprintf("%s-collector", params.OtelCol.Name), actual.Name)
assert.Equal(t, params.OtelCol.Namespace, actual.Namespace)
assert.Equal(t, "monitoring", actual.Spec.Endpoints[0].Port)
expectedSelectorLabels := map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
"app.kubernetes.io/instance": fmt.Sprintf("%s.%s", params.OtelCol.Namespace, params.OtelCol.Name),
"app.kubernetes.io/name": "otel-collector-monitoring",
}
assert.Equal(t, expectedSelectorLabels, actual.Spec.Selector.MatchLabels)
}

params, err = newParams("", "testdata/prometheus-exporter.yaml")
func TestDesiredServiceMonitorsWithPrometheus(t *testing.T) {
params, err := newParams("", "testdata/prometheus-exporter.yaml")
assert.NoError(t, err)
params.OtelCol.Spec.Observability.Metrics.EnableMetrics = true
actual, err = ServiceMonitor(params)
actual, err := ServiceMonitor(params)
assert.NoError(t, err)
assert.NotNil(t, actual)
assert.Equal(t, fmt.Sprintf("%s-collector", params.OtelCol.Name), actual.Name)
assert.Equal(t, params.OtelCol.Namespace, actual.Namespace)
assert.Equal(t, "monitoring", actual.Spec.Endpoints[0].Port)
assert.Equal(t, "prometheus-dev", actual.Spec.Endpoints[1].Port)
assert.Equal(t, "prometheus-prod", actual.Spec.Endpoints[2].Port)
expectedSelectorLabels := map[string]string{
"app.kubernetes.io/managed-by": "opentelemetry-operator",
"app.kubernetes.io/instance": fmt.Sprintf("%s.%s", params.OtelCol.Namespace, params.OtelCol.Name),
"app.kubernetes.io/name": "otel-collector-monitoring",
}
assert.Equal(t, expectedSelectorLabels, actual.Spec.Selector.MatchLabels)
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ spec:
matchLabels:
app.kubernetes.io/managed-by: opentelemetry-operator
app.kubernetes.io/instance: create-pm-prometheus.simplest
app.kubernetes.io/name: otel-collector-monitoring
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ spec:
matchLabels:
app.kubernetes.io/managed-by: opentelemetry-operator
app.kubernetes.io/instance: create-sm-prometheus.simplest
app.kubernetes.io/name: otel-collector-monitoring
---
apiVersion: v1
kind: Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ spec:
matchLabels:
app.kubernetes.io/managed-by: opentelemetry-operator
app.kubernetes.io/instance: create-sm-prometheus.simplest
app.kubernetes.io/name: otel-collector-monitoring
---
apiVersion: v1
kind: Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ spec:
matchLabels:
app.kubernetes.io/managed-by: opentelemetry-operator
app.kubernetes.io/instance: create-sm-prometheus.simplest
app.kubernetes.io/name: otel-collector-monitoring
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ spec:
matchLabels:
app.kubernetes.io/managed-by: opentelemetry-operator
app.kubernetes.io/instance: create-sm-prometheus.simplest
app.kubernetes.io/name: otel-collector-monitoring

0 comments on commit ea1e00a

Please sign in to comment.