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

Add missing label servicemonitor #2573

Merged

Conversation

yuriolisa
Copy link
Contributor

Description:

Add missing label for Service/Pod Monitors
Link to tracking Issue:
Resolves #2251
Testing:
Added unit and e2e tests.
Documentation:

@yuriolisa yuriolisa requested a review from a team January 29, 2024 11:08
@swiatekm
Copy link
Contributor

Could we use manifestutils.Labels for these?

@yuriolisa
Copy link
Contributor Author

Could we use manifestutils.Labels for these?

No, but I could include a PodMonitorSelector and ServiceMonitorSelector. WDYT?

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]>
@yuriolisa yuriolisa force-pushed the add-missing-label-servicemonitor branch from d88ee20 to ea1e00a Compare January 29, 2024 12:31
Copy link
Contributor

@jaronoff97 jaronoff97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuriolisa i left a comment on the original issue for how I think we should solve this. Let me know your thoughts.

Copy link
Contributor

@jaronoff97 jaronoff97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions. Do we have an e2e test for this that checks that we successfully pulled metrics based on the SM/PM?

internal/manifests/manifestutils/labels.go Outdated Show resolved Hide resolved
internal/manifests/manifestutils/labels.go Outdated Show resolved Hide resolved
Signed-off-by: Yuri Sa <[email protected]>
internal/manifests/collector/podmonitor_test.go Outdated Show resolved Hide resolved
internal/manifests/manifestutils/labels.go Outdated Show resolved Hide resolved
Copy link
Contributor

@jaronoff97 jaronoff97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i meant to click request changes for that podmonitor issue

@yuriolisa
Copy link
Contributor Author

yuriolisa commented Feb 12, 2024

i meant to click request changes for that podmonitor issue

Added the comment and changed the PodMonitor matchLabels to the default one.

@yuriolisa yuriolisa requested a review from jaronoff97 February 12, 2024 11:42
Copy link
Contributor

@jaronoff97 jaronoff97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one comment, otherwise i think this is looking good!

Signed-off-by: Yuri Sa <[email protected]>
Signed-off-by: Yuri Sa <[email protected]>
@jaronoff97
Copy link
Contributor

looks like some legit e2e and lint failures

@yuriolisa yuriolisa requested a review from jaronoff97 February 29, 2024 15:32
Copy link
Contributor

@jaronoff97 jaronoff97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one tiny comment, but i don't think it really matters.

internal/manifests/collector/podmonitor.go Outdated Show resolved Hide resolved
Copy link
Contributor

@swiatekm swiatekm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a e2e test similar to this one: https://github.com/open-telemetry/opentelemetry-operator/tree/main/tests/e2e-targetallocator/targetallocator-prometheuscr? I'd like to check that our generated PodMonitors and ServiceMonitors allow us to actually scrape collector metrics.

"app.kubernetes.io/instance": fmt.Sprintf("%s.%s", params.OtelCol.Namespace, params.OtelCol.Name),
"app.kubernetes.io/managed-by": "opentelemetry-operator",
"app.kubernetes.io/part-of": "opentelemetry",
"app.kubernetes.io/name": naming.MonitoringService(params.OtelCol.Name),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuriolisa i realized that we actually need to update the monitoring service for the collector to have its own special label in the same way we do for headless and instead match on that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is because the name label for the service actually is just the name of the overall collector

Signed-off-by: Yuri Sa <[email protected]>
Signed-off-by: Yuri Sa <[email protected]>
headlessLabel = "operator.opentelemetry.io/collector-headless-service"
headlessExists = "Exists"
headlessLabel = "operator.opentelemetry.io/collector-headless-service"
headlessExists = "Exists"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can consolidate here

@@ -44,7 +46,7 @@ func HeadlessService(params manifests.Params) (*corev1.Service, error) {
h.Name = naming.HeadlessService(params.OtelCol.Name)
h.Labels[headlessLabel] = headlessExists

// copy to avoid modifying params.OtelCol.Annotations
// copy to avoid modifying params.OtelCol.annotations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uppercase?

@@ -44,7 +44,6 @@ func ServiceMonitor(params manifests.Params) (*monitoringv1.ServiceMonitor, erro
}
name := naming.ServiceMonitor(params.OtelCol.Name)
labels := manifestutils.Labels(params.OtelCol.ObjectMeta, name, params.OtelCol.Spec.Image, ComponentOpenTelemetryCollector, []string{})
selectorMatchLabels := manifestutils.SelectorMatchLabels(params.OtelCol.ObjectMeta, ComponentOpenTelemetryCollector)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should still be using this to match on the overall labels we expect the service to have, otherwise our match would be too wide

Copy link
Contributor

@jaronoff97 jaronoff97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one last thing to improve test confidence, but the overall logic here looks 👌

Signed-off-by: Yuri Sa <[email protected]>
@pavolloffay pavolloffay merged commit 75fb162 into open-telemetry:main Mar 11, 2024
31 checks passed
ItielOlenick pushed a commit to ItielOlenick/opentelemetry-operator that referenced this pull request May 1, 2024
* 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]>

Add missing label for Service/Pod Monitors

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

* Added manifests.utils to set labels

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

* Fixed labels names

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

* Fixed labels for PodMonitor

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

* Fixed e2e test

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

* Fixed e2e test

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

* Fixed selectorMatchLabels

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

* Removed the extra method

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

* Adjusted nil

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

* Changed labels

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

* Changed labels

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

* Readded common labels

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

* Readded common labels

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

* Added labels assert

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

---------

Signed-off-by: Yuri Sa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mixing Prometheus Exporter with Collector's ServiceMonitor leads to double-scraping of metrics
5 participants