Subject: | sample rate is not sent to the statsd server |
I've been writing some tests and I believe that all non-unity sample
rates are not being sent to the server. I think the bug might be on line
127:
my $value = $data->{$stat};
..and I think that should be
my $value = $sampled_data->{$stat};
since $sampled_data is the hashref with munged value data.
In addition, I'm trying to understand this code (in _sample_data):
if ($sample_rate < 1) {
if (rand() <= $sample_rate) {
while (my ($stat, $value) = each %{ $data }) {
$sampled_data->{$stat} = sprintf "%s|@%s", $value,
$sample_rate;
}
}
}
If I understand this correctly, then I think it says that the sample
rate will only be added to the message SOME OF THE TIME, depending on
the value of rand() and $sample_rate. How can this be right?
Furthermore, since the assignment to the sampled_data hash also happens
in that block, the data never gets assigned.
Let's say I have a sample_rate of 0.1..then only 1 out of 10 times, you
will decide to append the @SAMPLE_RATE and assign it to the sampled_data
hash. Otherwise, the hash is empty and the module croaks when you try to
send. This seems wrong to me -- or at the very least the documentation
doesn't make any mention of this behavior.
Unless I'm misunderstanding the intent of this code, I would propose
always sending the sample rate value when it is provided by the caller,
as well as always sending the data.
Please let me know if anything in my report is unclear.
Thank You.