Skip to content

Commit

Permalink
fixup! Fixes #22088: make iterator report more independant
Browse files Browse the repository at this point in the history
Fixes #22088: make iterator report more independant
  • Loading branch information
VinceMacBuche committed Nov 17, 2022
1 parent a3ff2bc commit f7d1898
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tree/20_cfe_basics/common.cf
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ bundle agent call_method_classes(copy_to_prefix) {
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.report_id}", "${prefix}");
Expand Down
21 changes: 14 additions & 7 deletions tree/20_cfe_basics/log_rudder.cf
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ bundle agent _method_reporting_context_v4(c_name, c_key, report_id)
debug::
"${report_data.method_id}" usebundle => dump_reporting_context;
classes:
"pass1" expression => any;
"pass1" expression => any;
}

bundle agent rudder_reporting_context(d_id, r_id, t_name)
Expand Down Expand Up @@ -917,6 +917,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 @@ -927,13 +928,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 @@ -953,16 +958,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 Down

0 comments on commit f7d1898

Please sign in to comment.