Skip to content

Commit

Permalink
Remove using mochijson2 encoding in event logs
Browse files Browse the repository at this point in the history
Specifically, we encode JSON blobs using {struct, ...} tuples - remove
usage of that encoding. menelaus_util:encode_json does remove these
{struct, ...} tuples and coverts them to the way ejson:encode/1
expects it to be, but cleaning these up as suggested below:

https: //review.couchbase.org/c/ns_server/+/167153/2/src/event_log.erl#210
Change-Id: I914d41c7b349fb90e495665dbd103cff472cf06f
Reviewed-on: https://review.couchbase.org/c/ns_server/+/167282
Well-Formed: Build Bot <build@couchbase.com>
Tested-by: Build Bot <build@couchbase.com>
Tested-by: Hareen Kancharla <hareen.kancharla@couchbase.com>
Reviewed-by: Abhijeeth Nuthan <abhijeeth.nuthan@couchbase.com>
  • Loading branch information
hareen-kancharla committed Dec 9, 2021
1 parent 068a047 commit e02bf21
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/event_log.erl
Expand Up @@ -187,7 +187,7 @@ build_mandatory_attributes(Event) ->
build_extra_attributes([]) ->
[];
build_extra_attributes(Extra) ->
[{extra_attributes, {struct, lists:flatten(Extra)}}].
[{extra_attributes, {lists:flatten(Extra)}}].

add_log(Event) ->
add_log(Event, []).
Expand Down
4 changes: 2 additions & 2 deletions src/menelaus_web_ldap.erl
Expand Up @@ -42,8 +42,8 @@ handle_ldap_settings_post(Req) ->
NewSettings = ldap_util:build_settings(),
event_log:add_log(
ldap_cfg_changed,
[{old_settings, {struct, prepare_ldap_settings(OldSettings)}},
{new_settings, {struct, prepare_ldap_settings(NewSettings)}}]),
[{old_settings, {prepare_ldap_settings(OldSettings)}},
{new_settings, {prepare_ldap_settings(NewSettings)}}]),
handle_ldap_settings(Req2)
end, [], params(), fun type_spec/1, Req).

Expand Down
4 changes: 2 additions & 2 deletions src/menelaus_web_mcd_settings.erl
Expand Up @@ -216,8 +216,8 @@ continue_handle_post(Req, Params, SettingsKey, ExtraConfigKey) ->
NewSettings =/= [] andalso NewSettings =/= OldSettings ->
event_log:add_log(
memcached_cfg_changed,
[{old_settings, {struct, OldSettings}},
{new_settings, {struct, NewSettings}}]);
[{old_settings, {OldSettings}},
{new_settings, {NewSettings}}]);
true ->
ok
end,
Expand Down
8 changes: 4 additions & 4 deletions src/menelaus_web_rbac.erl
Expand Up @@ -149,8 +149,8 @@ handle_saslauthd_auth_settings_post(Req) ->
NewSettings = saslauthd_auth:build_settings(),
event_log:add_log(
saslauthd_cfg_changed,
[{old_settings, {struct, PrevSettings}},
{new_settings, {struct, NewSettings}}]),
[{old_settings, {PrevSettings}},
{new_settings, {NewSettings}}]),
ns_audit:setup_saslauthd(Req, Props),
handle_saslauthd_auth_settings(Req);
{errors, Errors} ->
Expand Down Expand Up @@ -1571,8 +1571,8 @@ handle_post_password_policy(Req) ->
NewSettings = ns_config:read_key_fast(password_policy, []),
event_log:add_log(
password_policy_changed,
[{old_settings, {struct, PrevSettings}},
{new_settings, {struct, NewSettings}}]),
[{old_settings, {PrevSettings}},
{new_settings, {NewSettings}}]),
ns_audit:password_policy(Req, Policy),
menelaus_util:reply(Req, 200)
end, Req, form, post_password_policy_validators()).
Expand Down
4 changes: 2 additions & 2 deletions src/menelaus_web_settings.erl
Expand Up @@ -607,8 +607,8 @@ handle_post(Type, Keys, Req) ->
OldPropsJSON = jsonify_security_settings(OldProps),
event_log:add_log(
security_cfg_changed,
[{old_settings, {struct, OldPropsJSON}},
{new_settings, {struct, NewPropsJSON}}]);
[{old_settings, {OldPropsJSON}},
{new_settings, {NewPropsJSON}}]);
_ ->
AuditFun = audit_fun(Type),
ns_audit:AuditFun(Req, NewProps)
Expand Down
4 changes: 2 additions & 2 deletions src/ns_audit.erl
Expand Up @@ -754,7 +754,7 @@ jsonify_audit_settings(Settings0) ->

add_event_log(OldSettings, NewSettings) ->
OldSettingsJson = [{old_settings,
{struct, jsonify_audit_settings(OldSettings)}}],
{jsonify_audit_settings(OldSettings)}}],
case NewSettings of
[] ->
event_log:add_log(audit_disabled, OldSettingsJson);
Expand All @@ -764,7 +764,7 @@ add_event_log(OldSettings, NewSettings) ->
andalso
proplists:get_value(auditd_enabled, NewSettings) =:= true,
NewSettingsJson =
[{new_settings, {struct, jsonify_audit_settings(NewSettings)}}],
[{new_settings, {jsonify_audit_settings(NewSettings)}}],

case Enabled of
true ->
Expand Down
6 changes: 2 additions & 4 deletions src/ns_bucket.erl
Expand Up @@ -1008,11 +1008,9 @@ update_bucket_props(Type, StorageMode, BucketName, Props) ->
{bucket_uuid, uuid(BucketName, direct)},
{type, DisplayBucketType},
{old_settings,
{struct, build_bucket_props_json(
PrevProps)}},
{build_bucket_props_json(PrevProps)}},
{new_settings,
{struct, build_bucket_props_json(
NewProps)}}]);
{build_bucket_props_json(NewProps)}}]);
true ->
ok
end,
Expand Down
12 changes: 5 additions & 7 deletions src/ns_orchestrator.erl
Expand Up @@ -620,8 +620,7 @@ idle({create_bucket, BucketType, BucketName, NewConfig}, From, _State) ->
[{bucket, list_to_binary(BucketName)},
{bucket_uuid, ns_bucket:uuid(BucketName, direct)},
{bucket_type, ns_bucket:display_type(BucketType, StorageMode)},
{bucket_props,
{struct, NewConfigJSON}}]),
{bucket_props, {NewConfigJSON}}]),
request_janitor_run({bucket, BucketName});
_ -> ok
end,
Expand Down Expand Up @@ -741,7 +740,7 @@ idle({start_graceful_failover, Nodes, Id, RetryChk}, From, _State) ->
"Operation Id = ~s", [Nodes, Id]),
Type = graceful_failover,
event_log:add_log(graceful_failover_initiated,
[{nodes_info, {struct, NodesInfo}},
[{nodes_info, {NodesInfo}},
{operation_id, Id}]),
ns_cluster:counter_inc(Type, start),
set_rebalance_status(Type, running, Pid),
Expand Down Expand Up @@ -802,7 +801,7 @@ idle({start_rebalance, KeepNodes, EjectNodes, FailedNodes, DeltaNodes,
end,
event_log:add_log(rebalance_initiated,
[{operation_id, RebalanceId},
{nodes_info, {struct, NodesInfo}}]),
{nodes_info, {NodesInfo}}]),
ns_cluster:counter_inc(Type, start),
set_rebalance_status(Type, running, Pid),

Expand Down Expand Up @@ -1643,12 +1642,11 @@ handle_start_failover(Nodes, AllowUnsafe, From, Wait, FailoverType, Options) ->
[];
_ ->
[{failover_reason,
{struct,
[{Node, JSONFun(Reason)} ||
{[{Node, JSONFun(Reason)} ||
{Node, Reason} <- FailoverReasons]}}]
end,
event_log:add_log(Event, [{operation_id, Id},
{nodes_info, {struct, NodesInfo}},
{nodes_info, {NodesInfo}},
{allow_unsafe, AllowUnsafe}] ++
FOReasonsJSON),

Expand Down
2 changes: 1 addition & 1 deletion src/ns_rebalance_observer.erl
Expand Up @@ -200,7 +200,7 @@ add_event_log(#state{type = Type,
TimeTaken = rebalance_stage_info:diff_timestamp(EndTime, StartTime),
event_log:add_log(get_event(Type, ResultType),
[{operation_id, Id},
{nodes_info, {struct, NodesInfo}},
{nodes_info, {NodesInfo}},
{time_taken, TimeTaken},
{completion_message, ExitInfo}]).

Expand Down

0 comments on commit e02bf21

Please sign in to comment.