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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user