-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add Overlay #1
Add Overlay #1
Conversation
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
I like the idea, it can be used for more than just the logging I'd initially mentioned! How would you see this being used inside a bootstrapper method, such as https://github.com/aphistic/softcopy/blob/master/cmd/softcopy-server/main.go#L27 ? Would it become an additional This is what I'm imagining it would look like, is it right? func (runner nacelle.ProcessContainer, container nacelle.ServiceContainer) error {
// This or some nicer method to move this out of the bootstrapper
rawLogger, err := container.Get("logger")
if err != nil {
return err
}
logger, ok := rawLogger.(nacelle.Logger)
if !ok {
return fmt.Errorf("logger isn't a nacelle logger")
}
runner.RegisterInitializer(
api.NewInitializer(),
nacelle.WithInitializerName("api"),
nacelle.WithInitializerOverlay(nacelle.Overlay(
"logger": logger.WithFields(
"service": "api",
),
),)
)
runner.RegisterProcess(
apiserver.NewProcess(),
nacelle.WithProcessName("apiserver"),
nacelle.WithProcessOverlay(nacelle.Overlay(
"logger": logger.WithFields(
"service": "apiserver",
),
),)
)
} |
My idea was to have the go-nacelle/process create a shim service and logger instance with any additional fields you've applied to an initializer or process. So really the setup methods would be something like: func (runner nacelle.ProcessContainer, container nacelle.ServiceContainer) error {
runner.RegisterInitializer(
api.NewInitializer(),
nacelle.WithInitializerName("api"),
nacelle.WithLogFields(map[string]string{
"service": "api",
}),
)
runner.RegisterProcess(
apiserver.NewProcess(),
nacelle.WithProcessName("apiserver"),
nacelle.WithLogFields(map[string]string{
"service": "apiserver",
}),
)
} Names subject to change, of course! |
And if you have an initializer/process name, this could be done automatically (but would still allow for additional fields to be applied). |
Ahh, gotcha. I didn't notice this was in the service repo at first! |
This PR introduced the
Overlay
function, which allows a service container to be wrapped in a set of additional, immutable services. This works with bothGet
andInject
functions, allowing a service to be temporarily replaced in the base container.This will be useful when specific loggers or context-specific services should be injected in all downstream handlers for a certain process, task, or request.