Repository navigation
Webhook notification support in registry webapp - #113
Conversation
ef5e3f6 to
d863726
Compare
There was a problem hiding this comment.
Do you think it'd be best to start calling these methods Blob* now?
There was a problem hiding this comment.
For now, I want things to be consistent. There is a grip of renaming that needs to happen for that. The intended refactoring changes the name of storage.Layer to storage.Blob. We also need to move those definitions out of the storage package.
I'll probably file an issue with these plans later this week.
d1a1c4b to
b0ad15c
Compare
|
@stevvooe with the pending removal of the decorators, I want to make sure that we'll still be able to "wrap" the entire set of registry routes and do some preliminary handling (auth) before forwarding the request to the actual handlers. I believe this is our planned approach (instead of using a separate standalone proxy in front of the registry) so I wanted to make sure it was something you're aware of. Once I wrap up the work I'm doing on something else, I plan to take a stab at trying this out. EDIT: "our" == OpenShift :-) |
|
@ncdc The removal of the decorator package was well-considered. After implementing the actual notification feature, the extra complexity did not prove as useful as I once thought. With the This was replaced by the code in It's unfortunate that the |
|
@stevvooe that makes sense. I found the auth.AccessController interface and am really happy to see that! Also, I'm looking in app.go at the |
|
@ncdc The Anything that intercepts repository calls would have to be built into app at this point. The Once you have your use case better defined, we should probably start looking at what would be required in the app interface to support the kind of intercepts that are required. |
8db5ca4 to
0830294
Compare
There was a problem hiding this comment.
I know the methods are all named *Layer* but the actual event would be triggered by a GET/PUT to a blob url.
There was a problem hiding this comment.
Woops, oversight. Adding this:
const (
EventTargetTypeManifest = "manifest"
EventTargetTypeBlob = "blob"
)
|
I don't think blob pull events should occur from "HEAD" requests. |
|
Other than the |
Agreed. What if we added request method to the
Fancy you ask: I am working on a PR that integrates google context. This will include the user data. Will this be okay for the time being? |
I remember an earlier discussion about how |
|
just spoke with @stevvooe, it looks like we'll be adding extra We also started talking about event sink filters, so you can configure an endpoint to not send events with |
|
@jlhawn The other option is to avoid setting up the event bridge repository when receiving a head request. Albeit, we may glean more information if we have a an event for the HEAD request. |
0830294 to
c27099f
Compare
This commit defines the message format used to notify external parties of activity within a registry instance. The event includes information about which action was taken on which registry object, including what user created the action and which instance generated the event. Message instances can be sent throughout an application or transmitted externally. An envelope format along with a custom media type is defined along with tests to detect changes to the wire format. Signed-off-by: Stephen J Day <[email protected]>
To provide easier access to digestible content, the paylaod has been made accessible on the signed manifest type. This hides the specifics of the interaction with libtrust with the caveat that signatures may be parsed twice. We'll have to have a future look at the interface for manifest as we may be making problematic architectural decisions. We'll visit this after the initial release. Signed-off-by: Stephen J Day <[email protected]>
This changeset implements webhook notification endpoints for dispatching registry events. Repository instances can be decorated by a listener that converts calls into context-aware events, using a bridge. Events generated in the bridge are written to a sink. Implementations of sink include a broadcast and endpoint sink which can be used to configure event dispatch. Endpoints represent a webhook notification target, with queueing and retries built in. They can be added to a Broadcaster, which is a simple sink that writes a block of events to several sinks, to provide a complete dispatch mechanism. The main caveat to the current approach is that all unsent notifications are inmemory. Best effort is made to ensure that notifications are not dropped, to the point where queues may back up on faulty endpoints. If the endpoint is fixed, the events will be retried and all messages will go through. Internally, this functionality is all made up of Sink objects. The queuing functionality is implemented with an eventQueue sink and retries are implemented with retryingSink. Replacing the inmemory queuing with something persistent should be as simple as replacing broadcaster with a remote queue and that sets up the sinks to be local workers listening to that remote queue. Metrics are kept for each endpoint and exported via expvar. This may not be a permanent appraoch but should provide enough information for troubleshooting notification problems. Signed-off-by: Stephen J Day <[email protected]>
After implementing notifications end to end, it was found that decorating repositories was more straightforward that previously thought. It's unfortunate to can this package, but it led to the techniques employed in storage/notifications/listeners.go. The ultimate result turned out much better.
If configured, a debug http server will be started to serve default registered endpoints, such as pprof and expvar. The endpoint should be secured carefully and not available to external traffic. It is disabled by default but the development config has been modified to make it available on localhost. Signed-off-by: Stephen J Day <[email protected]>
Endpoints are now created at applications startup time, using notification configuration. The instances are then added to a Broadcaster instance, which becomes the main event sink for the application. At request time, an event bridge is configured to listen to repository method calls. The actor and source of the eventBridge are created from the requeest context and application, respectively. The result is notifications are dispatched with calls to the context's Repository instance and are queued to each endpoint via the broadcaster. This commit also adds the concept of a RequestID and App.InstanceID. The request id uniquely identifies each request and the InstanceID uniquely identifies a run of the registry. These identifiers can be used in the future to correlate log messages with generated events to support rich debugging. The fields of the app were slightly reorganized for clarity and a few horrid util functions have been removed. Signed-off-by: Stephen J Day <[email protected]>
To clarify the role of actor, the request data that initiates an event has been separated. The ActorRecord is pared down to just the username. This eliminates confusion about where event related data should be added. Signed-off-by: Stephen J Day <[email protected]>
c27099f to
080e329
Compare
|
Thanks! The |
|
LGTM |
Webhook notification support in registry webapp
This PR provides support for configurable webhook notification endpoints.
Endpoints are created at applications startup time, using notification configuration. The instances are then added to a Broadcaster instance, which becomes the main event sink for the application. At request time, an event bridge is configured to listen to repository method calls. The actor and source of the eventBridge are created from the requeest context and application, respectively. The result is notifications are dispatched with calls to the context's Repository instance and are queued to each endpoint via the broadcaster.
This PR also adds the concept of a RequestID and App.InstanceID. The request id uniquely identifies each request and the InstanceID uniquely identifies a run of the registry. These identifiers can be used in the future to correlate log messages with generated events to support rich debugging. Please see the notification.Event type for information on how these fields relate.
The fields of the app were slightly reorganized for clarity and a few horrid util functions have been removed.
The following is an example notification generated while testing the feature:
If we look closely, there are some interesting things to note. First the source is obtained from the hostname, which is just running on my laptop. If running in a docker container, the instance id of the host would be picked up as the dns default name. The next interesting peice is that the external urls are picked up from
Hostheader in the initial request, making this compatible with registry instances that may serve content as multiple hosts.An important caveat to note is that the user name is not currently populated in the actor. We'll first need to make some modifications to the auth package to support
Useras a first class object. #118 has been filed to cover this.Debug Server
If configured, a debug http server will be started to serve default registered endpoints, such as pprof and expvar. The endpoint should be secured carefully and not available to external traffic. It is disabled by default but the development config has been modified to make it available on localhost.
This will support endpoint metrics that are reported via expvar, in addition to making pprof available for debugging.
Notification Package
This PR is based on a notification endpoints for dispatching registry events. Repository instances can be decorated by a listener that converts calls into context-aware events, using a bridge. Events generated in the bridge are written to a sink. Implementations of sink include a broadcast and endpoint sink which can be used to configure event dispatch. Endpoints represent a webhook notification target, with an inmemory queue and retries built in. They can be added to a Broadcaster, which is a simple sink that writes a block of events to several sinks, to provide a complete dispatch mechanism.
The main caveat to the current approach is that all unsent notifications are inmemory. Best effort is made to ensure that notifications are not dropped, to the point where queues may back up on faulty endpoints. If the endpoint is fixed, the events will be retried and all messages will go through.
Internally, this functionality is all made up of Sink objects. The queuing functionality is implemented with an eventQueue sink and retries are implemented with retryingSink. Replacing the inmemory queuing with something persistent should be as simple as replacing broadcaster with a remote queue and sets up the sinks to local workers listening to that remote queue.
Metrics are kept for each endpoint and exported via expvar. This may not be a permanent appraoch but should provide enough information for troubleshooting notification problems.
It also includes the message format used to notify external parties of activity within a registry instance. The event includes information about which action was taken on which registry object, including what user created the action and which instance generated the event.
Message instances can be sent throughout an application or transmitted externally. An envelope format along with a custom media type is defined along with tests to detect changes to the wire format.
After implementing notifications end to end, it was found that decorating repositories was more straightforward that previously thought so the decorator package was removed. It's unfortunate to can this package, but it led to the techniques employed in storage/notifications/listeners.go. The ultimate result turned out much better.
Closes #42, #117