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

WIP: Allow users to choose Endpoints/EndpoinSlice role in Prometheus and Prometheus Agent #6518

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

haanhvu
Copy link
Contributor

@haanhvu haanhvu commented Apr 16, 2024

Description

First task of the remaining tasks to support EndpointSlice, as discussed in #3862 (comment)

Type of change

What type of changes does your code introduce to the Prometheus operator? Put an x in the box that apply.

  • CHANGE (fix or feature that would cause existing functionality to not work as expected)
  • FEATURE (non-breaking change which adds functionality)
  • BUGFIX (non-breaking change which fixes an issue)
  • ENHANCEMENT (non-breaking change which improves existing functionality)
  • NONE (if none of the other choices apply. Example, tooling, build system, CI, docs, etc.)

Changelog entry

Allow users to choose Endpoints/EndpoinSlice role in Prometheus and Prometheus Agent

@haanhvu haanhvu requested a review from a team as a code owner April 16, 2024 11:43
@simonpasquier simonpasquier self-requested a review April 18, 2024 13:26
Comment on lines +696 to +698
// +kubebuilder:default="Endpoints"
// +kubebuilder:validation:Enum=Endpoints;EndpointSlice
ServiceDiscoveryRole string `json:"serviceDiscoveryRole,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I would make it optional without a predefined default so we could maybe toggle the default in the future.

Suggested change
// +kubebuilder:default="Endpoints"
// +kubebuilder:validation:Enum=Endpoints;EndpointSlice
ServiceDiscoveryRole string `json:"serviceDiscoveryRole,omitempty"`
// ServiceDiscoveryRole defines the service discovery role to use when discovering Kubernetes endpoints from ServiceMonitor objects. By default, the operator uses the `Endpoints` role.
//
// +kubebuilder:validation:Enum=Endpoints;EndpointSlice
// +optional
ServiceDiscoveryRole *string `json:"serviceDiscoveryRole,omitempty"`

Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't that be a breaking change anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think what Simon meant from the suggested change is:

  • If users don't set ServiceDiscoveryRole, or set it as Endpoints, we use Endpoints
  • Only if users set it as EndpointSlice, we use EndpointSlice

This way I don't think it would break current users' setup? Since we're already using Endpoints.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but I also understood that we want to change to EndpoitSlice by default in the future 😬. I was wondering how safe this change would be if we ever happen to make it.

But that's a problem for a future PR, going forward with Endpoints by default sounds the correct approach here :)

Copy link
Contributor Author

@haanhvu haanhvu May 7, 2024

Choose a reason for hiding this comment

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

I think how safe that change would be depends very much on how popular EndpointSlice would be. I researched this a bit (for ServiceMonitor support in GSoC proposal). There're questions around when/whether Kubernetes can deprecate Endpoints, since EndpointSlice has already proved to perform better.

If some far day Endpoints is not used anymore (or very rarely used), I think we can safely make EndpointSlice as the default.

@@ -68,7 +68,7 @@ type ConfigGenerator struct {
}

// NewConfigGenerator creates a ConfigGenerator for the provided Prometheus resource.
func NewConfigGenerator(logger log.Logger, p monitoringv1.PrometheusInterface, endpointSliceSupported bool) (*ConfigGenerator, error) {
func NewConfigGenerator(logger log.Logger, p monitoringv1.PrometheusInterface, endpointSliceSupported *bool) (*ConfigGenerator, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why change from a bool value to a bool pointer?

Copy link
Contributor Author

@haanhvu haanhvu Apr 22, 2024

Choose a reason for hiding this comment

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

Yeah it's not necessary.

Before I thought we needed to check the value of ServiceDiscoveryRole inside NewConfigGenerator(). If ServiceDiscoveryRole != "EndpointSlice" then we needed to change endpointSliceSupported = false (it may have been true before). That was why I changed the type of endpointSliceSupported to a bool pointer.

But now rereading the code I realized we can also check the value of ServiceDiscoveryRole and finalize the value of endpointSliceSupported inside sync() in Prometheus/Prometheus Agent operator, right before calling NewConfigGenerator(). So no need to make endpointSliceSupported a bool pointer anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants