mikejihbe / metrics

A metrics library for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Histogram doesn't update min/max correctly when initial updates are 0 or negative

otterley opened this issue · comments

Test case:

var Histogram = require('../metrics/histogram');

var broken = function(callback) {
  console.log("\nBroken histogram demo");
  var brokenHist = Histogram.createUniformHistogram(1000);
  console.log("Adding 0 to histogram");
  brokenHist.update(0);
  console.log("Current min: " + brokenHist.min + ", max: " + brokenHist.max);
  console.log("Adding -1 to histogram");
  brokenHist.update(-1);
  console.log("Current min: " + brokenHist.min + ", max: " + brokenHist.max);
  console.log("Adding 1 to histogram");
  brokenHist.update(1);
  console.log("Current min: " + brokenHist.min + ", max: " + brokenHist.max);

  if (typeof callback == 'function') {
    callback();
  }
};
Broken histogram demo
Adding 0 to histogram
Current min: 0, max: null
Adding -1 to histogram
Current min: -1, max: null
Adding 1 to histogram
Current min: -1, max: 1

Fix forthcoming in pull request.