-
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
Add log filtering functionality #71
Conversation
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.
LGTM. Couple of very minor comments.
|
||
return result | ||
for i := 0; i < len(args); i += 2 { |
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.
Although it looks like this should never happen, if len(args)
is an odd/uneven number, then a key with no corresponding value could be appended to keys
.
Perhaps for i := 0; i + 1 < len(args); i += 2 {
could be used to avoid such a scenario?
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 added tests for this as well
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.
Nice work so far -- a couple opening questions/comments before potentially diving deeper into things.
func omitOrMask(ctx context.Context, logger hclog.Logger, msg *string, additionalFields []map[string]interface{}) ([]interface{}, bool) { | ||
tfLoggerOpts := logging.GetProviderRootTFLoggerOpts(ctx) | ||
additionalArgs := hclogutils.MapsToArgs(additionalFields...) | ||
impliedArgs := logger.ImpliedArgs() |
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.
Could we save a lot of slice trouble by keeping everything as maps with terraform-plugin-log? e.g. Keeping additionalFields
as []map[string]interface{}
(or better yet requiring the merged additional fields map) and writing the inverse of hclogutils.MapsToArgs()
if we ever need to interrogate the underlying (Logger).ImpliedArgs()
? That said, we might be able to avoid ImpliedArgs()
completely, if we also saved the With()
information similar to this filtering information.
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.
Doing the filtering on the maps, would force the logic to convert the ImpliedArgs
to map, before it can be filtered.
So I did the opposite, given that the underlying library requires to go in the args = [][]interface{}
direction.
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.
Right, but in my opinion it is more difficult to work with the slices correctly since it is an odd way to store paired data, when a map gives you direct access to paired keys and values. I think it would save a lot of code complexity and readability, such as not needing to loop through all slice elements to find a key to mask its value, to let the slice stuff be a detail we don't have to worry about except for converting to/from.
It would be nice to avoid ImpliedArgs()
completely, but that change can certainly happen outside the scope of adding filters.
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 agree that the ImpliedArgs()
(that ultimately dictate this) are a sub-par thing from hclog
. But I didn't want to expand my work to have to also alter With()
so to always keep those key/value pairs stored in the context.
And writing the couple of i += 2
for loops was relatively easy.
We can refactor that later I guess.
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.
There was no need to refactor With() now (we could've introduced the slice to map converter temporarily), but like you say, it can be refactored later.
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'll create a follow up ticket to do the refactoring and simplification: iterating over the keys of a map is definitely the most desirable way to go. Just focused on getting the functionality done and working on this one.
a77fef1
to
5a3bd75
Compare
5a3bd75
to
8e9c63e
Compare
It takes `ImplicitArgs()` from `hclog.Logger`, and returns the keys of the k/v pairs slice
…onfiguration in Context
- tflog root logger - tflog subsystem logger - tfsdklog root logger - tfsdklog subsystem logger
a51f677
to
a1e51ea
Compare
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 don't agree with the readability and complexity of using slices throughout over maps, but the implementation works and that can be refactored later. Looks good to me, otherwise. 🚀
Will add a CHANGELOG entry for |
84ad741
to
d23e161
Compare
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
Closes #17
This is a general purpose solution, to enable provider developers to setup log filtering at runtime. Both log omission and log masking are supported.
Feature summary
For log omission (i.e. the log is never given to the underlying writer), it offers the following:
For log masking, it offers the following:
***
***
Feature coverage
The log filtering covers all the loggers in the package:
tflog
provider root loggertflog
provider subsystems loggertfsdklog
provider loggertfsdklog
provider subsystems logger