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

enhancement: allow toggling custom config deprecation behaviour #6955

Merged

Conversation

rexagod
Copy link
Contributor

@rexagod rexagod commented Sep 22, 2024

Description

Allow toggling custom config deprecation behaviour; helpful in scenarios where a controller disables all service discovery methods.

Type of change

  • 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

Users can toggle Prometheus controller's custom configuration deprecation behavior using the "--deprecate-custom-configuration" flag.

Sorry, something went wrong.

@rexagod rexagod force-pushed the deprecate-custom-config branch from e58644d to b667bf5 Compare September 22, 2024 18:30
@@ -49,6 +49,8 @@ Usage of ./operator:
Value used by the operator to filter Alertmanager, Prometheus, PrometheusAgent and ThanosRuler objects that it should reconcile. If the value isn't empty, the operator only reconciles objects with an operator.prometheus.io/controller-id annotation of the same value. Otherwise the operator reconciles all objects without the annotation or with an empty annotation value.
-deny-namespaces value
Namespaces not to scope the interaction of the Prometheus Operator (deny list). This is mutually exclusive with --namespaces.
-deprecate-custom-configuration
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest to name the flag -disable-unmanaged-prometheus-configuration and default to false.

@mviswanathsai
Copy link
Contributor

Not sure I understand what the flag is for, can you elaborate a bit? I lack the context behind this.

@simonpasquier
Copy link
Contributor

To provide more context, there's a legacy behavior which instructs the operator to not manage the Prometheus configuration when all selectors (ruleSelector, serviceMonitorSelector, ...) are nil. In this case, the user is supposed to build by hand the secret holding the (gzipped) configuration. It can be a pain to debug if you run into this mode by accident because the operator doesn't complain but the Prometheus statefulset will never spin up pods if the secret is missing.
This is very much deprecated now since we have additionalScrapeConfigs + ScrapeConfig CRD but removing it would break users. Adding a flag to say "don't support unamanaged configuration mode" improves the UX.

@rexagod rexagod force-pushed the deprecate-custom-config branch from f6de19a to b1e4375 Compare October 7, 2024 14:55
@pull-request-size pull-request-size bot added size/M and removed size/S labels Oct 7, 2024
@rexagod rexagod force-pushed the deprecate-custom-config branch from b1e4375 to b5797a8 Compare October 7, 2024 15:06
@rexagod
Copy link
Contributor Author

rexagod commented Oct 7, 2024

This PR is rebased on #6992 to address an issue that crashed the make generate target.

@rexagod rexagod marked this pull request as ready for review October 8, 2024 06:07
@rexagod rexagod requested a review from a team as a code owner October 8, 2024 06:07
@rexagod rexagod force-pushed the deprecate-custom-config branch 2 times, most recently from 28fe238 to aee0477 Compare October 8, 2024 07:13
@rexagod rexagod force-pushed the deprecate-custom-config branch from aee0477 to 7e9f70d Compare October 21, 2024 08:41
Allow toggling custom config deprecation behaviour; helpful in scenarios
where a controller disables all service discovery methods.

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
@rexagod rexagod force-pushed the deprecate-custom-config branch from 7e9f70d to 7a052f5 Compare October 21, 2024 08:42
@pull-request-size pull-request-size bot added size/S and removed size/M labels Oct 21, 2024
@rexagod rexagod requested a review from simonpasquier October 21, 2024 09:32
Copy link
Contributor

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

As a follow-up change, I suggest to enhance the Reconciled status condition so that when all selectors are nil, it gets reflected in the reconciled message. E.g. it's not an error but it can be hard to find out what you missed. Something like:

status:
  availableReplicas: 2
  conditions:
  - lastTransitionTime: "2024-10-21T14:45:40Z"
    message: ""
    observedGeneration: 2
    reason: ""
    status: "True"
    type: Available
  - lastTransitionTime: "2024-10-21T14:45:40Z"
    message: "None of the scrape resource selectors are specified."
    observedGeneration: 2
    reason: "NoScrapeResourceSelected"
    status: "True"
    type: Reconciled

@@ -183,7 +185,7 @@ func parseFlags(fs *flag.FlagSet) {
fs.Var(&cfg.SecretListWatchLabelSelector, "secret-label-selector", "Label selector to filter Secrets to watch")

fs.Float64Var(&memlimitRatio, "auto-gomemlimit-ratio", defaultMemlimitRatio, "The ratio of reserved GOMEMLIMIT memory to the detected maximum container or system memory. The value should be greater than 0.0 and less than 1.0. Default: 0.0 (disabled).")

fs.BoolVar(&disableUnmanagedPrometheusConfiguration, "disable-unmanaged-prometheus-configuration", false, "Toggle the legacy deprecation behaviour for unmanaged Prometheus configuration. Default: false.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fs.BoolVar(&disableUnmanagedPrometheusConfiguration, "disable-unmanaged-prometheus-configuration", false, "Toggle the legacy deprecation behaviour for unmanaged Prometheus configuration. Default: false.")
fs.BoolVar(&disableUnmanagedPrometheusConfiguration, "disable-unmanaged-prometheus-configuration", false, "Disable support for unmanaged Prometheus configuration when all resource selectors are nil. Default: false.")

@@ -117,6 +119,14 @@ func WithStorageClassValidation() ControllerOption {
}
}

// WithDisableUnmanagedPrometheusConfiguration tells that the controller should deprecate
// the custom configuration.
func WithDisableUnmanagedPrometheusConfiguration() ControllerOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func WithDisableUnmanagedPrometheusConfiguration() ControllerOption {
func WithUnmanagedConfigurationDisabled() ControllerOption {

@@ -91,6 +91,8 @@ type Operator struct {
canReadStorageClass bool

eventRecorder record.EventRecorder

disableUnmanagedPrometheusConfiguration bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
disableUnmanagedPrometheusConfiguration bool
disableUnmanagedConfiguration bool

@@ -954,7 +964,7 @@ func (c *Operator) UpdateStatus(ctx context.Context, key string) error {
return nil
}

func logDeprecatedFields(logger *slog.Logger, p *monitoringv1.Prometheus) {
func logDeprecatedFields(logger *slog.Logger, p *monitoringv1.Prometheus, disableUnmanagedPrometheusConfiguration bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

(suggestion) let's make it a pointer receiver function.

Suggested change
func logDeprecatedFields(logger *slog.Logger, p *monitoringv1.Prometheus, disableUnmanagedPrometheusConfiguration bool) {
func (c *Operator) logDeprecatedFields(logger *slog.Logger, p *monitoringv1.Prometheus) {

@@ -274,6 +276,9 @@ func run(fs *flag.FlagSet) int {
promControllerOptions = []prometheuscontroller.ControllerOption{}
thanosControllerOptions = []thanoscontroller.ControllerOption{}
)
if disableUnmanagedPrometheusConfiguration {
promControllerOptions = append(promControllerOptions, prometheuscontroller.WithDisableUnmanagedPrometheusConfiguration())
Copy link
Contributor

Choose a reason for hiding this comment

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

it might be good to log an info message saying that unmanaged configuration is disabled.

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
@rexagod rexagod force-pushed the deprecate-custom-config branch from 83864a0 to 39ff9a0 Compare October 22, 2024 21:31
Copy link
Contributor

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

I've got just a few last nits otherwise LGTM.

@@ -49,6 +49,8 @@ Usage of ./operator:
Value used by the operator to filter Alertmanager, Prometheus, PrometheusAgent and ThanosRuler objects that it should reconcile. If the value isn't empty, the operator only reconciles objects with an operator.prometheus.io/controller-id annotation of the same value. Otherwise the operator reconciles all objects without the annotation or with an empty annotation value.
-deny-namespaces value
Namespaces not to scope the interaction of the Prometheus Operator (deny list). This is mutually exclusive with --namespaces.
-disable-unmanaged-prometheus-configuration
Disable support for unmanaged Prometheus configuration when all resource selectors are nil. Default: false.
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit) let's provide more context why you might want to use the flag.

Suggested change
Disable support for unmanaged Prometheus configuration when all resource selectors are nil. Default: false.
Disable support for unmanaged Prometheus configuration when all resource selectors are nil. As stated in the API documentation, unmanaged Prometheus configuration is a deprecated feature which can be avoided with "additionalScrapeConfigs` or the ScrapeConfig CRD. Default: false.

@@ -91,6 +91,8 @@ type Operator struct {
canReadStorageClass bool

eventRecorder record.EventRecorder

disableUnmanagedConfiguration bool
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit) can we move it next to the other bool fields (e.g. at L92)?

@@ -117,6 +119,14 @@ func WithStorageClassValidation() ControllerOption {
}
}

// WithUnmanagedConfigurationDisabled tells that the controller should deprecate
// the custom configuration.
func WithUnmanagedConfigurationDisabled() ControllerOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit)

Suggested change
func WithUnmanagedConfigurationDisabled() ControllerOption {
func WithoutUnmanagedConfiguration() ControllerOption {

@pull-request-size pull-request-size bot added size/M and removed size/S labels Nov 4, 2024
…ation behaviour
@rexagod rexagod force-pushed the deprecate-custom-config branch from 88d46cc to bc8c0c3 Compare November 4, 2024 08:04
@rexagod rexagod requested a review from simonpasquier November 5, 2024 08:32
Copy link
Contributor

@simonpasquier simonpasquier 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 nits but lgtm

@@ -49,6 +49,8 @@ Usage of ./operator:
Value used by the operator to filter Alertmanager, Prometheus, PrometheusAgent and ThanosRuler objects that it should reconcile. If the value isn't empty, the operator only reconciles objects with an operator.prometheus.io/controller-id annotation of the same value. Otherwise the operator reconciles all objects without the annotation or with an empty annotation value.
-deny-namespaces value
Namespaces not to scope the interaction of the Prometheus Operator (deny list). This is mutually exclusive with --namespaces.
-disable-unmanaged-prometheus-configuration additionalScrapeConfigs
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, not sure why we have additionalScrapeConfigs here but it looks like removing the backticks in the help text should fix it 🤯

@@ -183,7 +185,7 @@ func parseFlags(fs *flag.FlagSet) {
fs.Var(&cfg.SecretListWatchLabelSelector, "secret-label-selector", "Label selector to filter Secrets to watch")

fs.Float64Var(&memlimitRatio, "auto-gomemlimit-ratio", defaultMemlimitRatio, "The ratio of reserved GOMEMLIMIT memory to the detected maximum container or system memory. The value should be greater than 0.0 and less than 1.0. Default: 0.0 (disabled).")

fs.BoolVar(&disableUnmanagedPrometheusConfiguration, "disable-unmanaged-prometheus-configuration", false, "Disable support for unmanaged Prometheus configuration when all resource selectors are nil. As stated in the API documentation, unmanaged Prometheus configuration is a deprecated feature which can be avoided with `additionalScrapeConfigs` or the ScrapeConfig CRD. Default: false.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fs.BoolVar(&disableUnmanagedPrometheusConfiguration, "disable-unmanaged-prometheus-configuration", false, "Disable support for unmanaged Prometheus configuration when all resource selectors are nil. As stated in the API documentation, unmanaged Prometheus configuration is a deprecated feature which can be avoided with `additionalScrapeConfigs` or the ScrapeConfig CRD. Default: false.")
fs.BoolVar(&disableUnmanagedPrometheusConfiguration, "disable-unmanaged-prometheus-configuration", false, "Disable support for unmanaged Prometheus configuration when all resource selectors are nil. As stated in the API documentation, unmanaged Prometheus configuration is a deprecated feature which can be avoided with '.spec.additionalScrapeConfigs' or the ScrapeConfig CRD. Default: false.")

@@ -274,6 +276,10 @@ func run(fs *flag.FlagSet) int {
promControllerOptions = []prometheuscontroller.ControllerOption{}
thanosControllerOptions = []thanoscontroller.ControllerOption{}
)
if disableUnmanagedPrometheusConfiguration {
logger.Info("unmanaged Prometheus configuration is disabled")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger.Info("unmanaged Prometheus configuration is disabled")
logger.Info("Disabling support for unmanaged Prometheus configurations")

Comment on lines 121 to 122
// WithoutUnmanagedConfiguration tells that the controller should deprecate
// the custom configuration.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// WithoutUnmanagedConfiguration tells that the controller should deprecate
// the custom configuration.
// WithoutUnmanagedConfiguration tells that the controller should not support
// unmanaged configurations.

… deprecation behaviour
@simonpasquier simonpasquier enabled auto-merge (squash) November 7, 2024 15:52
@simonpasquier
Copy link
Contributor

Thanks!

@simonpasquier simonpasquier merged commit f5218e1 into prometheus-operator:main Nov 7, 2024
23 checks passed
nicolastakashi pushed a commit that referenced this pull request Nov 18, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
nicolastakashi pushed a commit that referenced this pull request Nov 18, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
nicolastakashi pushed a commit that referenced this pull request Nov 18, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
nicolastakashi pushed a commit that referenced this pull request Nov 18, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
nicolastakashi pushed a commit that referenced this pull request Nov 18, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
nicolastakashi pushed a commit that referenced this pull request Nov 19, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
nicolastakashi pushed a commit that referenced this pull request Nov 19, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
nicolastakashi pushed a commit that referenced this pull request Nov 22, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
nicolastakashi pushed a commit that referenced this pull request Nov 22, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
nicolastakashi pushed a commit that referenced this pull request Nov 22, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
nicolastakashi pushed a commit that referenced this pull request Nov 30, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
nicolastakashi pushed a commit that referenced this pull request Nov 30, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
nicolastakashi pushed a commit that referenced this pull request Nov 30, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
nicolastakashi pushed a commit that referenced this pull request Dec 2, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
nicolastakashi pushed a commit that referenced this pull request Dec 2, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
nicolastakashi pushed a commit that referenced this pull request Dec 3, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
nicolastakashi pushed a commit that referenced this pull request Dec 3, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
nicolastakashi pushed a commit that referenced this pull request Dec 4, 2024
* enhancement: allow toggling custom config deprecation behaviour

---------

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
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