Alerting: use hash of labels instead of labels string as the alert state cache key (#88956)

* Alerting: use hash instead of labels as the cache key
* Use data.Labels.Fingerprint to calculate the cache key
This commit is contained in:
Alexander Akhmetov
2024-06-11 18:34:58 +02:00
committed by GitHub
parent d004f8a98d
commit 667fea6623
11 changed files with 72 additions and 81 deletions
@@ -4,6 +4,7 @@ import (
"fmt"
"testing"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/stretchr/testify/require"
)
@@ -39,6 +40,19 @@ func TestTupleLabelsToLabels(t *testing.T) {
})
}
func TestInstanceLabelsFingerprint(t *testing.T) {
t.Run("returns labels fingerprint", func(t *testing.T) {
labels := InstanceLabels{
"foo": "bar",
"baz": "qux",
}
fingerprint := labels.Fingerprint()
expectedFingerprint := data.Labels(labels).Fingerprint()
require.Equal(t, expectedFingerprint, fingerprint)
})
}
func BenchmarkTupleLabelsToLabels(b *testing.B) {
b.Run("10 labels", func(b *testing.B) {
in := make(tupleLabels, 0, 10)