Skip to content

Commit

Permalink
Add testcase to check for missing labels from the generated metrics (#…
Browse files Browse the repository at this point in the history
…116)

* Fixes the missing label issue

Signed-off-by: Prateek <prateek@bluekanvas.com>

* Fixes the missing label issue

Signed-off-by: Prateek <prateek@bluekanvas.com>

* Updates the test to tap into the ch

Signed-off-by: Prateek <prateek@bluekanvas.com>

* Fixes formating issues in the serve_test.gp

Signed-off-by: Prateek <prateek@bluekanvas.com>

* Remove the accidental merge conflict

Signed-off-by: Prateek <prateek@bluekanvas.com>

---------

Signed-off-by: Prateek <prateek@bluekanvas.com>
Co-authored-by: Prateek <prateek@bluekanvas.com>
  • Loading branch information
prateeknayak and Prateek authored Jan 16, 2025
1 parent 5bc6482 commit ad973cf
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions metrics/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,53 @@ func TestRunMetricsSpikeChange(t *testing.T) {
}
}
}

func TestCollectorLabels(t *testing.T) {
testCfg := Config{
GaugeMetricCount: 1,
LabelCount: 2,
SeriesCount: 100,
MaxSeriesCount: 30,
MinSeriesCount: 10,
SpikeMultiplier: 1.5,
MetricLength: 1,
LabelLength: 1,
SeriesOperationMode: spikeOpMode,
ConstLabels: []string{"constLabel=test"},
}

assert.NoError(t, testCfg.Validate())

reg := prometheus.NewRegistry()
col := NewCollector(testCfg)
reg.MustRegister(col)

go col.Run()
t.Cleanup(func() {
col.Stop(nil)
})

select {
case <-col.updateNotifyCh:
metricsFamilies, err := reg.Gather()
assert.NotEmpty(t, metricsFamilies)
assert.NoError(t, err)

for _, mf := range metricsFamilies {
for _, m := range mf.Metric {
labels := m.GetLabel()
labelMap := make(map[string]string)
for _, l := range labels {
labelMap[l.GetName()] = l.GetValue()
}
assert.Equal(t, "test", labelMap["constLabel"])
assert.Contains(t, labelMap, "label_key_k_0")
assert.Contains(t, labelMap, "label_key_k_1")
assert.Contains(t, labelMap, "series_id")
assert.Contains(t, labelMap, "cycle_id")
}
}
case <-time.After(2 * time.Second):
t.Fail()
}
}

0 comments on commit ad973cf

Please sign in to comment.