-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically prune metrics from the /metrics output of the promtail …
…metrics pipeline stage after an idle period. Signed-off-by: Edward Welch <edward.welch@grafana.com>
- Loading branch information
Showing
10 changed files
with
340 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package metric | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/prometheus/common/model" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGaugeExpiration(t *testing.T) { | ||
t.Parallel() | ||
cfg := GaugeConfig{ | ||
Action: "inc", | ||
} | ||
|
||
gag, err := NewGauges("test1", "HELP ME!!!!!", cfg, 1) | ||
assert.Nil(t, err) | ||
|
||
// Create a label and increment the gauge | ||
lbl1 := model.LabelSet{} | ||
lbl1["test"] = "app" | ||
gag.With(lbl1).Inc() | ||
|
||
// Collect the metrics, should still find the metric in the map | ||
collect(gag) | ||
assert.Contains(t, gag.metrics, lbl1.Fingerprint()) | ||
|
||
time.Sleep(1100 * time.Millisecond) // Wait just past our max idle of 1 sec | ||
|
||
//Add another gauge with new label val | ||
lbl2 := model.LabelSet{} | ||
lbl2["test"] = "app2" | ||
gag.With(lbl2).Inc() | ||
|
||
// Collect the metrics, first gauge should have expired and removed, second should still be present | ||
collect(gag) | ||
assert.NotContains(t, gag.metrics, lbl1.Fingerprint()) | ||
assert.Contains(t, gag.metrics, lbl2.Fingerprint()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package metric | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/prometheus/common/model" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestHistogramExpiration(t *testing.T) { | ||
t.Parallel() | ||
cfg := HistogramConfig{} | ||
|
||
hist, err := NewHistograms("test1", "HELP ME!!!!!", cfg, 1) | ||
assert.Nil(t, err) | ||
|
||
// Create a label and increment the histogram | ||
lbl1 := model.LabelSet{} | ||
lbl1["test"] = "app" | ||
hist.With(lbl1).Observe(23) | ||
|
||
// Collect the metrics, should still find the metric in the map | ||
collect(hist) | ||
assert.Contains(t, hist.metrics, lbl1.Fingerprint()) | ||
|
||
time.Sleep(1100 * time.Millisecond) // Wait just past our max idle of 1 sec | ||
|
||
//Add another histogram with new label val | ||
lbl2 := model.LabelSet{} | ||
lbl2["test"] = "app2" | ||
hist.With(lbl2).Observe(2) | ||
|
||
// Collect the metrics, first histogram should have expired and removed, second should still be present | ||
collect(hist) | ||
assert.NotContains(t, hist.metrics, lbl1.Fingerprint()) | ||
assert.Contains(t, hist.metrics, lbl2.Fingerprint()) | ||
} |
Oops, something went wrong.