Skip to content

Commit f92423b

Browse files
tinou98krajoramaArthurSens
authored andcommitted
[receiver/prometheus] Add fallback_scrape_protocol when using target allocator (open-telemetry#39672)
This applies a similar fix as 72b834b, when using TargetAllocator. #### Description For the same reason as we already add a `fallback_scrape_protocol` to the config, this PR add the same behavior when using the Target Allocator. It's important for me, as even the `fallbackScrapeProtocol` from the Prometheus CRD is ignored (I guess it's because the allocator advertise itself as version 2.55.1, which does not support (nor require) `fallback_scrape_protocol`). Maybe it's a change that should be done on the target-allocator side, but I kind of like the symmetry with what we're already doing with provided configuration. #### Link to tracking issue Same issue as open-telemetry#37902, but when using a target allocator --------- Signed-off-by: MATILLAT Quentin <[email protected]> Co-authored-by: George Krajcsovits <[email protected]> Co-authored-by: Arthur Silva Sens <[email protected]>
1 parent 5967fb2 commit f92423b

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed

.chloggen/prom-scrape-config-ta.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: prometheusreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add 'fallback_scrape_protocol' to entries obtained through Target Allocator, unless already defined.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [39672]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: This applies the same configuration change that is already applied on static configuration.
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

receiver/prometheusreceiver/targetallocator/manager.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ func (m *Manager) sync(compareHash uint64, httpClient *http.Client) (uint64, err
150150
scrapeConfig.HTTPClientConfig = commonconfig.HTTPClientConfig(*m.cfg.HTTPScrapeConfig)
151151
}
152152

153+
if scrapeConfig.ScrapeFallbackProtocol == "" {
154+
scrapeConfig.ScrapeFallbackProtocol = promconfig.PrometheusText0_0_4
155+
}
156+
153157
m.promCfg.ScrapeConfigs = append(m.promCfg.ScrapeConfigs, scrapeConfig)
154158
}
155159

receiver/prometheusreceiver/targetallocator/manager_test.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ type expectedMetricRelabelConfigTestResult struct {
6767
}
6868

6969
type expectedTestResultJobMap struct {
70-
Targets []string
71-
Labels model.LabelSet
72-
MetricRelabelConfig *expectedMetricRelabelConfigTestResult
70+
Targets []string
71+
Labels model.LabelSet
72+
MetricRelabelConfig *expectedMetricRelabelConfigTestResult
73+
ScrapeFallbackProtocol promconfig.ScrapeProtocol
7374
}
7475

7576
type expectedTestResult struct {
@@ -284,14 +285,15 @@ func TestTargetAllocatorJobRetrieval(t *testing.T) {
284285
"/scrape_configs": {
285286
mockTargetAllocatorResponseRaw{code: 200, data: map[string]map[string]any{
286287
"job1": {
287-
"job_name": "job1",
288-
"scrape_interval": "30s",
289-
"scrape_timeout": "30s",
290-
"scrape_protocols": []string{"OpenMetricsText1.0.0", "OpenMetricsText0.0.1", "PrometheusText0.0.4"},
291-
"metrics_path": "/metrics",
292-
"scheme": "http",
293-
"relabel_configs": nil,
294-
"metric_relabel_configs": nil,
288+
"job_name": "job1",
289+
"scrape_interval": "30s",
290+
"scrape_timeout": "30s",
291+
"scrape_protocols": []string{"OpenMetricsText1.0.0", "OpenMetricsText0.0.1", "PrometheusText0.0.4"},
292+
"metrics_path": "/metrics",
293+
"scheme": "http",
294+
"relabel_configs": nil,
295+
"metric_relabel_configs": nil,
296+
"fallback_scrape_protocol": promconfig.PrometheusText1_0_0,
295297
},
296298
"job2": {
297299
"job_name": "job2",
@@ -369,13 +371,15 @@ func TestTargetAllocatorJobRetrieval(t *testing.T) {
369371
"__meta_datacenter": "london",
370372
"__meta_prometheus_job": "node",
371373
},
374+
ScrapeFallbackProtocol: promconfig.PrometheusText1_0_0,
372375
},
373376
"job2": {
374377
Targets: []string{"10.0.40.2:9100", "10.0.40.3:9100"},
375378
Labels: map[model.LabelName]model.LabelValue{
376379
"__meta_datacenter": "london",
377380
"__meta_prometheus_job": "alertmanager",
378381
},
382+
ScrapeFallbackProtocol: promconfig.PrometheusText0_0_4, // Tests default value
379383
},
380384
},
381385
},
@@ -778,6 +782,15 @@ func TestTargetAllocatorJobRetrieval(t *testing.T) {
778782
}
779783
}
780784
}
785+
786+
if s.ScrapeFallbackProtocol != "" {
787+
for _, sc := range manager.promCfg.ScrapeConfigs {
788+
if sc.JobName == job {
789+
require.Equal(t, sc.ScrapeFallbackProtocol, s.ScrapeFallbackProtocol)
790+
}
791+
}
792+
}
793+
781794
found = true
782795
}
783796
require.True(t, found, "Returned job is not defined in expected values", group)

0 commit comments

Comments
 (0)