Skip to content
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

log type filtering, riak.conf support #1

Open
wants to merge 5 commits into
base: openriak-3.4
Choose a base branch
from

Conversation

martinsumner
Copy link
Collaborator

Changes to add filtering by log_type, and add a helper function to generate configuration from a schema (i.e. riak.conf cuttlefish)

Leveled uses backend log_type, and kv_index_tictcatree uses aae log_type.  This allows for different handling of these logs
Rather than have long translation fun in riak.schema - be able to refer to a translation function within riak_logger.
Have config helper function for producing the same log ouput as in openriak-3.2 as well as new formats for openriak-3.4
Copy link
Member

@tburghart tburghart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of comments, some to be taken with a grain of salt. I think we're a long way from sorting out the proper structure in here, especially in light of the JSON stuff we've got in progress. Since (I think) this is presently limited to your 3.4 stuff, if we can keep it on nhse branches for now we'll be able to compare with the upcoming wday branch and see what way we want to go.

I think there are generalizations to be had for the handler configs, though I'm not sure what they are yet - I just feel like "there's got to be a better way."

@@ -69,6 +70,7 @@

-type f_action() :: log | stop.
-type f_result() :: logger:filter_return().
-type f_type() :: backend|aae|metric.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be atom(), or even term() - the filter, as implemented, doesn't care about the type or value.

{Action :: f_action(), LogTypes :: list(f_type())})
-> f_result().
%% @doc Filter out logs with specific log_types, e.g. such as the backend log
%% type used in leveled
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a head for the most common case?

filter_t(#{meta := #{log_type := LogType}} = Event, {Action, [LogType]}) ->
    filter_match(Event, Action);

case lists:member(LogType, LogTypes) of
true ->
filter_match(Event, Action);
false ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change false to _ - generates less code.

%%
%% -------------------------------------------------------------------
%% Portions informed by OTP module logger_filters,
%% Copyright Ericsson AB 2017-2018, though no code is duplicated.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything in here warranting this attribution?


-module(riak_logger_config).

-export([o34std_generator/2, o32std_generator/2]).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the generators should be pegged to versions, but should instead have descriptive names. Different orgs may not be conforming to the exact OpenRiak versions - for instance, some might be using much of the nominal 3.4 code in 3.2, or vice-versa.
If the generators were really version-specific, they wouldn't exist together.

[Handler] = HandlerList,
?assertMatch(ExpectedConfig, Handler).

wday_handler_test() ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be named per-org, but instead for semantics.
Perhaps std_local_handler_test?

[{crash_filter, {_FilterFunC, Action}}] = maps:get(filters, CLC),
?assertMatch(log, Action).

nhs_handler_test() ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be named per-org, but instead for semantics.
Perhaps std_divert_handler_test?

%% The configuration can be ignored if preferred - and a statically defined
%% logging config be returned

-module(riak_logger_config).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe refactor into more descriptive module name(s), to allow for additions without namespace confusion? Possible names:
riak_log_std_config
riak_log_type_config
riak_log_json_config
That suggests there may be a shared set of functions, perhaps in riak_log_common_config.

@tburghart
Copy link
Member

So, in implementing the JSON logger formatter, I've become fairly convinced that the log_type metadata field semantics can, and should, be implemented using the existing domain field, which is designed specifically for this use case.
As a list, domain also supports hierarchy, so values such as [backend, leveled, penciller], [aae, tictac], [metric, riak_core], etc allow for configurable granularity.
My current JSON formatter defaults to mapping log_type => Value, if present, to domain => [Value].

@martinsumner
Copy link
Collaborator Author

OK, I'm happy with that. I was confused by the domain field when I looked at it, as all the examples refer to internal BEAM domains (e.g. otp, sasl, ssl) - It wasn't clear to me that the intention was that it could then be used within applications themselves. Also with the default rule being to drop a log if it has a domain other than otp was a little off-putting.

But if it is in fact the intention for this to be used by applications, I agree that we should use it.

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.

2 participants