if_elapsed + randomint as argument.

27 views
Skip to first unread message

Vladislav Zhivotnev

unread,
May 20, 2015, 10:23:07 AM5/20/15
to help-c...@googlegroups.com
Hi. We have huge directory, which we wanna to sync from policyhub not often then 1 hour, but also with delay after that hout (to split all hosts in this hour to random time). 

I have in lib.cf this: 
body action if_elapsed(x)
{
      ifelapsed => "$(x)";
      expireafter => "$(x)";
}



Also i had in promises.cf this: 
vars: 
"delay" int => "60"; 

files:
"/path/to/file":
comment => "...",
action            => if_elapsed($(delay)),
copy_from => ...;

That worked perfectly (but all hosts synced this directory in one 10minutes interval). 

So i decided to replace
"delay" int => "60"; 
with
"delay" int => randomint(30,90); 

In theory in this way we should have some randomization at if_elapsed and oveload once per hour should dissapear. 
In practice i have "/path/to/file" executed 9/10 times (due to tcpdump). 

When "/path/to/file" not executed, i can at cf-agent -Iv output strings like:
Nothing promised here [last.domain.files.action.ifelapsed.expir] (YY/78 minutes elapsed)
with always random integer instead of YY.

When i using static integer - YY replaced with number of minutes, which looks like time from last execution of "/path/to/file" input. 

Probably, it s a bug. 

Anyway - are there another methods to do such logic? Once per hour/halfour + random delay for only one input. 

Thanks.

Nick Anderson

unread,
May 20, 2015, 10:25:32 AM5/20/15
to help-c...@googlegroups.com
On 05/20/2015 09:23 AM, Vladislav Zhivotnev wrote:
> Anyway - are there another methods to do such logic? Once per
> hour/halfour + random delay for only one input.

Check out select_class
https://docs.cfengine.com/latest/reference-promise-types-classes.html#select_class

You can use it to divide your infrastructure and then base the updates
on time intervals plus one of the classes from select_class.

Neil Watson

unread,
May 20, 2015, 10:26:22 AM5/20/15
to help-c...@googlegroups.com
Look at splaytime to distribute agents across your cf-execd interval.

Also, look at dist classes:
https://docs.cfengine.com/docs/master/reference-promise-types-classes.html#dist

--
Neil H Watson
Sr. Partner, Architecture and Infrastructure
CFEngine reporting: https://github.com/evolvethinking/delta_reporting
CFEngine policy: https://github.com/evolvethinking/evolve_cfengine_freelib
CFEngine and vim: https://github.com/neilhwatson/vim_cf3
CFEngine support: http://evolvethinking.com

Vladislav Zhivotnev

unread,
May 20, 2015, 10:29:42 AM5/20/15
to help-c...@googlegroups.com, cfen...@watson-wilson.ca
Nah, it was first, which i looked. 

It can be set per-input. 

I need to run only one input per hour + splaytime 60 (for example). 
But agent still need to run once per 10 mins + splaytime 10. 

среда, 20 мая 2015 г., 17:26:22 UTC+3 пользователь Neil Watson написал:

Vladislav Zhivotnev

unread,
May 20, 2015, 10:30:37 AM5/20/15
to help-c...@googlegroups.com, cfen...@watson-wilson.ca
s/It can be set per-input. /It can't be set per-input. /



среда, 20 мая 2015 г., 17:29:42 UTC+3 пользователь Vladislav Zhivotnev написал:

Vladislav Zhivotnev

unread,
May 20, 2015, 10:35:51 AM5/20/15
to help-c...@googlegroups.com
If i will use random classes (dist classes, or randomint based classes) - there will be no warranty, that input will executed at all. 
Manual splitting hosts to groups+time periods is sux, we have too lot of servers and classes to maintain this split. 

среда, 20 мая 2015 г., 17:25:32 UTC+3 пользователь Nick Anderson написал:

Nick Anderson

unread,
May 20, 2015, 10:41:24 AM5/20/15
to help-c...@googlegroups.com
On 05/20/2015 09:35 AM, Vladislav Zhivotnev wrote:
> Manual splitting hosts to groups+time periods is sux, we have too lot of
> servers and classes to maintain this split.

select class will automatically select one of the available options
deterministically.

classes:
"selection" select_class => { "one", "two", "three" "four" };

reports:
one.Q1::
"1/4th of hosts should report this during the first 15 minutes of
every hour";



Vladislav Zhivotnev

unread,
May 20, 2015, 10:50:27 AM5/20/15
to help-c...@googlegroups.com
Is select_class static on client? 
I mean, that if server choosed class "one" - will it always choose this class in future? 

If not - than we'll have hosts, where one.Q1, two.Q2, three.Q3, four.Q4 will never match (or match too rare). 

среда, 20 мая 2015 г., 17:41:24 UTC+3 пользователь Nick Anderson написал:

Neil Watson

unread,
May 20, 2015, 10:58:46 AM5/20/15
to help-c...@googlegroups.com
On Wed, May 20, 2015 at 07:50:26AM -0700, Vladislav Zhivotnev wrote:
>
>
> Is select_class static on client? 
> I mean, that if server choosed class "one" - will it always choose this
> class in future? 

Yes, that is what deterministic means.

Nick Anderson

unread,
May 20, 2015, 11:01:25 AM5/20/15
to help-c...@googlegroups.com
On 05/20/2015 09:50 AM, Vladislav Zhivotnev wrote:
> Is select_class static on client?
> I mean, that if server choosed class "one" - will it always choose this
> class in future?

Yes, so long as the list of possible class options does not change.

If you added a "five" for example, they would all rebalance.

Neil Watson

unread,
May 20, 2015, 11:12:13 AM5/20/15
to help-c...@googlegroups.com
On Wed, May 20, 2015 at 10:58:43AM -0400, Neil Watson wrote:
>On Wed, May 20, 2015 at 07:50:26AM -0700, Vladislav Zhivotnev wrote:
>>
>>
>> Is select_class static on client? 
>> I mean, that if server choosed class "one" - will it always choose this
>> class in future? 
>
>Yes, that is what deterministic means.

FYI, IIRC the seed for the random selection is based on the hostname.

Vladislav Zhivotnev

unread,
May 20, 2015, 12:03:05 PM5/20/15
to help-c...@googlegroups.com, cfen...@watson-wilson.ca
You are genius all! 

Problems seems resolved. 

Great thanks!
Reply all
Reply to author
Forward
0 new messages