Skip to content

Commit ff47bc4

Browse files
committed
test(target-allocator): guard scrape_protocols defaulting on config load
Add a regression test asserting that loading a Target Allocator config whose static scrape job omits scrape_protocols still yields a non-empty ScrapeProtocols on every loaded scrape config. This is defaulted by the pinned Prometheus library during yaml.UnmarshalStrict into the prometheus Config type, so the distributed /scrape_configs payload is never empty and the agent's prometheus-receiver validation passes. The test fails fast if a future dependency or load-path change drops this defaulting.
1 parent 1376451 commit ff47bc4

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package config
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
// TestScrapeProtocolsDefaultedOnLoad guards against "scrape_protocols cannot be empty" regression.
14+
func TestScrapeProtocolsDefaultedOnLoad(t *testing.T) {
15+
got := CreateDefaultConfig()
16+
err := LoadFromFile("./testdata/scrape_protocols_omitted_test.yaml", &got)
17+
require.NoError(t, err)
18+
19+
require.NotNil(t, got.PromConfig)
20+
require.NotEmpty(t, got.PromConfig.ScrapeConfigs)
21+
22+
for _, sc := range got.PromConfig.ScrapeConfigs {
23+
assert.NotEmpty(t, sc.ScrapeProtocols,
24+
"scrape_protocols must be defaulted for job %q", sc.JobName)
25+
}
26+
27+
// Spot-check the specific static job from the reproduction by name.
28+
found := false
29+
for _, sc := range got.PromConfig.ScrapeConfigs {
30+
if sc.JobName == "prometheus-sample-app" {
31+
found = true
32+
assert.Greater(t, len(sc.ScrapeProtocols), 0)
33+
}
34+
}
35+
require.True(t, found, "expected the 'prometheus-sample-app' job to be present")
36+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Regression fixture for "scrape_protocols cannot be empty".
2+
# A static scrape job that deliberately OMITS scrape_protocols, mirroring the
3+
# quip-doc "prometheus-sample-app" Test 5 job. Loading this through the TA config
4+
# path must default scrape_protocols onto every scrape config (Prometheus
5+
# v0.311.3 ScrapeConfig.UnmarshalYAML), so the distributed config is never empty
6+
# and the agent's prometheus-receiver validation passes.
7+
config:
8+
scrape_configs:
9+
- job_name: prometheus-sample-app
10+
kubernetes_sd_configs:
11+
- role: pod
12+
relabel_configs:
13+
- source_labels: [__meta_kubernetes_pod_label_app]
14+
regex: prometheus-sample-app
15+
action: keep
16+
- target_label: label1
17+
replacement: value1

0 commit comments

Comments
 (0)