mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
fix: fix inputs and output tests for OM
Signed-off-by: Manik Rana <manikrana54@gmail.com>
This commit is contained in:
parent
8f088845d1
commit
808d920415
|
@ -730,7 +730,7 @@ func TestManagerCTZeroIngestion(t *testing.T) {
|
||||||
counterSampleProto *dto.Counter
|
counterSampleProto *dto.Counter
|
||||||
counterSampleText string
|
counterSampleText string
|
||||||
enableCTZeroIngestion bool
|
enableCTZeroIngestion bool
|
||||||
exp exp
|
exp []exp
|
||||||
typ string
|
typ string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -763,39 +763,45 @@ func TestManagerCTZeroIngestion(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "OMText disabled with CT on counter",
|
name: "OMText disabled with CT on counter",
|
||||||
counterSampleText: `# TYPE expected_counter counter
|
counterSampleText: `# TYPE expected_counter counter
|
||||||
expected_counter 17.0 1520879607.789
|
expected_counter 17.0 1520879607.789
|
||||||
expected_counter_created 1000
|
expected_counter_created 1000
|
||||||
# EOF`,
|
# EOF`,
|
||||||
exp: exp{
|
exp: []exp{{
|
||||||
value: 17.0,
|
value: 17.0,
|
||||||
ts: 1520879607789,
|
ts: 1520879607789,
|
||||||
},
|
}},
|
||||||
typ: "application/openmetrics-text; version=1.0.0",
|
typ: "application/openmetrics-text; version=1.0.0; charset=utf-8",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "OMText enabled with CT on counter",
|
name: "OMText enabled with CT on counter",
|
||||||
counterSampleText: `# TYPE expected_counter counter
|
counterSampleText: `# TYPE expected_counter counter
|
||||||
expected_counter 17.0 1520879607.789
|
expected_counter 17.0 1520879607.789
|
||||||
expected_counter_created 1000
|
expected_counter_created 1000
|
||||||
# EOF`,
|
# EOF`,
|
||||||
enableCTZeroIngestion: true,
|
enableCTZeroIngestion: true,
|
||||||
exp: exp{
|
exp: []exp{
|
||||||
|
{
|
||||||
value: 0.0,
|
value: 0.0,
|
||||||
ts: 1000,
|
ts: 1000,
|
||||||
},
|
},
|
||||||
typ: "application/openmetrics-text; version=1.0.0",
|
{
|
||||||
|
value: 17.0,
|
||||||
|
ts: 1520879607789,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
typ: "application/openmetrics-text; version=1.0.0; charset=utf-8",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "OMText enabled without CT on counter",
|
name: "OMText enabled without CT on counter",
|
||||||
counterSampleText: `# TYPE expected_counter counter
|
counterSampleText: `# TYPE expected_counter counter
|
||||||
expected_counter 17.0 1520879607.789
|
expected_counter 17.0 1520879607.789
|
||||||
# EOF`,
|
# EOF`,
|
||||||
enableCTZeroIngestion: true,
|
enableCTZeroIngestion: true,
|
||||||
exp: exp{
|
exp: []exp{{
|
||||||
value: 17.0,
|
value: 17.0,
|
||||||
ts: 1520879607789,
|
ts: 1520879607789,
|
||||||
},
|
}},
|
||||||
typ: "application/openmetrics-text; version=1.0.0",
|
typ: "application/openmetrics-text; version=1.0.0; charset=utf-8",
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
@ -816,9 +822,7 @@ func TestManagerCTZeroIngestion(t *testing.T) {
|
||||||
// Disable regular scrapes.
|
// Disable regular scrapes.
|
||||||
ScrapeInterval: model.Duration(9999 * time.Minute),
|
ScrapeInterval: model.Duration(9999 * time.Minute),
|
||||||
ScrapeTimeout: model.Duration(5 * time.Second),
|
ScrapeTimeout: model.Duration(5 * time.Second),
|
||||||
// Ensure the proto is chosen. We need proto as it's the only protocol
|
ScrapeProtocols: []config.ScrapeProtocol{config.OpenMetricsText1_0_0, config.PrometheusProto},
|
||||||
// with the CT parsing support.
|
|
||||||
ScrapeProtocols: []config.ScrapeProtocol{config.PrometheusProto, config.OpenMetricsText1_0_0},
|
|
||||||
},
|
},
|
||||||
ScrapeConfigs: []*config.ScrapeConfig{{JobName: "test"}},
|
ScrapeConfigs: []*config.ScrapeConfig{{JobName: "test"}},
|
||||||
}))
|
}))
|
||||||
|
@ -835,7 +839,7 @@ func TestManagerCTZeroIngestion(t *testing.T) {
|
||||||
Type: &ctrType,
|
Type: &ctrType,
|
||||||
Metric: []*dto.Metric{{Counter: tc.counterSampleProto}},
|
Metric: []*dto.Metric{{Counter: tc.counterSampleProto}},
|
||||||
})
|
})
|
||||||
case "application/openmetrics-text; version=1.0.0":
|
case "application/openmetrics-text; version=1.0.0; charset=utf-8":
|
||||||
toWrite = []byte(tc.counterSampleText)
|
toWrite = []byte(tc.counterSampleText)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -910,17 +914,18 @@ func TestManagerCTZeroIngestion(t *testing.T) {
|
||||||
require.Len(t, got, 1)
|
require.Len(t, got, 1)
|
||||||
require.Equal(t, tc.counterSampleProto.GetValue(), got[0])
|
require.Equal(t, tc.counterSampleProto.GetValue(), got[0])
|
||||||
|
|
||||||
case "application/openmetrics-text; version=1.0.0":
|
case "application/openmetrics-text; version=1.0.0; charset=utf-8":
|
||||||
if tc.enableCTZeroIngestion && tc.exp.ts == 0 {
|
if tc.enableCTZeroIngestion {
|
||||||
require.Len(t, got, 2)
|
require.Len(t, got, len(tc.exp))
|
||||||
require.Equal(t, 0.0, got[0])
|
for i, e := range tc.exp {
|
||||||
require.Equal(t, tc.exp.value, got[1])
|
require.Equal(t, e.value, got[i])
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expect only one, valid sample.
|
// Expect only one, valid sample.
|
||||||
require.Len(t, got, 1)
|
require.Len(t, got, 1)
|
||||||
require.Equal(t, tc.exp.value, got[0])
|
require.Equal(t, tc.exp[0].value, got[0])
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue