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

Fixes #22088: make iterator report more independent #1375

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions tree/20_cfe_basics/common.cf
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ body classes cancel_classes(y)
"repair_denied_$(y)", "$(y)_denied", "repair_timeout_$(y)",
"$(y)_timeout", "promise_kept_$(y)", "$(y)_kept"
};

}

body classes common_classes_exclusive_persist_codes(prefix, persist, keptcodes, repairedcodes, errorcodes)
Expand Down Expand Up @@ -353,7 +353,7 @@ bundle agent ncf_classes_copy(source_prefix, destination_prefix)
"destination_defined" expression => strcmp("${destination_prefix}", "${destination_prefix}");
"destination_not_empty" not => strcmp("${destination_prefix}", "");
"destination_exists" and => { "destination_defined", "destination_not_empty" };

"pass2" expression => "pass1";
"pass1" expression => "any";
}
Expand Down Expand Up @@ -381,7 +381,7 @@ bundle agent call_method(method) {
# needs to be called in pass3 as it changes the report_data.method_id which makes it reexecute
"${report_data.method_id}" usebundle => method_id_push("${method}");
"${report_data.method_id}" usebundle => disable_reporting;

reports:
pass3.debug::
"${configuration.debug} Entering method ${report_data.method_id} (should_report: ${call_method_data.${method_id}_${method}})";
Expand All @@ -392,17 +392,17 @@ bundle agent call_method_classes(copy_to_prefix) {
"prefix" string => canonify("${copy_to_prefix}");

methods:
"${report_data.method_id}" usebundle => _classes_copy("${report_data.method_id}", "${prefix}");
"${report_data.method_id}" usebundle => _classes_copy("${report_data.report_id}", "${prefix}");
}

# Define on upper level method id
bundle agent call_method_classes_caller {
vars:
# First entry is latest inserted
"prefix" string => canonify(nth("method_id_unique.stack", 0));
"prefix" string => canonify(nth("method_id_unique.report_stack", 0));

methods:
"${report_data.method_id}" usebundle => _classes_copy("${report_data.method_id}", "${prefix}");
"${report_data.method_id}" usebundle => _classes_copy("${report_data.report_id}", "${prefix}");
}

bundle agent call_method_end(method) {
Expand All @@ -421,7 +421,7 @@ bundle agent call_method_end(method) {
pass3::
"${report_data.method_id}_${method}" usebundle => enable_reporting,
if => "should_report";

reports:
pass3.debug.should_report::
"${configuration.debug} Exiting method ${method} from ${report_data.method_id}, should_report: true";
Expand Down
59 changes: 44 additions & 15 deletions tree/20_cfe_basics/log_rudder.cf
Original file line number Diff line number Diff line change
Expand Up @@ -510,20 +510,24 @@ bundle agent _method_reporting_context(c_name, c_key)
bundle agent _method_reporting_context_v4(c_name, c_key, report_id)
{
vars:
"report_data.component_name" string => "${c_name}";
"report_data.component_key" string => "${c_key}";
# Non-canonified version, to be used in reports
"report_data.report_id_r" string => "${report_id}";
# Canonified version, to be used in policies (as class prefix)
# it needs the directive_id to enforce unicity
"report_data.report_id" string => canonify("${report_id}_${report_data.directive_id}");
"report_data.method_id" string => canonify("${report_id}_${report_data.directive_id}");
"report_data.identifier" string => "${report_data.rule_id}@@${report_data.directive_id}@@${report_data.report_id_r}";
!pass1::
"report_data.index" int => int(eval("${report_data.index}+1", "math", "infix"));
"report_data.component_name" string => "${c_name}";
"report_data.component_key" string => "${c_key}";
# Non-canonified version, to be used in reports
"report_data.report_id_r" string => "${report_id}";
# Canonified version, to be used in policies (as class prefix)
# it needs the directive_id to enforce unicity
"report_data.report_id" string => canonify("${report_id}_${report_data.directive_id}");
"report_data.method_id" string => canonify("${report_id}_${report_data.directive_id}_${report_data.index}");
Copy link
Member

Choose a reason for hiding this comment

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

this change looks really complex.
we need to clearly define what is expected in report, method, and why index is necessary like (why not use something else like an auto generated id from the webapp)
there are many moving parts, in services, packages in 20_services, but also in system techniques.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just added an id to track the iteration on a method

Copy link
Member Author

Choose a reason for hiding this comment

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

replaced usage a method_id to report_id (they were the same value)

Copy link
Member Author

Choose a reason for hiding this comment

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

To use report_id effectively in reports and method_id where we need to identify the method

"report_data.identifier" string => "${report_data.rule_id}@@${report_data.directive_id}@@${report_data.report_id_r}";

methods:
"${report_id}" usebundle => rudder_method_id_reset;
debug::
"${report_data.method_id}" usebundle => dump_reporting_context;
classes:
"pass1" expression => "any";
}

bundle agent rudder_reporting_context(d_id, r_id, t_name)
Expand Down Expand Up @@ -579,12 +583,27 @@ bundle agent dump_reporting_context
report_id_r = ${report_data.report_id_r}
report_id = ${report_data.report_id}
method_id = ${report_data.method_id}
index = ${report_data.index}
}";
}

bundle agent clean_method_reporting_context
{
vars:
"report_data.index" int => "0";
"report_data.component_name" string => "";
"report_data.component_key" string => "";
"report_data.identifier" string => "";
"report_data.report_id_r" string => "";
"report_data.report_id" string => "";
"report_data.method_id" string => "";
}


bundle agent clean_reporting_context
{
vars:
"report_data.index" int => "0";
"report_data.component_name" string => "";
"report_data.component_key" string => "";
"report_data.technique_name" string => "";
Expand Down Expand Up @@ -897,6 +916,7 @@ bundle agent rudder_method_id_reset() {
vars:
"method_id_unique.value" string => "1";
"method_id_unique.stack" slist => {};
"method_id_unique.report_stack" slist => {};
}

# You must call pop_method_id later to remove it.
Expand All @@ -907,13 +927,17 @@ bundle agent method_id_push(method_id)
# this must be evaluated exactly only once
"canon_method_id" string => canonify("${method_id}");
pass3::
"old_value" string => "${report_data.method_id}";
"old_value" string => "${report_data.method_id}";
"old_report" string => "${report_data.report_id}";
# copy the full slist but disable convergence detection
"stack" slist => sublist("method_id_unique.stack", "head", "99999");
"stack" slist => sublist("method_id_unique.stack", "head", "99999");
"report_stack" slist => sublist("method_id_unique.report_stack", "head", "99999");
# push the old value to the stack
"method_id_unique.stack" slist => { "${old_value}", @{stack} };
"method_id_unique.stack" slist => { "${old_value}", @{stack} };
"method_id_unique.report_stack" slist => { "${old_report}", @{report_stack} };
# set new value
"report_data.method_id" string => "${old_value}_${canon_method_id}";
"report_data.report_id" string => "${old_report}_${canon_method_id}";

classes:
"pass3" expression => "pass2";
Expand All @@ -933,16 +957,18 @@ bundle agent method_id_pop()
!pass1::
"stack_len" int => length("method_id_unique.stack");
"method_id" string => nth("method_id_unique.stack", "0");
"report_id" string => nth("method_id_unique.report_stack", "0");

# this must be evaluated exactly only once
pass2::
# compute stack length minus 1
"new_len_float" string => eval("${stack_len}-1", "math", "infix");
"new_len" string => format("%d", "${new_len_float}");
"new_len_float" int => int(eval("${stack_len}-1", "math", "infix"));
# remove first value
"method_id_unique.stack" slist => sublist("method_id_unique.stack", "tail", "${new_len}");
"method_id_unique.stack" slist => sublist("method_id_unique.stack", "tail", "${new_len}");
"method_id_unique.report_stack" slist => sublist("method_id_unique.report_stack", "tail", "${new_len}");
# set new value
"report_data.method_id" string => "${method_id}";
"report_data.report_id" string => "${report_id}";

classes:
"pass3" expression => "pass2";
Expand All @@ -954,6 +980,9 @@ bundle agent method_id_pop()
"empty_stack" expression => islessthan("${stack_len}", "0");

methods:
pass1.!pass2::
"${report_data.method_id}" usebundle => _classes_cancel("${report_data.report_id}");

pass3.empty_stack::
"${report_data.method_id}" usebundle => _abort("BUG in method-id stack", "pop_method_id was called more times than push_method_id. Stopping immediately to prevent any unwanted behavior.");

Expand Down