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

"[email protected]" <[email protected]> Fri, 14 Jul 2023 02:54:51 -0700 (PDT)
Newsgroups gmane.comp.sysutils.cfengine.general
Message-ID <[email protected]>
Many thanks, NIck.  Appreciated.

No we're not running with inform as default.   So that part of my message 
was not as considered as it should have been, and took us down a 
cul-de-sac.  Apologies.

Nevertheless, when we run cf-agent manually, we habitually run with "-I".  
I suppose this qualifies as local convention.

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!

-- David Lee


On Thursday, 13 July 2023 at 17:27:50 UTC+1 [email protected] wrote:

> I had a recollection from several years ago that a "files:" promise could 
> take an attribute: 
>
>    - inform => "false" 
>
> Is my memory playing tricks? I've just tried it and got: 
>
>    - Unknown attribute 'inform' for promise type 'files' 
>
> Yes, probably a cosmic ray has flipped a bit in your memory. 
>
> There is a promise level inform attribute, but, it's not for files it's 
> for commands. 
>
> Here is a fun snippet, show the promise types that have an attribute of 
> inform. 
>
> exec 2>&1
> cf-promises --syntax-description json | jq '.promiseTypes | to_entries[] | select(.value.attributes.inform != null) | .key'
> :
>
>
> "commands"
>
> It's a relatively recent addition, introduced in 3.15.0 (2019). 
>
>
> https://docs.cfengine.com/docs/3.21/reference-promise-types-commands.html#inform 
>
> Background. We have been working our way up from 3.10 to 3.15. Now I'm 
> trying 3.18. Suddenly one of our promises has changed from producing a 
> single diagnostic line for the file: 
>
>
>    - info: Edit file '…' 
>
> to two diagnostic lines for each and every line changed in the file. What 
> pushes this over the acceptability boundary for us is that this is a local 
> "state" file, which we deliberately empty and re-populate with 400-500 
> lines each and every run of "cf-agent" (so 800-1,000 diagnostic lines every 
> run of cf-agent). 
>
> What I ideally wish to do is that apply something like "inform => false" 
> to that single promise (with all other promises continuing to show their 
> more modest diagnostic lines). 
>
> So… is my (supposed) memory of a per-promise "inform => false" (or 
> similar) playing mind-games and tricks on me? Or was there once such an 
> attribute? (Maybe even 15 years ago when, at another place, I had been 
> using CFE version 2!) Or, even better, is there such a per-promise 
> attribute, but I simply haven't found it? 
>
> Yes, the inform logging became more specific. It's not expected that 
> *each* execution of cf-agent is done with inform logging, generally 
> that's reserved for manual runs or specific cases. As a general rule there 
> is an expectation that a regularly scheduled execution of cf-agent will 
> produce no output unless there was some problem. 
>
> action bodies can specify log_level (
> https://docs.cfengine.com/docs/3.21/reference-promise-types.html#log_level) 
> and report_level (
> https://docs.cfengine.com/docs/3.21/reference-promise-types.html#report_level). 
> log_level influences what is sent to syslog and report_level influences 
> standard output. These are useful for *increasing*, not decreasing the 
> level of output from the global default. So, if you ran cf-agent with no 
> log level specified you could for a single promise increase it's level to 
> inform for example, but if you run cf-agent --log-level inform you could 
> not reduce an individual promise log level to error. 
>
> Here is a small example to illustrate the behavior: 
> Listing 1: Example Policy
>
> bundle agent __main__{
>     methods:
>       "init";
>       "example";}bundle agent init{
>   files:
>     "/tmp/[1-3].txt"
>       delete => default:tidy,
>       action => default:report_level_x( "error" );}bundle agent example{
>   files:
>     "/tmp/1.txt"
>       content => "default report level";
>
>     "/tmp/2.txt"
>       content => "promise specific inform report level",
>       action => default:report_level_x( "inform" );
>
>     "/tmp/3.txt"
>       content => "promise specific verbose report level",
>       action => default:report_level_x( "verbose" );
>
>
>   reports:
>     "/tmp/1.txt" printfile => default:cat( "$(this.promiser)" );
>     "/tmp/2.txt" printfile => default:cat( "$(this.promiser)" );
>     "/tmp/3.txt" printfile => default:cat( "$(this.promiser)" );
> }body action report_level_x( x ){
>     report_level => "$(x)";}
>
>
> # cf-agent --no-lock --file /tmp/example.cf
>     info: Created file '/tmp/2.txt', mode 0600
>     info: Updated file '/tmp/2.txt' with content 'promise specific inform report level'
>  verbose: P: .........................................................
>  verbose: P: BEGIN promise 'promise_cfengine3_kw9dYH_25' of type "files" (pass 1)
>  verbose: P:    Promiser/affected object: '/tmp/3.txt'
>  verbose: P:    Part of bundle: example
>  verbose: P:    Base context class: any
>  verbose: P:    Stack path: /default/main/methods/'example'/default/example/files/'/tmp/3.txt'[1]
>  verbose: Using literal pathtype for '/tmp/3.txt'
>  verbose: No mode was set, choose plain file default 0600
>  verbose: Additional promise info: source path '/home/nickanderson/org/roam/daily/work/cfengine3-kw9dYH' at line 25
>     info: Created file '/tmp/3.txt', mode 0600
>  verbose: Replacing '/tmp/3.txt' with content 'promise specific verbose report level'
>  verbose: Additional promise info: source path '/home/nickanderson/org/roam/daily/work/cfengine3-kw9dYH' at line 25
>     info: Updated file '/tmp/3.txt' with content 'promise specific verbose report level'
>  verbose: Additional promise info: source path '/home/nickanderson/org/roam/daily/work/cfengine3-kw9dYH' at line 25
>  verbose: files promise '/tmp/3.txt' repaired
>  verbose: A: Promise REPAIRED
>  verbose: P: END files promise (/tmp/3.txt)
> R: /tmp/1.txt
> R: default report level
> R: /tmp/2.txt
> R: promise specific inform report level
> R: /tmp/3.txt
> R: promise specific verbose report level
>  verbose: P: .........................................................
>  verbose: P: BEGIN promise 'promise_cfengine3_kw9dYH_25' of type "files" (pass 2)
>  verbose: P:    Promiser/affected object: '/tmp/3.txt'
>  verbose: P:    Part of bundle: example
>  verbose: P:    Base context class: any
>  verbose: P:    Stack path: /default/main/methods/'example'/default/example/files/'/tmp/3.txt'[1]
>  verbose: Using literal pathtype for '/tmp/3.txt'
>  verbose: P: .........................................................
>  verbose: P: BEGIN promise 'promise_cfengine3_kw9dYH_25' of type "files" (pass 3)
>  verbose: P:    Promiser/affected object: '/tmp/3.txt'
>  verbose: P:    Part of bundle: example
>  verbose: P:    Base context class: any
>  verbose: P:    Stack path: /default/main/methods/'example'/default/example/files/'/tmp/3.txt'[1]
>  verbose: Using literal pathtype for '/tmp/3.txt'
>
> Then, when run again with inform as the default, we can see that the file 
> deletion still comes out as info, it's not suppressed by setting it's 
> report_level to error because this attribute can only *increase* the 
> verbosity. 
>
>
> # cf-agent --no-lock --log-level inform --file /tmp/example.cf
>     info: Deleted file '/tmp/1.txt'
>     info: Deleted file '/tmp/2.txt'
>     info: Deleted file '/tmp/3.txt'
>     info: Created file '/tmp/1.txt', mode 0600
>     info: Updated file '/tmp/1.txt' with content 'default report level'
>     info: Created file '/tmp/2.txt', mode 0600
>     info: Updated file '/tmp/2.txt' with content 'promise specific inform report level'
>  verbose: P: .........................................................
>  verbose: P: BEGIN promise 'promise_cfengine3_JFnoIJ_25' of type "files" (pass 1)
>  verbose: P:    Promiser/affected object: '/tmp/3.txt'
>  verbose: P:    Part of bundle: example
>  verbose: P:    Base context class: any
>  verbose: P:    Stack path: /default/main/methods/'example'/default/example/files/'/tmp/3.txt'[1]
>  verbose: Using literal pathtype for '/tmp/3.txt'
>  verbose: No mode was set, choose plain file default 0600
>  verbose: Additional promise info: source path '/home/nickanderson/org/roam/daily/work/cfengine3-JFnoIJ' at line 25
>     info: Created file '/tmp/3.txt', mode 0600
>  verbose: Replacing '/tmp/3.txt' with content 'promise specific verbose report level'
>  verbose: Additional promise info: source path '/home/nickanderson/org/roam/daily/work/cfengine3-JFnoIJ' at line 25
>     info: Updated file '/tmp/3.txt' with content 'promise specific verbose report level'
>  verbose: Additional promise info: source path '/home/nickanderson/org/roam/daily/work/cfengine3-JFnoIJ' at line 25
>  verbose: files promise '/tmp/3.txt' repaired
>  verbose: A: Promise REPAIRED
>  verbose: P: END files promise (/tmp/3.txt)
> R: /tmp/1.txt
> R: default report level
> R: /tmp/2.txt
> R: promise specific inform report level
> R: /tmp/3.txt
> R: promise specific verbose report level
>  verbose: P: .........................................................
>  verbose: P: BEGIN promise 'promise_cfengine3_JFnoIJ_25' of type "files" (pass 2)
>  verbose: P:    Promiser/affected object: '/tmp/3.txt'
>  verbose: P:    Part of bundle: example
>  verbose: P:    Base context class: any
>  verbose: P:    Stack path: /default/main/methods/'example'/default/example/files/'/tmp/3.txt'[1]
>  verbose: Using literal pathtype for '/tmp/3.txt'
>  verbose: P: .........................................................
>  verbose: P: BEGIN promise 'promise_cfengine3_JFnoIJ_25' of type "files" (pass 3)
>  verbose: P:    Promiser/affected object: '/tmp/3.txt'
>  verbose: P:    Part of bundle: example
>  verbose: P:    Base context class: any
>  verbose: P:    Stack path: /default/main/methods/'example'/default/example/files/'/tmp/3.txt'[1]
>  verbose: Using literal pathtype for '/tmp/3.txt'
>
> So, are you running with --inform by default, if so, why? 
>

-- 
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/d9a36684-ef99-465d-8488-8ba961e54370n%40googlegroups.com.