Skip to content

Refactor HTTP Service Discovery#6800

Merged
simonpasquier merged 1 commit intoprometheus-operator:mainfrom
mviswanathsai:sc-refactor--http-sd
Aug 30, 2024
Merged

Refactor HTTP Service Discovery#6800
simonpasquier merged 1 commit intoprometheus-operator:mainfrom
mviswanathsai:sc-refactor--http-sd

Conversation

@mviswanathsai
Copy link
Contributor

@mviswanathsai mviswanathsai commented Aug 5, 2024

Description

This PR refactors the HTTP Service Discovery, adds new test cases for unit tests.
PR also adds OAuth2, FollowRedirects and EnableHTTP2 fields to the HTTP service discovery.

Generic API validation e2e tests are yet to be added.

Closes #6798

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.


@mviswanathsai mviswanathsai requested a review from a team as a code owner August 5, 2024 12:10
@mviswanathsai
Copy link
Contributor Author

Not sure why OAuth2, FollowRedirects and EnableHTTP2 were not added originally. I did not find any documentation stating that they are unsupported nor did I find any evidence for this in the code (hoping you could verify). Were these fields intentionally left out? was it a mistake?
CC: @slashpai @simonpasquier

@slashpai
Copy link
Contributor

slashpai commented Aug 7, 2024

Not sure why OAuth2, FollowRedirects and EnableHTTP2 were not added originally. I did not find any documentation stating that they are unsupported nor did I find any evidence for this in the code (hoping you could verify). Were these fields intentionally left out? was it a mistake? CC: @slashpai @simonpasquier

httpsd was one of the first SD added to scrapeconfig IIRC it must have added required fields at that moment, thanks for adding rest

@mviswanathsai
Copy link
Contributor Author

mviswanathsai commented Aug 9, 2024

I will re-base once the EC2 PR is merged and add CRD validation tests for HTTPSDConfigs.

@mviswanathsai
Copy link
Contributor Author

I will re-base as soon as we are happy with the changes and the PR for subtests is merged!

@simonpasquier
Copy link
Contributor

Another merge conflict appeared :)

@mviswanathsai
Copy link
Contributor Author

Conflicts resolved. PTAL @simonpasquier

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.

LGTM, a few nits only.

scrapeConfigSpec: monitoringv1alpha1.ScrapeConfigSpec{
HTTPSDConfigs: []monitoringv1alpha1.HTTPSDConfig{
{
URL: "http://valid-url",
Copy link
Contributor

Choose a reason for hiding this comment

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

(nit) a good habit is to use reserved top-level domains for tests and documentation (the existing code base doesn't apply this recommendation though!).

Suggested change
URL: "http://valid-url",
URL: "http://valid.test",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm... maybe we can just log an issue for that, it would make a good first-issue IMO.

@mviswanathsai mviswanathsai force-pushed the sc-refactor--http-sd branch 2 times, most recently from 6d6a90c to 5e9a3c9 Compare August 29, 2024 16:30
@mviswanathsai
Copy link
Contributor Author

Can't quite understand the unit-tests failing.

=== RUN   TestSelectScrapeConfigs/HTTP_SD_config_with_valid_proxy_settings
time=2024-08-30T11:26:59.002+05:30 level=WARN msg="skipping scrapeconfig" error="puppetDBSDConfigs: puppetDB SD configuration is only sup
ported for Prometheus version >= 2.31.0" scrapeconfig=test/test namespace=test prometheus=test
    resource_selector_test.go:3848: 
                Error Trace:    /home/mviswanathsai/operator/pkg/prometheus/resource_selector_test.go:3848
                Error:          "map[]" should have 1 item(s), but has 0
                Test:           TestSelectScrapeConfigs/HTTP_SD_config_with_valid_proxy_settings
=== RUN   TestSelectScrapeConfigs/HTTP_SD_config_with_valid_secret_ref
time=2024-08-30T11:26:59.003+05:30 level=WARN msg="skipping scrapeconfig" error="puppetDBSDConfigs: puppetDB SD configuration is only sup
ported for Prometheus version >= 2.31.0" scrapeconfig=test/test namespace=test prometheus=test
    resource_selector_test.go:3848: 
                Error Trace:    /home/mviswanathsai/operator/pkg/prometheus/resource_selector_test.go:3848
                Error:          "map[]" should have 1 item(s), but has 0
                Test:           TestSelectScrapeConfigs/HTTP_SD_config_with_valid_secret_ref

@mviswanathsai
Copy link
Contributor Author

The test case seems right to me

		{
			scenario: "HTTP SD config with valid proxy settings",
			updateSpec: func(sc *monitoringv1alpha1.ScrapeConfigSpec) {
				sc.HTTPSDConfigs = []monitoringv1alpha1.HTTPSDConfig{
					{
						URL: "http://example.com",
						ProxyConfig: monitoringv1.ProxyConfig{
							ProxyURL:             ptr.To("http://no-proxy.com"),
							NoProxy:              ptr.To("0.0.0.0"),
							ProxyFromEnvironment: ptr.To(false),
							ProxyConnectHeader: map[string][]v1.SecretKeySelector{
								"header": {
									{
										LocalObjectReference: v1.LocalObjectReference{
											Name: "secret",
										},
										Key: "key1",
									},
								},
							},
						},
					},
				}
			},
			selected: true,
            promVersion: "2.29.0",
		},

Can't see why we get logs from validatePuppetDBSDConfigs in the error.

@mviswanathsai
Copy link
Contributor Author

At the resource_selector_test.go, we could also do something similar to what we did with the e2e tests for API validation and break up the large test in smaller subtests.

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.

Thanks!

@simonpasquier simonpasquier merged commit bc63606 into prometheus-operator:main Aug 30, 2024
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.

Refactor the HTTP service discovery configurations

3 participants