-
Notifications
You must be signed in to change notification settings - Fork 10
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
cobrautil v2 #19
cobrautil v2 #19
Conversation
6e2b011
to
8bfdabf
Compare
this allows clients importing just the bits they need without bringing all the transitive module dependencies
the functionality is largely the same as v1. The gist of this redesign is configurability: v1 didn't offer any API to have cobrautil consumer adjust the logger was configured. This is important as zerolog provides a vast API with many knobs to tweak. - a new fluent API is offered so that cobrautil/zerolog can be extended with options as the need arises. It's used to implement two new options in the package - v1 assumed the consumer would use the zerolog/log global instance package. This forces the consuming application to use that global instance. The WithTarget option offers a callback when the logger is instantiated, so e.g. consumers can cache the instance somewhere else - v1 used zerolog global level. This is an unexpected side-effect the consumer may not want, specially given cobrautil is creating an instance of a zerolog Logger. The implementation now adjusts the level on the logger instance instead. - singleton methods are provided to offer an easy path of migration to v2. - WithAsync configures the logger to be non-blocking, implemented using diode buffered-ring. This is default by default to retain v1 behaviour.
behaviour should be the same as v1, but: - removes dependency on zerolog and replaces with go-log/logr - allows defining the logger used by otel
8bfdabf
to
6eeae43
Compare
6b41b83
to
8627e24
Compare
- since it's optional and has a sensible default - also align preRunLevel in OTel with zerolog
- turned all optional arguments into a ConfigureFunc - added WithHandler to provide a http.Handler to inject into ServerFromFlags - added ListenFromFlags that instantiates the http.Server - migrated go go-log/logr facade
a2352c4
to
553eadd
Compare
- turned all optional arguments into a ConfigureFunc - migrated go go-log/logr facade
- make sure messaging is consistent - make use of same logging level across packages - do not warn on insecure http/gRPC. Instead load additional key-value - log scheme in http package
} | ||
|
||
// CobraUtil carries the configuration for a otel CobraRunFunc | ||
type CobraUtil struct { |
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.
I'd name this type config in each package instead of cobrautil. I think it makes sense to also make the type private, since all of the fields are also private. I'm pretty sure you can still return the type from functions, but folks will just be unable to construct it from a literal in other packages.
Picking up optgen might also be a good idea for this too: https://github.com/ecordell/optgen
Closes #17
Main design choices
Zerolog
The main problems is v1 didn't offer any API to have
cobrautil
consumers adjust how the logger was configured. This is important as zerolog provides a vast API with many knobs to tweak.cobrautil/zerolog
can be extended with options as the need arises.zerolog/log
global instance package. This forces the consuming application to use that global instance. TheWithTarget
option offers a callback when the logger is instantiated, so e.g. consumers can cache the instance somewhere else. It continues to default to that global instance.Logger
. The implementation now adjusts the level on the logger instance instead.WithAsync
configures the logger to be non-blocking, implemented using diode buffered-ring. This is default by default to retain v1 behaviour.See how it's used in https://github.com/authzed/spicedb/pull/844/files#diff-df0635588ca5d6a577487faacc185c3838a3fe2b321660c36372541797c54c74R59-R67
OTel
zerolog
and replaces withgo-log/logr
WithLogger
makes it possible to set the global logger used by the OTel librarydebug
HTTP
WithLogger
allows injecting a customgo-log/logr
valueWithHandler
allows injecting ahttp.Handler
into thehttp.Server
to be createddebug
instead ofinfo
. Can be tweaked withWithPreRunLevel
warn
level logging for non-https configuration moves topreRunLevel
. Insecure http is used behind load-balancers that do TLS offloading.gRPC
WithLogger
allows injecting a customgo-log/logr
valuedebug
instead ofinfo
. Can be tweaked withWithPreRunLevel
warn
level logging for non-https configuration moves topreRunLevel
. Insecure http is used behind load-balancers that do TLS offloading.