-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added ignore event types into notifications #2501
Conversation
Please sign your commits following these rules: $ git clone -b "master" [email protected]:xiaonancc77/distribution.git somewhere
$ cd somewhere
$ git commit --amend -s --no-edit
$ git push -f Amending updates the existing PR. You DO NOT need to open a new one. |
Codecov Report
@@ Coverage Diff @@
## master #2501 +/- ##
=========================================
- Coverage 60.83% 51.2% -9.64%
=========================================
Files 129 129
Lines 11864 11830 -34
=========================================
- Hits 7218 6057 -1161
- Misses 3743 5012 +1269
+ Partials 903 761 -142
Continue to review full report at Codecov.
|
configuration/configuration.go
Outdated
@@ -551,6 +551,7 @@ type Endpoint struct { | |||
Timeout time.Duration `yaml:"timeout"` // HTTP timeout | |||
Threshold int `yaml:"threshold"` // circuit breaker threshold before backing off on failure | |||
Backoff time.Duration `yaml:"backoff"` // backoff duration | |||
IgnoreEventTypes []string `yaml:"ignoreEventTypes"` // ignore event types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use camelcase here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'll modify it.
Rather than piling on another field, it would better if this was properly structured:
It needs to be made clear that if it matches any of the mediatypes or actions, that it won't be propagated. This would deprecate Other than that, this seems like a reasonable feature. |
Thancks@stevvooe , this is a good idea, I will update the commit and submit it later. |
41cfa83
to
78fef0a
Compare
1e5d5d1
to
9f6c42f
Compare
@stevvooe I don't how to solve this problem. |
@stevvooe Hope to get your help, Thanks so much. |
@xiaonancc77 Don't worry about the diffs: we deal with this in Go to have consistent formatting. |
configuration/configuration.go
Outdated
Timeout time.Duration `yaml:"timeout"` // HTTP timeout | ||
Threshold int `yaml:"threshold"` // circuit breaker threshold before backing off on failure | ||
Backoff time.Duration `yaml:"backoff"` // backoff duration | ||
IgnoredMediaTypes []string `yaml:"ignoredmediatypes"` // target media types to ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to preserve this field to maintain backwards compatibility. Just enforce that one or the other needs to be used and not both.
configuration/configuration.go
Outdated
} | ||
|
||
//Ignore configures mediaTypes and actions of the event, that it won't be propagated | ||
type Ignore struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
notifications/endpoint.go
Outdated
"net/http" | ||
"time" | ||
) | ||
|
||
// EndpointConfig covers the optional configuration parameters for an active | ||
// endpoint. | ||
type EndpointConfig struct { | ||
configuration.Ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Field embedding isn't quite need here. Should be Ignore configuration.Ignore
.
notifications/http.go
Outdated
// TODO(stevvooe): Allow one to configure the media type accepted by this | ||
// sink and choose the serialization based on that. | ||
} | ||
|
||
// newHTTPSink returns an unreliable, single-flight http sink. Wrap in other | ||
// sinks for increased reliability. | ||
func newHTTPSink(u string, timeout time.Duration, headers http.Header, transport *http.Transport, listeners ...httpStatusListener) *httpSink { | ||
func newHTTPSink(u string, timeout time.Duration, headers http.Header, transport *http.Transport, iActions []string, listeners ...httpStatusListener) *httpSink { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sinks are compositional and should be focused on a single goal. Rather than adding an argument here, fix newIgnoredMediaTypesSink
to handle this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks,I will update the commit and submit it later. O(∩_∩)O
@nwt PTAL |
Same comments as @stevvooe, so LGTM after those are addressed. |
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
notifications/sinks.go
Outdated
@@ -210,14 +210,15 @@ func (eq *eventQueue) next() []Event { | |||
return block | |||
} | |||
|
|||
// ignoredMediaTypesSink discards events with ignored target media types and | |||
// ignoredSink discards events with ignored target media types and anctions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: s/anctions/actions/
.
notifications/endpoint.go
Outdated
endpoint.Sink = newIgnoredSink(endpoint.Sink, config.Ignore.MediaTypes, config.Ignore.Actions) | ||
} else { | ||
endpoint.Sink = newIgnoredSink(endpoint.Sink, config.IgnoredMediaTypes, config.Ignore.Actions) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One other nit: If both config.Ignore.MediaTypes
and config.IgnoredMediaTypes
are set, I'd expect both to be honored, so I'd do something like this here:
mediaTypes := append(config.Ignore.MediaTypes, config.IgnoredMediaTypes...)
endpoint.Sink = newIgnoredSink(endpoint.Sink, mediaTypes, config.Ignore.Actions)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a good idea.
Signed-off-by: elsanli(李楠) <[email protected]>
@nwt I have already updated my code. Please review it~ |
LGTM. |
LGTM |
Because image pull events occur frequently and not very important, we do not want to receive such notification events. So we need a filter that filters out the types of events I do not need, and the user can customize the types of events I do not want.