Skip to content

Commit

Permalink
Add a basic integration test + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stevesg committed Dec 3, 2024
1 parent 3bcf275 commit ce8df12
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ type Enrichment struct {

var (
DefaultEnrichment = Enrichment{
Timeout: 15 * time.Second,
HTTPConfig: &commoncfg.DefaultHTTPClientConfig,
Timeout: 15 * time.Second,
}
)

Expand Down
6 changes: 5 additions & 1 deletion enrichment/enrichment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/url"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
Expand Down Expand Up @@ -91,7 +92,10 @@ func NewEnrichment(conf config.Enrichment) (*Enrichment, error) {

func (e *Enrichment) Apply(ctx context.Context, l log.Logger, alerts ...*types.Alert) error {
// TODO: Template isn't needed by this function but we need to pass something.
data := notify.GetTemplateData(ctx, &template.Template{}, alerts, l)
t := &template.Template{
ExternalURL: &url.URL{},
}
data := notify.GetTemplateData(ctx, t, alerts, l)

var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(data); err != nil {
Expand Down
47 changes: 47 additions & 0 deletions test/with_api_v2/acceptance/send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,3 +464,50 @@ receivers:

t.Log(co.Check())
}

func TestEnrichment(t *testing.T) {
t.Parallel()

conf := `
route:
receiver: "default"
group_by: [alertname]
group_wait: 1s
group_interval: 2s
repeat_interval: 3s
enrichments:
- url: 'http://localhost:9099'
receivers:
- name: "default"
webhook_configs:
- url: 'http://%s'
- url: 'http://%s'
`

at := NewAcceptanceTest(t, &AcceptanceOpts{
Tolerance: 150 * time.Millisecond,
})

co1 := at.Collector("webhook1")
wh1 := NewWebhook(t, co1)

co2 := at.Collector("webhook2")
wh2 := NewWebhook(t, co2)

am := at.AlertmanagerCluster(fmt.Sprintf(conf, wh1.Address(), wh2.Address()), 1)

am.Push(At(1), Alert("alertname", "test1"))

co1.Want(Between(2, 2.5), Alert("alertname", "test1").Active(1))
co1.Want(Between(6, 6.5), Alert("alertname", "test1").Active(1))

co2.Want(Between(2, 2.5), Alert("alertname", "test1").Active(1))
co2.Want(Between(6, 6.5), Alert("alertname", "test1").Active(1))

at.Run()

for _, c := range []*Collector{co1, co2} {
t.Log(c.Check())
}
}

0 comments on commit ce8df12

Please sign in to comment.