mirror of
https://github.com/distribution/distribution.git
synced 2025-09-06 09:20:45 +00:00
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:
@@ -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
|
||||
|
Reference in New Issue
Block a user