Skip to content

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

Merged
merged 3 commits into from
Mar 29, 2025

Conversation

mholt
Copy link
Member

@mholt mholt commented Mar 28, 2025

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

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).
@mholt mholt added the under review 🧐 Review is pending before merging label Mar 28, 2025
Copy link

@Copilot Copilot AI left a 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.

@mholt
Copy link
Member Author

mholt commented Mar 29, 2025

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.

@mholt mholt removed the under review 🧐 Review is pending before merging label Mar 29, 2025
@mholt mholt merged commit 5a6b2f8 into master Mar 29, 2025
20 checks passed
@mholt mholt deleted the more-events branch March 29, 2025 14:15
@joeblew999
Copy link

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 .

@francislavoie
Copy link
Member

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

@mholt
Copy link
Member Author

mholt commented Apr 6, 2025

Beat me to the answer. Thanks @francislavoie !

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.

3 participants