Skip to content

Commit ee8cf76

Browse files
author
kylo
committed
Merge pull request #2013 from nfagerlund/fqdn_rand_redux
Docs: Explain the usage of fqdn_rand more effectively
2 parents a351bce + a85d6f3 commit ee8cf76

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/puppet/parser/functions/fqdn_rand.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
require 'digest/md5'
22

33
Puppet::Parser::Functions::newfunction(:fqdn_rand, :arity => -2, :type => :rvalue, :doc =>
4-
"Generates random numbers based on the node's fqdn. Generated random values
5-
will be a range from 0 up to and excluding n, where n is the first parameter.
6-
The second argument specifies a number or string to add to the seed and is optional.
4+
"Usage: `fqdn_rand(MAX, [SEED])`. MAX is required and must be a positive
5+
integer; SEED is optional and may be any number or string.
76
8-
Examples:
7+
Generates a random whole number greater than or equal to 0 and less than MAX,
8+
combining the `$fqdn` fact and the value of SEED for repeatable randomness.
9+
(That is, each node will get a different random number from this function, but
10+
a given node's result will be the same every time unless its hostname changes.)
911
10-
$random_number = fqdn_rand(30)
11-
$random_number_seeded = fqdn_rand(30,30)
12-
$random_number_seeded2 = fqdn_rand(30,'foo')") do |args|
12+
This function is usually used for spacing out runs of resource-intensive cron
13+
tasks that run on many nodes, which could cause a thundering herd or degrade
14+
other services if they all fire at once. Adding a SEED can be useful when you
15+
have more than one such task and need several unrelated random numbers per
16+
node. (For example, `fqdn_rand(30)`, `fqdn_rand(30, 'expensive job 1')`, and
17+
`fqdn_rand(30, 'expensive job 2')` will produce totally different numbers.)") do |args|
1318
max = args.shift.to_i
1419
seed = Digest::MD5.hexdigest([self['::fqdn'],args].join(':')).hex
1520
Puppet::Util.deterministic_rand(seed,max)

0 commit comments

Comments
 (0)