Skip to content
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

Merged
merged 1 commit into from
Mar 14, 2018

Conversation

xiaonancc77
Copy link

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.

image

@GordonTheTurtle
Copy link

Please sign your commits following these rules:
https://github.com/moby/moby/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ 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
Copy link

codecov bot commented Jan 18, 2018

Codecov Report

Merging #2501 into master will decrease coverage by 9.63%.
The diff coverage is 95%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
configuration/configuration.go 68.33% <ø> (ø) ⬆️
registry/handlers/app.go 48.04% <0%> (+0.24%) ⬆️
notifications/sinks.go 95% <100%> (+0.33%) ⬆️
notifications/endpoint.go 94.44% <100%> (+0.15%) ⬆️
registry/storage/driver/gcs/gcs.go 0.39% <0%> (-68.67%) ⬇️
registry/storage/driver/oss/oss.go 0.56% <0%> (-56.91%) ⬇️
registry/storage/driver/s3-goamz/s3.go 0.5% <0%> (-51.14%) ⬇️
registry/storage/driver/s3-aws/s3.go 4.15% <0%> (-50.98%) ⬇️
registry/client/transport/transport.go 69.69% <0%> (-9.1%) ⬇️
registry/storage/driver/base/base.go 69.23% <0%> (-5.32%) ⬇️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6fca8d6...fc1d364. Read the comment docs.

@@ -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
Copy link
Collaborator

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.

Copy link
Author

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.

@stevvooe
Copy link
Collaborator

Rather than piling on another field, it would better if this was properly structured:

ignore:
  mediatypes: []
  actions: []

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 ignoredmediatypes in favor of this configuration, but this is going to get out of hand really quickly. #1957 should have considered these cases before being merged.

Other than that, this seems like a reasonable feature.

@xiaonancc77
Copy link
Author

Thancks@stevvooe , this is a good idea, I will update the commit and submit it later.

@xiaonancc77
Copy link
Author

@stevvooe I don't how to solve this problem.
image
The diff hit index is lower, because I formatted my code with "gofmt -s" to pass the CI test. I do not know how to improve the diff hit index for my code. Hope to get your help, Thanks.
image
image

@xiaonancc77
Copy link
Author

@stevvooe Hope to get your help, Thanks so much.

@stevvooe
Copy link
Collaborator

stevvooe commented Feb 3, 2018

@xiaonancc77 Don't worry about the diffs: we deal with this in Go to have consistent formatting.

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
Copy link
Collaborator

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.

}

//Ignore configures mediaTypes and actions of the event, that it won't be propagated
type Ignore struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"net/http"
"time"
)

// EndpointConfig covers the optional configuration parameters for an active
// endpoint.
type EndpointConfig struct {
configuration.Ignore
Copy link
Collaborator

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.

// 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 {
Copy link
Collaborator

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.

Copy link
Author

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

@stevvooe
Copy link
Collaborator

stevvooe commented Feb 3, 2018

@nwt PTAL

@nwt
Copy link
Contributor

nwt commented Feb 6, 2018

Same comments as @stevvooe, so LGTM after those are addressed.

@xiaonancc77
Copy link
Author

@stevvooe @nwt I'm so sorry to submit late. Because I am very busy recently. I have already solved the above problems. Thanks. O(∩_∩)O

@stevvooe
Copy link
Collaborator

stevvooe commented Mar 9, 2018

LGTM

Copy link
Contributor

@nwt nwt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: s/anctions/actions/.

endpoint.Sink = newIgnoredSink(endpoint.Sink, config.Ignore.MediaTypes, config.Ignore.Actions)
} else {
endpoint.Sink = newIgnoredSink(endpoint.Sink, config.IgnoredMediaTypes, config.Ignore.Actions)
}
Copy link
Contributor

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)

Copy link
Author

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.

@xiaonancc77
Copy link
Author

@nwt I have already updated my code. Please review it~

@nwt
Copy link
Contributor

nwt commented Mar 13, 2018

LGTM.

@xiaonancc77 xiaonancc77 changed the title Added ignore event typs into notifications Added ignore event types into notifications Mar 14, 2018
@dmcgowan
Copy link
Collaborator

LGTM

@dmcgowan dmcgowan merged commit 607ae5d into distribution:master Mar 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants