Skip to content

feat(events): add events extension #3045

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

Merged
merged 30 commits into from
May 2, 2025

Conversation

phoban01
Copy link
Contributor

@phoban01 phoban01 commented Mar 19, 2025

What type of PR is this?

feature

Which issue does this PR fix:

#2992

What does this PR do / Why do we need it:
This PR introduces a new extension: events that enables publishing events in the CloudEvent schema.

The following event types are implemented:

  • RepositoryCreated
  • ImageUpdated
  • ImageDeleted
  • ImageLintFailed

Two event sinks are implemented as part of this change:

  • HTTP: a generic http event sink that can be used for webhook style eventing
  • NATS: a nats event sink that can send events to a nats server

Testing done on this change:

Unit tests added for http and nats event sinks. I have also tested things locally.

Automation added to e2e:

Will this break upgrades or downgrades?
No

Does this PR introduce any user-facing change?:

Yes it introduces a new configuration stanza for events.

The following shows how the extension may be configured:

  "extensions": {
    "events": {
      "enable": true,
      "sinks": [
        {
          "type": "nats",
          "address": "nats://127.0.0.1:4222",
          "timeout": "2s",
          "channel": "alerts.images"
       }, 
        {
          "type": "http",
          "address": "http://127.0.0.1:3333/events/zot/webhook",
          "timeout": "5s",
       }]
    }
  }

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@phoban01 phoban01 changed the title Feat: support events (feat): support events Mar 19, 2025
@phoban01 phoban01 changed the title (feat): support events feat(events): add events extension Mar 19, 2025
@phoban01 phoban01 force-pushed the feat-support-events branch from 28ab11e to bc805f9 Compare March 19, 2025 18:35
@rchincha
Copy link
Contributor

@phoban01 nice work! thanks for starting this PR.

@@ -954,7 +954,7 @@ func TestCookiestoreCleanup(t *testing.T) {
err = os.Chtimes(sessionPath, changeTime, changeTime)
So(err, ShouldBeNil)

imgStore := local.NewImageStore(rootDir, false, false, log, metrics, nil, nil, nil)
imgStore := local.NewImageStore(rootDir, false, false, log, metrics, nil, nil, nil, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

We really need to shorten the args list into a struct we can pass around. Not related to your PR thouugh.

@phoban01
Copy link
Contributor Author

Updated with HTTP and NATs event sinks. Also generalized the sink config.

@phoban01 phoban01 marked this pull request as ready for review March 20, 2025 18:19
@phoban01 phoban01 requested a review from rchincha March 21, 2025 16:31
@phoban01 phoban01 force-pushed the feat-support-events branch 2 times, most recently from 6027785 to ba31ccf Compare March 31, 2025 06:47
@phoban01
Copy link
Contributor Author

phoban01 commented Apr 2, 2025

Anything I can do to help bump this along? cc: @rchincha

@rchincha
Copy link
Contributor

rchincha commented Apr 4, 2025

Anything I can do to help bump this along? cc: @rchincha

There are CI failures that will need fixing.

@phoban01 phoban01 force-pushed the feat-support-events branch from fadab3f to 6a42932 Compare April 4, 2025 08:12
@rchincha
Copy link
Contributor

rchincha commented Apr 4, 2025

@phoban01

Let's also add an end-to-end validation with a mock or real CloudEvents server/broker.
Something along these lines.
https://github.com/project-zot/zot/blob/main/.github/workflows/ecosystem-tools.yaml

Easiest to pick something you can package as a container image.
https://github.com/cloudevents/conformance

You are making an investment with this PR, let's also protect it going forward.

@phoban01
Copy link
Contributor Author

phoban01 commented Apr 4, 2025

Let's also add an end-to-end validation with a mock or real CloudEvents server/broker.

Yeah, agree; I've been thinking a bit about this. My current dev machine is macos/arm... which is not really compatible with the current Makefile as most tools are targeting amd arch.

I can update the Makefile to address these issues, @rchincha you happy for that to be part of this PR or shall I break it out?

@phoban01 phoban01 force-pushed the feat-support-events branch from 6a42932 to a7632fe Compare April 4, 2025 16:38
@rchincha
Copy link
Contributor

rchincha commented Apr 5, 2025

I can update the Makefile to address these issues, @rchincha you happy for that to be part of this PR or shall I break it out?

Either way is fine.

First the CI failures need addressing. Let us know if need help with that. Note that data race detection is enabled for our tests.

@phoban01 phoban01 force-pushed the feat-support-events branch from 1ea5194 to 2b3564b Compare April 7, 2025 07:00
@phoban01 phoban01 force-pushed the feat-support-events branch from ccc5e45 to 8c0d3f1 Compare April 10, 2025 18:17
@phoban01
Copy link
Contributor Author

Added blackbox tests for events service covering nats and http.

@phoban01 phoban01 force-pushed the feat-support-events branch 2 times, most recently from c8c5a68 to cc5148a Compare May 1, 2025 13:34
@phoban01
Copy link
Contributor Author

phoban01 commented May 1, 2025

Apologies @andaaron; your review got dismissed because of a DCO issue.

andaaron
andaaron previously approved these changes May 1, 2025
@rchincha
Copy link
Contributor

rchincha commented May 1, 2025

{"level":"error","error":"decoding failed due to the following error(s):\n\nerror decoding 'Extensions.Events.Sinks[0]': event sink is not supported","time":"2025-05-01T14:02:39.330842112Z","message":"failed to unmarshal new config"}
Error: decoding failed due to the following error(s):

error decoding 'Extensions.Events.Sinks[0]': event sink is not supported

I believe this PR is very close to merging.

@rchincha
Copy link
Contributor

rchincha commented May 1, 2025

Also, go.mod needs bumping ...
CVEs
Introduced through
github.com/nats-io/[email protected]
Fixed in
github.com/nats-io/nats-server/[email protected], @2.11.1

@rchincha
Copy link
Contributor

rchincha commented May 1, 2025

@phoban01 not sure if you are able to look at coverage profile. If you are, do also look at bumping coverage up.

@phoban01 phoban01 force-pushed the feat-support-events branch from 30b182a to 524280b Compare May 2, 2025 06:51
@phoban01
Copy link
Contributor Author

phoban01 commented May 2, 2025

@phoban01 not sure if you are able to look at coverage profile. If you are, do also look at bumping coverage up.

I am; spent some time on it earlier this week. Will invest more as time allows.

@phoban01
Copy link
Contributor Author

phoban01 commented May 2, 2025

{"level":"error","error":"decoding failed due to the following error(s):\n\nerror decoding 'Extensions.Events.Sinks[0]': event sink is not supported","time":"2025-05-01T14:02:39.330842112Z","message":"failed to unmarshal new config"}
Error: decoding failed due to the following error(s):

error decoding 'Extensions.Events.Sinks[0]': event sink is not supported

I believe this PR is very close to merging.

Fix in 524280b

andaaron
andaaron previously approved these changes May 2, 2025
Copy link
Contributor

@rchincha rchincha left a comment

Choose a reason for hiding this comment

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

lgtm

@rchincha rchincha requested a review from andaaron May 2, 2025 19:21
@rchincha rchincha merged commit bc5fd1a into project-zot:main May 2, 2025
41 of 43 checks passed
@rchincha
Copy link
Contributor

rchincha commented May 2, 2025

@phoban01 @asgeirn
PR has been merged.

Pls do consider joining #zot on Slack
https://cloud-native.slack.com/archives/C03EGRE4QGH

@rchincha
Copy link
Contributor

rchincha commented May 2, 2025

https://github.com/project-zot/zot/releases/tag/v2.1.3-rc6
^ now released. @phoban01 enjoy the fruits of your labor, and thanks for sharing with the community.
@asgeirn thx for pitching in.

@joejulian
Copy link

@rchincha just an FYI. I noticed this introduces a new dependency on helm. The helm project is working on v4 and one of the dependency changes in v4 is oras v2.

You might want to give some thought to upgrading oras at some point.

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