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

Use standard label selectors in target allocator config #2564

Merged
merged 2 commits into from
Jan 25, 2024

Conversation

swiatekm
Copy link
Contributor

@swiatekm swiatekm commented Jan 25, 2024

Description:
Use standard label selectors in target allocator config instead of plain maps. This is a step towards resolving #1907 in v1alpha2 CRs, by using these selectors in the CRDs themselves as well.

I'd wanted to keep backwards compatibility with older target allocator versions to make upgrades easier, so I couldn't simply change the types of existing config fields. Instead, I decided to move all of these fields under the prometheus_cr section in the configuration, which imo is the more intuitive location for it anyway.

There's also a difference in semantics between our current v1alpha1 CRD and standard behaviour for these selectors that I needed to handle. For selectors:

  • a nil selector means "select nothing", which is also the default in prometheus-operator CRs
  • an empty {} selector means "select everything"
  • a selector with actual labels or expressions works as expected

However, for the label maps in our v1alpha1 CRD, an empty or nil map means "select everything". As a result, I needed to make sure we put an empty selector in the configuration in that case. This is the reason they appear in the modified test code. In v1alpha2, we can change this behaviour to match prometheus-operator.

Link to tracking Issue: #1907

Testing:
Modified existing unit tests. Existing E2E tests cover the functionality.

@swiatekm swiatekm changed the title Use standard label selectors for Prometheus CR Use standard label selectors in target allocator config Jan 25, 2024
@swiatekm swiatekm force-pushed the feat/ta/monitor-selectors branch from dd73dd6 to 941ac15 Compare January 25, 2024 11:35
@swiatekm swiatekm marked this pull request as ready for review January 25, 2024 11:47
@swiatekm swiatekm requested review from a team January 25, 2024 11:47
@@ -68,10 +68,20 @@ func ConfigMap(params manifests.Params) (*corev1.ConfigMap, error) {
prometheusCRConfig["scrape_interval"] = params.OtelCol.Spec.TargetAllocator.PrometheusCR.ScrapeInterval.Duration
}

prometheusCRConfig["service_monitor_selector"] = &metav1.LabelSelector{
Copy link
Contributor

Choose a reason for hiding this comment

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

just to confirm my understanding here... by not having the nil check we follow what prometheus expects i.e. when service/pod monitor selector is nil nothing will be selected? whereas before we just didn't set it and assumed everything?

Copy link
Contributor

Choose a reason for hiding this comment

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

do we have a test in the configmap_test.go for this new nil behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just to confirm my understanding here... by not having the nil check we follow what prometheus expects i.e. when service/pod monitor selector is nil nothing will be selected? whereas before we just didn't set it and assumed everything?

Prometheus' (and LabelSelector in general) behaviour is that nil == nothing and empty == everything. We on the other hand, took the map being empty or nil to mean everything, and there wasn't any way to set it to be nothing.

I've modified the configmap tests (and the builder and reconciliation tests) to show the empty label selectors. E2E tests check that this works as well - I know because I had a bug here earlier, and they caught it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In a sense, I'm moving the logic from target allocator here. If you look at the target allocator changes, it used to have this for the Prometheus Spec:

ServiceMonitorSelector: &metav1.LabelSelector{
	MatchLabels: cfg.ServiceMonitorSelector,
},

Now we have this here, accomplishing the same thing.

Copy link
Contributor

Choose a reason for hiding this comment

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

gotcha, thanks for explaining.

@jaronoff97 jaronoff97 merged commit f918128 into open-telemetry:main Jan 25, 2024
27 checks passed
@swiatekm swiatekm deleted the feat/ta/monitor-selectors branch February 14, 2024 17:15
ItielOlenick pushed a commit to ItielOlenick/opentelemetry-operator that referenced this pull request May 1, 2024
…ry#2564)

* Use standard label selectors in target allocator config

* Move all CR selectors in TA config to the right section
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.

2 participants