Skip to content

Commit

Permalink
fix: add 0.01 default bucket (#8)
Browse files Browse the repository at this point in the history
* fix: add 0.01 default bucket

* fix: test

Co-authored-by: alexander <[email protected]>
  • Loading branch information
alexanderGalushka and alexander-eng authored Nov 18, 2020
1 parent 6fc6052 commit fba332a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import { Counter } from '../mod.ts';
import { Metric, SUPRESS_HEADER, Labels } from './types.ts';

// 50 100 200 400 600 1000 ... ms
const defaultBuckets = [0.1, 0.2, 0.4, 0.6, 1, 3, 8, 20, 60, 120];
// 10 100 200 400 600 1000 ... ms
const defaultBuckets = [0.01, 0.1, 0.2, 0.4, 0.6, 1, 3, 8, 20, 60, 120];

export class Histogram extends Metric {
private buckets: number[];
Expand Down
9 changes: 5 additions & 4 deletions src/histogram_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { assertEquals } from "https://deno.land/[email protected]/testing/asserts.ts";
import { Histogram } from "./histogram.ts";

Deno.test("Histogram", async (): Promise<void> => {
// Buckets: [0.1, 0.2, 0.4, 0.6, 1, 3, 8, 20, 60, 120, +Inf];
// Buckets: [0.01, 0.1, 0.2, 0.4, 0.6, 1, 3, 8, 20, 60, 120, +Inf];
const histogram = new Histogram("http_request_duration");
histogram.observe(0.01);
histogram.observe(0.1);
Expand All @@ -18,13 +18,13 @@ Deno.test("Histogram", async (): Promise<void> => {

histogram.observe(300);
histogram.observe(300);
assertEquals(histogram.getObserved(10), 6); // le=+Inf
assertEquals(histogram.getObserved(11), 6); // le=+Inf
histogram.observe(50);
histogram.observe(50);
histogram.observe(50);
histogram.observe(50);
assertEquals(histogram.getObserved(8), 8); // le=60
assertEquals(histogram.getObserved(7), 4); // le=20
assertEquals(histogram.getObserved(9), 8); // le=60
assertEquals(histogram.getObserved(8), 4); // le=20
});


Expand All @@ -44,6 +44,7 @@ Deno.test("Histogram toString()", async (): Promise<void> => {
histogram.observe(50);

const expected = `# TYPE http_request_duration histogram
http_request_duration_bucket{le="0.01"} 1
http_request_duration_bucket{le="0.1"} 2
http_request_duration_bucket{le="0.2"} 2
http_request_duration_bucket{le="0.4"} 2
Expand Down

0 comments on commit fba332a

Please sign in to comment.