Path: blob/main/component/loki/process/internal/metric/histograms_test.go
4096 views
package metric12import (3"testing"4"time"56"github.com/prometheus/common/model"7"github.com/stretchr/testify/assert"8)910func TestHistogramExpiration(t *testing.T) {11t.Parallel()12cfg := &HistogramConfig{13Description: "HELP ME!!!!!",14MaxIdle: 1 * time.Second,15}1617hist, err := NewHistograms("test1", cfg)18assert.Nil(t, err)1920// Create a label and increment the histogram21lbl1 := model.LabelSet{}22lbl1["test"] = "app"23hist.With(lbl1).Observe(23)2425// Collect the metrics, should still find the metric in the map26collect(hist)27assert.Contains(t, hist.metrics, lbl1.Fingerprint())2829time.Sleep(1100 * time.Millisecond) // Wait just past our max idle of 1 sec3031//Add another histogram with new label val32lbl2 := model.LabelSet{}33lbl2["test"] = "app2"34hist.With(lbl2).Observe(2)3536// Collect the metrics, first histogram should have expired and removed, second should still be present37collect(hist)38assert.NotContains(t, hist.metrics, lbl1.Fingerprint())39assert.Contains(t, hist.metrics, lbl2.Fingerprint())40}414243