Skip to content

Commit 287fe85

Browse files
carsonipmergify[bot]
authored andcommitted
test: Fix TestStorageMonitoring to assert properly (#21384)
* test: Fix TestStorageMonitoring to assert properly * Improve require (cherry picked from commit bf99daa)
1 parent 857888a commit 287fe85

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

x-pack/apm-server/sampling/processor_test.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ func TestGroupsMonitoring(t *testing.T) {
642642
//
643643
// It is helpful to provide multiple names for synchronous metrics to avoid losing data when collecting.
644644
// Observable metrics report everytime Collect is called, so there will be no data loss.
645-
func getGaugeValues(t testing.TB, reader sdkmetric.Reader, names ...string) []float64 {
645+
func getGaugeValues(t assert.TestingT, reader sdkmetric.Reader, names ...string) []float64 {
646646
var rm metricdata.ResourceMetrics
647647
assert.NoError(t, reader.Collect(context.Background(), &rm))
648648

@@ -690,17 +690,11 @@ func TestStorageMonitoring(t *testing.T) {
690690
Sampled: true,
691691
},
692692
}}
693-
err := processor.ProcessBatch(context.Background(), &batch)
693+
err := processor.ProcessBatch(t.Context(), &batch)
694694
require.NoError(t, err)
695695
assert.Empty(t, batch)
696696
}
697697

698-
// Wait for cached db size update
699-
require.EventuallyWithT(t, func(c *assert.CollectT) {
700-
lsm, _ := config.DB.Size()
701-
assert.Greater(c, lsm, int64(0))
702-
}, 2*time.Second, 20*time.Millisecond)
703-
704698
metricsNames := []string{
705699
"apm-server.sampling.tail.storage.lsm_size",
706700
"apm-server.sampling.tail.storage.value_log_size",
@@ -709,14 +703,24 @@ func TestStorageMonitoring(t *testing.T) {
709703
"apm-server.sampling.tail.storage.disk_total",
710704
"apm-server.sampling.tail.storage.disk_usage_threshold_pct",
711705
}
712-
gaugeValues := getGaugeValues(t, tempdirConfig.metricReader, metricsNames...)
713-
assert.Len(t, gaugeValues, 6)
706+
assert.EventuallyWithT(t, func(c *assert.CollectT) {
707+
gaugeValues := getGaugeValues(c, tempdirConfig.metricReader, metricsNames...)
708+
require.Len(c, gaugeValues, len(metricsNames))
709+
710+
lsmSize := gaugeValues[0]
711+
assert.Greater(c, lsmSize, float64(2000), "lsm_size")
712+
713+
vlogSize := gaugeValues[1]
714+
assert.Zero(c, vlogSize, "value_log_size")
714715

715-
lsmSize := gaugeValues[0]
716-
assert.NotZero(t, lsmSize)
716+
assert.Zero(c, gaugeValues[2], "storage_limit")
717+
assert.NotZero(c, gaugeValues[3], "disk_used")
718+
assert.NotZero(c, gaugeValues[4], "disk_total")
717719

718-
vlogSize := gaugeValues[1]
719-
assert.Zero(t, vlogSize)
720+
// TODO: known issue: disk_usage_threshold_pct not reported
721+
// See https://github.com/elastic/apm-server/issues/20996
722+
assert.Zero(c, gaugeValues[5], "disk_usage_threshold_pct")
723+
}, 2*time.Second, 50*time.Millisecond)
720724
}
721725

722726
func TestStorageLimit(t *testing.T) {

0 commit comments

Comments
 (0)