Re: per-promise 'inform => "false"'?

"[email protected]" <[email protected]> Thu, 31 Aug 2023 06:34:51 -0700 (PDT)
Newsgroups gmane.comp.sysutils.cfengine.general
Message-ID <[email protected]>
Thanks, Nick!

I was unaware of the "report_to_file" functionality on "reports::".  That's 
good to know.  I've just tried it and it seems to work very well.   (As you 
highlight, it's basically an append rather than a rewrite, so we need to 
re-create it.  But that's OK.)  So I now have a local MR awaiting review.

Yes, I certainly take the point about being more selective in the 
contents!  But that's a different topic, although I might try to raise it 
on the coat-tails of this MR.

Enterprise reporting?  Well, for ages I've been gently trying to push 
Enterprise here. A few months ago, we started pursuing it, but the cost, 
even after some negotiation was going to be prohibitive.  (In contrast to 
technical aspects of CFE, this aspect is out of my hands.)

Thanks again.

-- David Lee

On Friday, 14 July 2023 at 16:08:47 UTC+1 [email protected] wrote:

> For reference here is the problematic part (bundle slightly reduced here) 
> where we dump all classes, several hundred of them, into a state file: 
>
> bundle agent dls_reports { vars: "allclasses" slist => 
> classesmatching(".*"); 
>
> files: cfengine_3:: "$(sys.workdir)/state/allclasses.txt" create => 
> "true", perms => mog("0644", "root", "root"), edit_defaults => empty, 
> edit_line => insert_lines(@(allclasses)); } 
>
> ------------------------------
>
> Try that in a test framework. Up to and including version 3.15.5, 
> "cf-agent -I …" (manually at the console) is decently quiet at this point 
> (a single diagnostic line telling us the file has been edited). But at 3.18 
> its output swamps us! 
>
> Manual executions with -K and -I are super common, it's definitely 
> embedded in my muscle memory. 
>
> First thing that I notice in that policy: since you are managing the full 
> file content, I think you should use mustache or the content attribute 
> instead of edit_line, any time you are using edit_default => empty it's 
> worth re-evaluating the choice and considering something that was designed 
> for full file management. 
>
> Instead of recording ALL classes you could be more selective and perhaps 
> filter out classes that change with each run, like time_based classes. 
> Listing 1: Example Policy
>
> bundle agent __main__{
>     
> vars:
>        "allclasses" slist => classesmatching(".*")
>
> ;
>        "time_based_classes" slist => classesmatching(".*", "time_based");
>        "allclasses_excluding_unstable"
>          with => concat( "(", join( "|", time_based_classes), ")" ),
>          slist => filter( "$(with)",         # Filter
>                           "allclasses",      # source list
>                           "true",            # is regex?
>                           "true",            # invert result?
>                           inf );             # max return
>
>     reports:
>       "allclasses has $(with) elements" with => length( "allclasses" );
>       "allclasses_excluding_unstable has $(with) elements" with => length( "allclasses_excluding_unstable" );
> }
>
> Another option would be to use reports with report_to_file *instead* of 
> files promises for managing the content of a file, you would have to be 
> sure to cull the file first or it's basically a log. 
>
> Of course if you use a files promise and run with inform you will get 
> noise about it's deletion. 
>
> bundle agent __main__
>
> {
>   vars:
>       "allclasses" slist => classesmatching(".*")
>
> ;
>       "time_based_classes" slist => classesmatching(".*", "time_based");
>
>       "allclasses_excluding_unstable"
>         with => concat( "(", join( "|", time_based_classes), ")" ),
>         slist => sort( filter( "$(with)",         # Filter
>                                "allclasses",      # source list
>                                "true",            # is regex?
>                                "true",            # invert result?
>                                inf ),             # max return
>                        "lex" );
>
>   files:
>       "/tmp/allclasses_excluding_unstable.txt"
>         delete => default:tidy,
>         handle => "cull_allclasses_statefile";
>
>   reports:
>       "allclasses has $(with) elements" with => length( "allclasses" );
>       "allclasses_excluding_unstable has $(with) elements" with => length( "allclasses_excluding_unstable" );
>
>       "$(allclasses_excluding_unstable)"
>         report_to_file => "/tmp/allclasses_excluding_unstable.txt",
>         depends_on => { "cull_allclasses_statefile" };}
>
>
>     info: Deleted file '/tmp/allclasses_excluding_unstable.txt'
> R: allclasses has 281 elements
> R: allclasses_excluding_unstable has 258 elements
>
> So, you could use commands where you can suppress inform. 
>
> bundle agent __main__
>
> {
>   vars:
>       "allclasses" slist => classesmatching(".*")
>
> ;
>       "time_based_classes" slist => classesmatching(".*", "time_based");
>
>       "allclasses_excluding_unstable"
>         with => concat( "(", join( "|", time_based_classes), ")" ),
>         slist => sort( filter( "$(with)",         # Filter
>                                "allclasses",      # source list
>                                "true",            # is regex?
>                                "true",            # invert result?
>                                inf ),             # max return
>                        "lex" );
>
>   commands:
>       "/bin/rm /tmp/allclasses_excluding_unstable.txt"
>         inform => "false",
>         contain => silent,
>         handle => "cull_allclasses_statefile",
>         if => fileexists( "/tmp/allclasses_excluding_unstable.txt" );
>
>   reports:
>       "allclasses has $(with) elements" with => length( "allclasses" );
>       "allclasses_excluding_unstable has $(with) elements" with => length( "allclasses_excluding_unstable" );
>
>       "$(allclasses_excluding_unstable)"
>         report_to_file => "/tmp/allclasses_excluding_unstable.txt",
>         depends_on => { "cull_allclasses_statefile" };}
>
>
> R: allclasses has 281 elements
> R: allclasses_excluding_unstable has 258 elements
>
> It would be nice to be able to set the log level per promise and not just 
> increase it, I think there is a ticket somewhere but I couldn't find in a 
> couple minutes of searching. 
>
> And, finally, instead of managing that state file, you could get 
> Enterprise reporting :D. 
>

-- 
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/8fec2139-ad1c-44c4-942a-36f8e71ea6a1n%40googlegroups.com.