Add notification filtering by target media type
The Hub registry generates a large volume of notifications, many of which are uninteresting based on target media type. Discarding them within the notification endpoint consumes considerable resources that could be saved by discarding them within the registry. To that end, this change adds registry configuration options to restrict the notifications sent to an endpoint based on target media type. Signed-off-by: Noah Treuhaft <noah.treuhaft@docker.com>
This commit is contained in:
parent
cb744efe8b
commit
ad6bb66faf
7 changed files with 112 additions and 16 deletions
|
@ -3,6 +3,7 @@ package notifications
|
|||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -112,6 +113,38 @@ func TestEventQueue(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestIgnoredMediaTypesSink(t *testing.T) {
|
||||
blob := createTestEvent("push", "library/test", "blob")
|
||||
manifest := createTestEvent("push", "library/test", "manifest")
|
||||
|
||||
type testcase struct {
|
||||
ignored []string
|
||||
expected []Event
|
||||
}
|
||||
|
||||
cases := []testcase{
|
||||
{nil, []Event{blob, manifest}},
|
||||
{[]string{"other"}, []Event{blob, manifest}},
|
||||
{[]string{"blob"}, []Event{manifest}},
|
||||
{[]string{"blob", "manifest"}, nil},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
ts := &testSink{}
|
||||
s := newIgnoredMediaTypesSink(ts, c.ignored)
|
||||
|
||||
if err := s.Write(blob, manifest); err != nil {
|
||||
t.Fatalf("error writing event: %v", err)
|
||||
}
|
||||
|
||||
ts.mu.Lock()
|
||||
if !reflect.DeepEqual(ts.events, c.expected) {
|
||||
t.Fatalf("unexpected events: %#v != %#v", ts.events, c.expected)
|
||||
}
|
||||
ts.mu.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetryingSink(t *testing.T) {
|
||||
|
||||
// Make a sync that fails most of the time, ensuring that all the events
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue