Notifications: webhooks for a parked model, a lost node, a spent budget and new weights; Alertmanager receiver templates
notify.webhooks sends signed JSON or Slack-compatible messages, queued, retried, de-duplicated hourly; ctl notify test checks each webhook. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
646ff996c7
commit
1b71c38f89
24 files changed
+907
-4
No files matched your search
@@ -0,0 +1,41 @@
|
||||
// Package notifytest catches notifications in tests.
|
||||
package notifytest
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/notify"
|
||||
)
|
||||
|
||||
// Catch returns a notifier whose webhook records what it is sent, and a func
|
||||
// that waits for the sending and returns the events. The notifier takes no
|
||||
// more events once that func is called.
|
||||
func Catch(t *testing.T) (*notify.Notifier, func() []notify.Event) {
|
||||
t.Helper()
|
||||
var mu sync.Mutex
|
||||
var got []notify.Event
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
b, _ := io.ReadAll(req.Body)
|
||||
var e notify.Event
|
||||
_ = json.Unmarshal(b, &e)
|
||||
mu.Lock()
|
||||
got = append(got, e)
|
||||
mu.Unlock()
|
||||
}))
|
||||
t.Cleanup(srv.Close)
|
||||
n, err := notify.New(t.Context(), notify.Config{Webhooks: []notify.Webhook{{URL: srv.URL}}}, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return n, func() []notify.Event {
|
||||
n.Wait()
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
return got
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user