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 #25936: Port condition_from methods to log v4+ #1438

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions tree/30_generic_methods/condition_from_expression.cf
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,7 @@
bundle agent condition_from_expression(condition, expression)
{
vars:
"old_class_prefix" string => canonify("condition_from_expression_${condition}");
"args" slist => { "${condition}", "${expression}" };
"report_param" string => join("_", args);
"full_class_prefix" string => canonify("condition_from_expression_${report_param}");
"class_prefix" string => string_head("${full_class_prefix}", "1000");
"class_prefix" string => canonify("condition_from_expression_${condition}");

classes:
"${condition}_true" expression => "${expression}",
Expand All @@ -84,13 +80,11 @@ bundle agent condition_from_expression(condition, expression)
scope => "namespace";

methods:
"success" usebundle => _classes_success("${old_class_prefix}");
"success" usebundle => _classes_success("${class_prefix}");
"${report_data.method_id}" usebundle => _classes_success("${report_data.method_id}");
"${report_data.method_id}" usebundle => _classes_success("${class_prefix}");

"report" usebundle => _log_v3("Create the condition ${condition}_{true,false} with ${expression}", "${condition}", "${old_class_prefix}", "${class_prefix}", @{args});
reports:
"Condition ${condition}_true defined"
if => "${condition}_true";
"Condition ${condition}_false defined"
if => "${condition}_false";
"${report_data.method_id}" usebundle => log_rudder_v4("${condition}", "Condition ${condition}_true was defined", ""),
if => "${condition}_true";
"${report_data.method_id}" usebundle => log_rudder_v4("${condition}", "Condition ${condition}_false was defined", ""),
if => "${condition}_false";
}
27 changes: 13 additions & 14 deletions tree/30_generic_methods/condition_from_expression_persistent.cf
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,23 @@
bundle agent condition_from_expression_persistent(condition, expression, duration)
{
vars:
"old_class_prefix" string => canonify("condition_from_expression_persistent_${condition}");
"args" slist => { "${condition}", "${expression}", "${duration}" };
"report_param" string => join("_", args);
"full_class_prefix" string => canonify("condition_from_expression_persistent_${report_param}");
"class_prefix" string => string_head("${full_class_prefix}", "1000");
"class_prefix" string => canonify("condition_from_expression_persistent_${condition}");

classes:
"${condition}_true" expression => "${expression}",
persistence => "${duration}",
scope => "namespace";
"${condition}_true" expression => "${expression}",
persistence => "${duration}",
scope => "namespace";

"${condition}_false" expression => "!(${expression})",
persistence => "${duration}",
scope => "namespace";
"${condition}_false" expression => "!(${expression})",
persistence => "${duration}",
scope => "namespace";

methods:
"success" usebundle => _classes_success("${old_class_prefix}");
"success" usebundle => _classes_success("${class_prefix}");
"${report_data.method_id}" usebundle => _classes_success("${report_data.method_id}");
"${report_data.method_id}" usebundle => _classes_success("${class_prefix}");

"report" usebundle => _log_v3("Create the persistent condition ${condition}_{true,false} with ${expression}", "${condition}", "${old_class_prefix}", "${class_prefix}", @{args});
"${report_data.method_id}" usebundle => log_rudder_v4("${condition}", "The condition ${condition}_true was defined and will persist for ${duration} minutes", ""),
if => "${expression}";
"${report_data.method_id}" usebundle => log_rudder_v4("${condition}", "The condition ${condition}_false was defined and will persist for ${duration} minutes", ""),
if => "!(${expression})";
}
22 changes: 10 additions & 12 deletions tree/30_generic_methods/condition_from_variable_existence.cf
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,21 @@
bundle agent condition_from_variable_existence(condition, variable_name)
{
vars:
"old_class_prefix" string => canonify("condition_from_variable_existence_${condition}");
"args" slist => { "${condition}", "${variable_name}" };
"report_param" string => join("_", args);
"full_class_prefix" string => canonify("condition_from_variable_existence_${report_param}");
"class_prefix" string => string_head("${full_class_prefix}", "1000");
"class_prefix" string => canonify("condition_from_variable_existence_${condition}");

classes:

"${condition}_true" expression => isvariable("${variable_name}"),
scope => "namespace";
scope => "namespace";

"${condition}_false" not => isvariable("${variable_name}"),
scope => "namespace";
"${condition}_false" not => isvariable("${variable_name}"),
scope => "namespace";

methods:
"success" usebundle => _classes_success("${old_class_prefix}");
"success" usebundle => _classes_success("${class_prefix}");
"${report_data.method_id}" usebundle => _classes_success("${report_data.method_id}");
"${report_data.method_id}" usebundle => _classes_success("${class_prefix}");

"report" usebundle => _log_v3("Create the condition ${condition}_{true,false} from the existence of variable ${variable_name}", "${condition}", "${old_class_prefix}", "${class_prefix}", @{args});
"${report_data.method_id}" usebundle => log_rudder_v4("${condition}", "The condition ${condition}_true was defined as the variable ${variable_name} was defined", ""),
if => isvariable("${variable_name}");
"${report_data.method_id}" usebundle => log_rudder_v4("${condition}", "The condition ${condition}_false was defined as the variable ${variable_name} was undefined", ""),
not => isvariable("${variable_name}");
}
39 changes: 22 additions & 17 deletions tree/30_generic_methods/condition_from_variable_match.cf
Original file line number Diff line number Diff line change
Expand Up @@ -55,37 +55,42 @@
bundle agent condition_from_variable_match(condition, variable_name, expected_match)
{
vars:
"old_class_prefix" string => canonify("condition_from_variable_match_${condition}");
"args" slist => { "${condition}", "${variable_name}", "${expected_match}" };
"report_param" string => join("_", args);
"full_class_prefix" string => canonify("condition_from_variable_match_${report_param}");
"class_prefix" string => string_head("${full_class_prefix}", "1000");
"class_prefix" string => canonify("condition_from_variable_match_${condition}");

classes:
"pass1" expression => "any";
"pass2" expression => "pass1";
"pass3" expression => "pass2";

pass2::
"var_exists" expression => isvariable("${variable_name}");
"var_exists" expression => isvariable("${variable_name}");

"${condition}_true" and => {regcmp("${expected_match}", "${${variable_name}}"), "var_exists"},
scope => "namespace";
scope => "namespace";

"${condition}_false" or => {"!${condition}_true", "!var_exists"},
scope => "namespace";
scope => "namespace";

methods:
pass3::
"failure" usebundle => _classes_failure("${old_class_prefix}"),
ifvarclass => "!var_exists";
"failure" usebundle => _classes_failure("${class_prefix}"),
ifvarclass => "!var_exists";
"${report_data.method_id}" usebundle => _classes_failure("${report_data.method_id}"),
not => "var_exists";
"${report_data.method_id}" usebundle => _classes_failure("${class_prefix}"),
not => "var_exists";

"success" usebundle => _classes_success("${old_class_prefix}"),
ifvarclass => "var_exists";
"success" usebundle => _classes_success("${class_prefix}"),
ifvarclass => "var_exists";
"${report_data.method_id}" usebundle => _classes_success("${report_data.method_id}"),
if => "var_exists";
"${report_data.method_id}" usebundle => _classes_success("${class_prefix}"),
if => "var_exists";

"report" usebundle => _log("Create the condition ${condition}_{true,false} from the result of regex: /${expected_match}/ on variable ${variable_name}", "${old_class_prefix}", "${class_prefix}", @{args});
"${report_data.method_id}" usebundle => log_rudder_v4("${condition}","Condition ${condition}_true was defined as the variable ${variable_name} matched the expected pattern", ""),
if => and( regcmp("${expected_match}", "${${variable_name}}"),
"var_exists"
);
"${report_data.method_id}" usebundle => log_rudder_v4("${condition}", "Condition ${condition}_false was defined as the variable ${variable_name} did not match the expected pattern", ""),
if => and( "var_exists",
not(regcmp("${expected_match}", "${${variable_name}}"))
);
"${report_data.method_id}" usebundle => log_rudder_v4("${condition}", "Condition ${condition}_false was defined as the variable ${variable_name} was undefined", ""),
not => "var_exists";
}
48 changes: 21 additions & 27 deletions tree/30_generic_methods/condition_once.cf
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,22 @@
bundle agent condition_once(condition)
{
vars:
"c_condition" string => canonify("${condition}");
"old_class_prefix" string => canonify("condition_once_${condition}");
"args" slist => { "${condition}" };
"report_param" string => join("_", args);
"full_class_prefix" string => canonify("condition_once_${report_param}");
"class_prefix" string => string_head("${full_class_prefix}", "1000");
"c_condition" string => canonify("${condition}");
"class_prefix" string => canonify("condition_once_${condition}");

classes:
"reserved" expression => strcmp("${reserve[1]}", "ok");
"already_set" expression => strcmp("${reserve[1]}", "failed_set");
"reserved" expression => strcmp("${reserve[1]}", "ok");
"already_set" expression => strcmp("${reserve[1]}", "failed_set");
"already_reserved" expression => strcmp("${reserve[1]}", "failed_reserved");
"set_ok" expression => strcmp("${set[1]}", "ok");
"set_ok" expression => strcmp("${set[1]}", "ok");

"${c_condition}" expression => "set_ok",
scope => "namespace";

"should_report" expression => "${report_data.should_report}";
"pass3" expression => "pass2";
"pass2" expression => "pass1";
"pass1" expression => "any";
"pass3" expression => "pass2";
"pass2" expression => "pass1";
"pass1" expression => "any";

methods:
"reserve the flag" usebundle => reserve_flag("condition_once_${c_condition}"),
Expand All @@ -78,27 +74,25 @@ bundle agent condition_once(condition)
useresult => "set";

set_ok::
"success" usebundle => _classes_repaired("${old_class_prefix}");
"success" usebundle => _classes_repaired("${class_prefix}");
"${report_data.method_id}" usebundle => _classes_repaired("${report_data.method_id}");
"${report_data.method_id}" usebundle => _classes_repaired("${class_prefix}");

pass3.reserved.!set_ok::
"failure" usebundle => _classes_failure("${old_class_prefix}");
"failure" usebundle => _classes_failure("${class_prefix}");
"${report_data.method_id}" usebundle => _classes_failure("${report_data.method_id}");
"${report_data.method_id}" usebundle => _classes_failure("${class_prefix}");

pass3.(already_set|already_reserved)::
"success" usebundle => _classes_success("${old_class_prefix}");
"success" usebundle => _classes_success("${class_prefix}");
"${report_data.method_id}" usebundle => _classes_success("${report_data.method_id}");
"${report_data.method_id}" usebundle => _classes_success("${class_prefix}");

pass3.already_reserved::
"disable_reporting_${class_prefix}"
usebundle => disable_reporting;
"failure" usebundle => _classes_failure("temp_${old_class_prefix}_warn");
"failure" usebundle => _classes_failure("temp_${class_prefix}_warn");
"report" usebundle => _log_v3("The '${c_condition}' condition was reserved but not set, this is unexpected", "${condition}", "temp_${old_class_prefix}_warn", "temp_${class_prefix}_warn", @{args});
"reenable_reporting_${class_prefix}"
usebundle => enable_reporting,
if => "should_report";
"disable_reporting_${class_prefix}" usebundle => disable_reporting;
"${report_data.method_id}" usebundle => _classes_failure("${class_prefix}");
"${report_data.method_id}" usebundle => _classes_failure("${report_data.method_id}");
"${report_data.method_id}" usebundle => log_rudder_v4("${c_condition}", "condition was reserved but not set, this is unexpected");
"reenable_reporting_${class_prefix}" usebundle => enable_reporting,
if => "should_report";

pass3::
"report" usebundle => _log_v3("Create the condition ${c_condition} once", "${condition}", "${old_class_prefix}", "${class_prefix}", @{args});
"${report_data.method_id}" usebundle => log_rudder_v4("${condition}", "Create the condition ${c_condition} once", "");
}
44 changes: 18 additions & 26 deletions tree/30_generic_methods/directory_absent.cf
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,22 @@
bundle agent directory_absent(path, recursive)
{
vars:
"old_class_prefix" string => canonify("directory_absent_${path}");

# don't rewrite the class prefix based on defaults
!pass1::
"args" slist => { "${path}", "${recursive}" };
"report_param" string => join("_", args);
"full_class_prefix" string => canonify("directory_absent_${report_param}");
"class_prefix" string => string_head("${full_class_prefix}", "1000");
"class_prefix" string => canonify("directory_absent_${path}");

defaults:
"recursive" string => "false", if_match_regex => "";
"recursive" string => "false", if_match_regex => "";

classes:
"is_recursive" expression => strcmp("true", "${recursive}");
"is_recursive" expression => strcmp("true", "${recursive}");

pass2::
"directory_exists_after" expression => isdir("${path}");
"path_exists_after" expression => fileexists("${path}");

any::
"pass3" expression => "pass2";
"pass2" expression => "pass1";
"pass1" expression => "any";
"pass3" expression => "pass2";
"pass2" expression => "pass1";
"pass1" expression => "any";

files:

Expand All @@ -64,34 +57,33 @@ bundle agent directory_absent(path, recursive)
delete => tidy,
file_select => all,
depth_search => recurse_with_base("inf"),
classes => classes_generic_two("${old_class_prefix}_inside", "${class_prefix}_inside");
classes => classes_generic_two("${report_data.method_id}_inside", "${class_prefix}_inside");

pass1::
"${path}/."
delete => tidy,
file_select => all,
classes => classes_generic_two("${old_class_prefix}", "${class_prefix}"),
ifvarclass => "!${class_prefix}_inside_error";
classes => classes_generic_two("${report_data.method_id}", "${class_prefix}"),
if => "!${report_data.method_id}_inside_error";

methods:

# If path was not empty, we need to trigger an error manually as the files promise will be kept
# Because of https://tracker.mender.io/browse/CFE-1570
pass3.directory_exists_after::
"fail_if_not_empty" usebundle => _classes_failure("${class_prefix}");
"clean_if_not_empty" usebundle => _classes_sanitize("${class_prefix}");

"fail_if_not_empty" usebundle => _classes_failure("${old_class_prefix}");
"clean_if_not_empty" usebundle => _classes_sanitize("${old_class_prefix}");
"${report_data.method_id}" usebundle => _classes_failure("${class_prefix}");
"${report_data.method_id}" usebundle => _classes_failure("${report_data.method_id}");
"${report_data.method_id}" usebundle => _classes_sanitize("${class_prefix}");
"${report_data.method_id}" usebundle => _classes_sanitize("${report_data.method_id}");

pass3::
# Use classes of the first promise when it failed
"copy_inside_error" usebundle => _classes_copy("${class_prefix}_inside", "${class_prefix}"),
ifvarclass => "${class_prefix}_inside_error";
"copy_inside_error" usebundle => _classes_copy("${old_class_prefix}_inside", "${old_class_prefix}"),
ifvarclass => "${old_class_prefix}_inside_error";
"${report_data.method_id}" usebundle => _classes_copy("${report_data.method_id}_inside", "${report_data.method_id}"),
if => "${report_data.method_id}_inside_error";
"${report_data.method_id}" usebundle => _classes_copy("${report_data.method_id}_inside", "${class_prefix}"),
if => "${report_data.method_id}_inside_error";

"report" usebundle => _log_v3("Remove directory ${path}", "${path}", "${old_class_prefix}", "${class_prefix}", @{args});
"${report_data.method_id}" usebundle => log_rudder_v4("${path}", "Remove directory ${path}", "");

reports:
pass3.info.path_exists_after.!directory_exists_after::
Expand Down