Skip to content

[feat]:Refactor KumaSDconfig#7379

Closed
Dharma-09 wants to merge 13 commits intoprometheus-operator:mainfrom
Dharma-09:feat/kumasd
Closed

[feat]:Refactor KumaSDconfig#7379
Dharma-09 wants to merge 13 commits intoprometheus-operator:mainfrom
Dharma-09:feat/kumasd

Conversation

@Dharma-09
Copy link
Contributor

Description

This pull request refactors the validation logic for the KumaSDConfig struct in the Prometheus Operator. The changes include improving the handling of configuration fields such as server, ClientID, TLSConfig , ProxyURL,AllowRedirect.

Fixes

#7203

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.)

Verification

Please check the Prometheus-Operator testing guidelines for recommendations about automated tests.

Changelog entry

Please put a one-line changelog entry below. This will be copied to the changelog file during the release process.

NONE

@Dharma-09 Dharma-09 requested a review from a team as a code owner March 3, 2025 19:54
@Dharma-09 Dharma-09 changed the title Open new pr for KumsSDconfig [feat]:Refactore KumsSDconfig Mar 3, 2025
@Dharma-09 Dharma-09 changed the title [feat]:Refactore KumsSDconfig [feat]:Refactor KumsSDconfig Mar 3, 2025
@Dharma-09
Copy link
Contributor Author

I have closed Pull Request #7241 due to rebase conflicts. To ensure a clean integration, I have opened a new pull request with the necessary changes.

@Dharma-09 Dharma-09 changed the title [feat]:Refactor KumsSDconfig [feat]:Refactor KumaSDconfig Mar 3, 2025
@pull-request-size pull-request-size bot added size/M and removed size/L labels Mar 8, 2025
Copy link
Contributor

@mviswanathsai mviswanathsai left a comment

Choose a reason for hiding this comment

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

Thanks for the effort! a few comments, but otherwise seems good to me.

@mviswanathsai
Copy link
Contributor

Also, the ClientID is only configurable for Prometheus >= v2.50.0. We may want to add the check for that as well. Something similar to: https://github.com/prometheus-operator/prometheus-operator/blob/main/pkg/prometheus/resource_selector.go#L1061-L1063

You would also need to add the comment above the ClientID field. Like so:

	// It requires Prometheus >= v2.50.0.

@pull-request-size pull-request-size bot added size/L and removed size/M labels Mar 14, 2025
@Dharma-09
Copy link
Contributor Author

@mviswanathsai Thanks for reviewing it.

@slashpai
Copy link
Contributor

@Dharma-09 Can you rebase, if everything looks good we may be able to merge this before release tomorrow

Copy link
Contributor

@mviswanathsai mviswanathsai left a comment

Choose a reason for hiding this comment

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

LGTM

func (rs *ResourceSelector) validateKumaSDConfigs(ctx context.Context, sc *monitoringv1alpha1.ScrapeConfig) error {
for i, config := range sc.Spec.KumaSDConfigs {
if config.ClientID != nil && rs.version.LT(semver.MustParse("2.50.0")) {
return fmt.Errorf("field `clientID` is only supported for Prometheus version >= 2.50.0")
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add the [%d] prefix like for other errors?

return fmt.Errorf("[%d]: invalid scheme '%s'. Only 'http' and 'https' are supported", i, parsedURL.Scheme)
}

if len(parsedURL.Scheme) == 0 || len(parsedURL.Host) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

If I read the code properly, scheme can't be empty at this stage. Nit but in other places, we prefer to test against the empty string rather than the string length.

Suggested change
if len(parsedURL.Scheme) == 0 || len(parsedURL.Host) == 0 {
if parsedURL.Host == "" {

@@ -923,6 +923,8 @@ type KumaSDConfig struct {
// +required
Copy link
Contributor

Choose a reason for hiding this comment

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

would it make sense to use the URL type which would validate that the value starts by https?://?

@slashpai
Copy link
Contributor

@Dharma-09 Can you rebase and address code review comments?

@mviswanathsai mviswanathsai mentioned this pull request Jul 10, 2025
5 tasks
@github-actions github-actions bot added the stale label Aug 20, 2025
@nutmos nutmos mentioned this pull request Oct 1, 2025
5 tasks
@simonpasquier
Copy link
Contributor

superseded by #7966.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants