A source is keyed by a uuid, owned by the organisation or one person, and labelled within that scope. The webhook path is a separate unique column, so renaming either leaves stored events, event types, triggers, groups, mappings and drafts alone. Delivery policies, sealed secrets and group keys use the id.
36 lines
1.5 KiB
Go
36 lines
1.5 KiB
Go
package events
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/samcharles93/archie-core/modules/connectors"
|
|
"github.com/samcharles93/archie-core/modules/events/internal/store"
|
|
)
|
|
|
|
// TestNewRowGrouping guards two rules: an echo of Archie's own delivery never
|
|
// carries a group key, so it can't become a proposal, and events differing
|
|
// only outside the key fields share one key.
|
|
func TestNewRowGrouping(t *testing.T) {
|
|
src := store.Source{ID: hookID, KeyFields: []byte(`["alertname","labels"]`)}
|
|
run := uuid.New()
|
|
ev := func(fields string) connectors.Event {
|
|
return connectors.Event{Type: "alert.firing", SourceEventID: fields, Fields: []byte(fields)}
|
|
}
|
|
disk := newRow("o", src, ev(`{"alertname":"DiskPressure","labels":{"host":"a"},"value":91}`), nil, false, uuid.Nil)
|
|
again := newRow("o", src, ev(`{"alertname":"DiskPressure","labels":{"host":"a"},"value":97}`), nil, false, uuid.Nil)
|
|
other := newRow("o", src, ev(`{"alertname":"DiskPressure","labels":{"host":"b"}}`), nil, false, uuid.Nil)
|
|
own := newRow("o", src, ev(`{"alertname":"DiskPressure","labels":{"host":"a"}}`), nil, true, run)
|
|
|
|
if !disk.GroupKey.Valid || disk.GroupKey != again.GroupKey {
|
|
t.Errorf("same key fields gave different keys: %q, %q", disk.GroupKey.String, again.GroupKey.String)
|
|
}
|
|
if disk.GroupKey == other.GroupKey {
|
|
t.Error("different labels shared a key")
|
|
}
|
|
if own.GroupKey.Valid || own.GroupFilter != nil || !own.Own || own.OriginRunID.UUID != run {
|
|
t.Errorf("own delivery was keyed or not linked to its run: %+v", own)
|
|
}
|
|
}
|