mmrobins
mmrobins

Reputation: 13775

Order of summarize and diffSeries with graphite

I'm trying to subtract the sum of a couple graphite metrics from the sum of a couple of other graphite metrics over a summarized period of time. However, I'm getting different results depending on whether I summarize before or after I do diffSeries.

I expect these two graphite queries below to be the same, but they're not:

summarize(
  diffSeries(
    sum(
      stats_counts.otherthing.one,
      stats_counts.otherthing.two
    ),
    sum(
      stats_counts.thing.one,
      stats_counts.thing.two,
      stats_counts.thing.three
    )
  ),
  '1week',
  'sum',
  true
)

With summarize on the outside of diffSeries (as above) I get numbers that seem way too high based on looking at the raw data in csv exports.

diffSeries(
  summarize(
    sum(
      stats_counts.otherthing.one,
      stats_counts.otherthing.more_than_five
    ),
    '1week',
    'sum',
    true
  ),
  summarize(
    sum(
      stats_counts.thing.one,
      stats_counts.thing.two,
      stats_counts.thing.three,
    ),
    '1week',
    'sum',
    true
  )
)

The above seems to give me the right data, but I'd rather only have to summarize once and can't for the life of me figure out why it should be different. It seems like the arguments to diffSeries are getting messed up when I just pass them in as sums and don't summarize too, but I'm not sure how.

Upvotes: 2

Views: 3246

Answers (1)

gingerlime
gingerlime

Reputation: 5346

I'm not entirely sure, but was also getting some strange behaviour with diffSeries. In my case it looked like I was always getting positive diffs, when it should have been negative.

Looking at the code, diffSeries uses a function called safeDiff. It looks to me like the first line of the function might be the culprit. It only takes values that are not None, so if you try to diff a numeric value from None, it will output the (positive) numeric value... Where I would have expected a negative one.

Perhaps there's a way to convert None/null to zeros? I couldn't find a function in graphite to do so. There is a drawNullAsZero, but is there some kind of a treatNullAsZero? or maybe I missed something.

In any case, I suspect this might be related to the issue you're seeing.

Upvotes: 2

Related Questions