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

[target-allocator] Hashing in ScrapeConfigsHandler results in false negative #1358

Closed
kristinapathak opened this issue Jan 10, 2023 · 0 comments · Fixed by #2171
Closed

[target-allocator] Hashing in ScrapeConfigsHandler results in false negative #1358

kristinapathak opened this issue Jan 10, 2023 · 0 comments · Fixed by #2171
Labels
area:target-allocator Issues for target-allocator

Comments

@kristinapathak
Copy link
Contributor

When adding unit tests, I found that the hashing algorithm in ScrapeConfigsHandler() for the target allocator results in the same hash if the only thing that has changed is a regex value. The regex struct used in prometheus has no exported fields, so the hashing algorithm creates the same hash for both scrape configs. This results in a false negative, and the old object returned in the http response.

Unit test:

// description: "different regex",

previous scrape configs:

map[string]*promconfig.ScrapeConfig{
	"serviceMonitor/testapp/testapp/1": {
		JobName:         "serviceMonitor/testapp/testapp/1",
		HonorTimestamps: false,
		ScrapeTimeout:   model.Duration(30 * time.Second),
		MetricsPath:     "/metrics",
		Scheme:          "http",
		HTTPClientConfig: config.HTTPClientConfig{
			FollowRedirects: true,
		},
		RelabelConfigs: []*relabel.Config{
			{
				SourceLabels: model.LabelNames{model.LabelName("job")},
				Separator:    ";",
				Regex:        relabel.MustNewRegexp("(.*)"),
				TargetLabel:  "__tmp_prometheus_job_name",
				Replacement:  "$$1",
				Action:       relabel.Replace,
			},
		},
	},
}

new scrape configs:

map[string]*promconfig.ScrapeConfig{
	"serviceMonitor/testapp/testapp/1": {
		JobName:         "serviceMonitor/testapp/testapp/1",
		HonorTimestamps: false,
		ScrapeTimeout:   model.Duration(30 * time.Second),
		MetricsPath:     "/metrics",
		Scheme:          "http",
		HTTPClientConfig: config.HTTPClientConfig{
			FollowRedirects: true,
		},
		RelabelConfigs: []*relabel.Config{
			{
				SourceLabels: model.LabelNames{model.LabelName("job")},
				Separator:    ";",
				Regex:        relabel.MustNewRegexp("something else"),
				TargetLabel:  "__tmp_prometheus_job_name",
				Replacement:  "$$1",
				Action:       relabel.Replace,
			},
		},
	},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:target-allocator Issues for target-allocator
Projects
None yet
2 participants