paulasmuth/fnordmetric — pull request #51 by efqdalton (2012-01-21 23:37:41+00:00)
Title: Progressive gauges doesn't work properly when a tick doesn't receive any incr. and is skipped

First of all, I want to say that this project looks great, and everyday I see that someone is doing something here to make it better, so congratulations!

Well, so I want to give a little help, so I just found a little bug, and I fixed that.

The problem is that when we are using a progressive gauge, it's only set a value in a tick when some event triggers some change. But when a tick is skipped, not having any change, it doesn't change the value stored at Redis hash.

My solution is keep record of what is the last tick in a key that can be accessed by that can be obtained by some_gauge.key(:head_tick), if some_gauge.value_at is called on a tick that has an undefined value and is greater than head_tick, value_at method returns the value stored at some_gauge.key(:head).

Same thing happens when calling some_gauge.values_in.

But doing only this, there is a problem that, if a tick is skipped, and after that the next tick is set, the missing tick remains undefined, so a timeline widget has a wrong 0 value at that missing tick.

To avoid this behavior, I modified the incr_tick method at GaugeModifiers, so now, when a new head_tick is created, new code looks for missing ticks between last head tick, and the new one, setting them as the last head value, so when some_gauge.values_in or some_gauge.value_at looks for those ticks, they are already defined with the right value.

Sorry, but I am a little lazy, and I not wrote test code for this fix.

Talking about tests, I executed your specs. They are accusing my code of breaking something, but I can't realize how any of my changes could break something that causes Failures about "ERR unknown command 'app'"

I didn't dig deep on your code, so you should be the best person to figure out what's happening. Maybe my code could help to fix this issue.

Running this on my machine, testing by hand with your examples, and some more that I wrote, it seems to work well, Maybe your test code is giving false results, maybe not.