-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
events: Refactor; move Event into core, so core can emit events #6930
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
Conversation
Requires some slight trickery to invert dependencies. We can't have the caddy package import the caddyevents package, because caddyevents imports caddy. Interface to the rescue! Also add two new events, experimentally: started, and stopping. At the request of a sponsor. Also rename "Filesystems" to "FileSystems" to match Go convention (unrelated to events, was just bugging me when I noticed it).
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.
Pull Request Overview
This PR refactors the event system by moving the Event struct into core and by updating Filesystems to FileSystems to better conform to Go naming conventions. It also adds two experimental events ("started" and "stopping") and inverts dependencies to eliminate import cycles.
- Renames Filesystems to FileSystems across multiple modules.
- Updates the event emission mechanism to use a new event interface and helper functions.
- Introduces experimental events to signal application lifecycle changes.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
modules/caddyhttp/fileserver/staticfiles.go | Updates ctx.Filesystems() to ctx.FileSystems() to comply with updated naming. |
modules/caddyhttp/fileserver/matcher_test.go | Reflects renaming of FilesystemMap to FileSystemMap in tests. |
modules/caddyhttp/fileserver/matcher.go | Updates matcher's provisioning to use FileSystems. |
modules/caddyfs/filesystem.go | Renames Filesystems to FileSystems in filesystem registration and unregistration. |
modules/caddyevents/app.go | Refactors event emission to use the new API with improved logging and error handling. |
internal/filesystems/map.go | Renames DefaultFilesystemKey and related variables to use FileSystem naming. |
context.go | Renames Filesystems API to FileSystems; adds emitEvent for core event emission. |
caddy.go | Adapts configuration and lifecycle event emission to support the new event system and filesystem naming. |
Huh, that's interesting. Anyway, as we know from the sponsor this is working, I'll probably merge this now and fix a potential bug with logging in another patch. |
This is exactly what I also needed . What transport are events going to be published with ? I would like to try this so I can integrate it with load balancers , to tell them when caddy starts / stops. I suspect this will be highly useful for modules also . |
Events are only pushed via this event interface (Go level APIs), so you can use a plugin or write your own to do something with the events. See here https://caddyserver.com/docs/caddyfile/options#event-options |
Beat me to the answer. Thanks @francislavoie ! |
Breaking change for modules that use events. I suspect this will affect very few code bases. Events are also documented as still experimental, and for good reason! This allows us to do much more with events and make them more useful.
Requires some slight trickery to invert dependencies. We can't have the caddy package import the caddyevents package, because caddyevents imports caddy. Interface to the rescue!
Also add two new events, experimentally: started, and stopping. At the request of a sponsor.
Also rename "Filesystems" to "FileSystems" to match Go convention (unrelated to events, was just bugging me when I noticed it).
/cc @ankon