-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[receiver/prometheus] syncTargetAllocator now detects regex changes in relabel config #32127
Changes from 62 commits
d1de8b3
35f4b63
d3b0ccd
f631611
11e35c0
0a886f4
9d9a83c
fe3b4f2
a2fa93e
f5e999d
424be70
fd262e9
fff66e3
f47c4ff
affec96
eebe192
a4080d8
f17fbd0
1483b3b
fc5687c
eb84345
b81f716
e144c70
a341238
9b3e031
2af9cbe
3a0079b
1b89f83
d341e4f
9a53706
c6741cd
9ae5028
ad9481f
45be98b
bd5d110
9e1f7ca
8c59017
7265d9d
566607c
e422260
14008da
c8a05b8
ac00f1e
ba06a4c
f6614c2
f91cbb9
c691c2b
e610046
72fecb5
9215009
11dbc8d
c24114d
07f7d29
80eb11f
83b4953
acf2014
61687b6
3c36028
f710b26
7bc97bb
c4b65e8
550b0cf
1ecbce7
31f7545
119a1ac
b852a93
0684887
998a7cc
639a2ad
5d8fe5d
df760b0
3037589
b95cc82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
change_type: 'bug_fix' | ||
component: 'prometheusreceiver' | ||
note: Fix hash computation to include non exported fields like regex in scrape configuration for TargetAllocator | ||
issues: [29313] | ||
subtext: | ||
change_logs: [] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
"github.com/prometheus/common/model" | ||
promconfig "github.com/prometheus/prometheus/config" | ||
promHTTP "github.com/prometheus/prometheus/discovery/http" | ||
"github.com/prometheus/prometheus/model/relabel" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component/componenttest" | ||
"go.opentelemetry.io/collector/consumer/consumertest" | ||
|
@@ -50,9 +51,15 @@ type hTTPSDResponse struct { | |
Labels map[model.LabelName]model.LabelValue `json:"labels"` | ||
} | ||
|
||
type expectedMetricRelabelConfigTestResult struct { | ||
JobName string | ||
MetricRelabelRegex relabel.Regexp | ||
} | ||
|
||
type expectedTestResultJobMap struct { | ||
Targets []string | ||
Labels model.LabelSet | ||
Targets []string | ||
Labels model.LabelSet | ||
MetricRelabelConfig *expectedMetricRelabelConfigTestResult | ||
} | ||
|
||
type expectedTestResult struct { | ||
|
@@ -481,6 +488,111 @@ func TestTargetAllocatorJobRetrieval(t *testing.T) { | |
jobMap: map[string]expectedTestResultJobMap{}, | ||
}, | ||
}, | ||
{ | ||
desc: "update metric relabel config regex", | ||
responses: Responses{ | ||
releaserMap: map[string]int{ | ||
"/scrape_configs": 1, | ||
}, | ||
responses: map[string][]mockTargetAllocatorResponseRaw{ | ||
"/scrape_configs": { | ||
mockTargetAllocatorResponseRaw{code: 200, data: map[string]map[string]any{ | ||
"job1": { | ||
"job_name": "job1", | ||
"scrape_interval": "30s", | ||
"scrape_timeout": "30s", | ||
"metrics_path": "/metrics", | ||
"scheme": "http", | ||
"metric_relabel_configs": []map[string]string{ | ||
{ | ||
"separator": ";", | ||
"regex": "regex1", | ||
"action": "keep", | ||
}, | ||
}, | ||
}, | ||
}}, | ||
mockTargetAllocatorResponseRaw{code: 200, data: map[string]map[string]any{ | ||
"job1": { | ||
"job_name": "job1", | ||
"scrape_interval": "30s", | ||
"scrape_timeout": "30s", | ||
"metrics_path": "/metrics", | ||
"scheme": "http", | ||
"metric_relabel_configs": []map[string]string{ | ||
{ | ||
"separator": ";", | ||
"regex": "regex2", | ||
"action": "keep", | ||
}, | ||
}, | ||
}, | ||
}}, | ||
}, | ||
"/jobs/job1/targets": { | ||
mockTargetAllocatorResponseRaw{code: 200, data: []hTTPSDResponse{ | ||
{Targets: []string{"localhost:9090"}, | ||
Labels: map[model.LabelName]model.LabelValue{ | ||
"__meta_datacenter": "london", | ||
"__meta_prometheus_job": "node", | ||
}}, | ||
}}, | ||
mockTargetAllocatorResponseRaw{code: 200, data: []hTTPSDResponse{ | ||
{Targets: []string{"localhost:9090"}, | ||
Labels: map[model.LabelName]model.LabelValue{ | ||
"__meta_datacenter": "london", | ||
"__meta_prometheus_job": "node", | ||
}}, | ||
}}, | ||
}, | ||
}, | ||
}, | ||
cfg: &Config{ | ||
PrometheusConfig: &PromConfig{ | ||
ScrapeConfigs: []*promconfig.ScrapeConfig{ | ||
{ | ||
JobName: "job1", | ||
HonorTimestamps: true, | ||
ScrapeInterval: model.Duration(30 * time.Second), | ||
ScrapeTimeout: model.Duration(30 * time.Second), | ||
MetricsPath: "/metrics", | ||
Scheme: "http", | ||
MetricRelabelConfigs: []*relabel.Config{ | ||
{ | ||
Separator: ";", | ||
Regex: relabel.MustNewRegexp("(.*)"), | ||
Action: relabel.Keep, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
TargetAllocator: &TargetAllocator{ | ||
Interval: 10 * time.Second, | ||
CollectorID: "collector-1", | ||
HTTPSDConfig: &PromHTTPSDConfig{ | ||
HTTPClientConfig: commonconfig.HTTPClientConfig{}, | ||
RefreshInterval: model.Duration(60 * time.Second), | ||
}, | ||
}, | ||
}, | ||
want: expectedTestResult{ | ||
empty: false, | ||
jobMap: map[string]expectedTestResultJobMap{ | ||
"job1": { | ||
Targets: []string{"localhost:9090"}, | ||
Labels: map[model.LabelName]model.LabelValue{ | ||
"__meta_datacenter": "london", | ||
"__meta_prometheus_job": "node", | ||
}, | ||
MetricRelabelConfig: &expectedMetricRelabelConfigTestResult{ | ||
JobName: "job1", | ||
MetricRelabelRegex: relabel.MustNewRegexp("regex2"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} { | ||
t.Run(tc.desc, func(t *testing.T) { | ||
ctx := context.Background() | ||
|
@@ -532,6 +644,17 @@ func TestTargetAllocatorJobRetrieval(t *testing.T) { | |
// which is identical to the source url | ||
s.Labels["__meta_url"] = model.LabelValue(sdConfig.URL) | ||
require.Equal(t, s.Labels, group.Labels) | ||
if s.MetricRelabelConfig != nil { | ||
// Adding wait here so that the latest scrape config is applied with the updated regex | ||
time.Sleep(5 * time.Second) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we do need to wait here, could we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @swiatekm - This is not needed. Removed it. |
||
for _, sc := range receiver.cfg.PrometheusConfig.ScrapeConfigs { | ||
if sc.JobName == s.MetricRelabelConfig.JobName { | ||
for _, mc := range sc.MetricRelabelConfigs { | ||
require.Equal(t, s.MetricRelabelConfig.MetricRelabelRegex, mc.Regex) | ||
} | ||
} | ||
} | ||
} | ||
found = true | ||
} | ||
require.True(t, found, "Returned job is not defined in expected values", group) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add some simple unit tests for this function? There was concern about map iteration order inconsistency, so we should at least check if this function ran on two copies of the same config gives the same result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @swiatekm. Added one. Please take a look.