(config)
| 17 | |
| 18 | class Histogram extends Metric { |
| 19 | constructor(config) { |
| 20 | super(config, { |
| 21 | buckets: [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10], |
| 22 | }); |
| 23 | |
| 24 | this.type = 'histogram'; |
| 25 | this.defaultLabels = {}; |
| 26 | this.defaultExemplarLabelSet = {}; |
| 27 | this.enableExemplars = false; |
| 28 | |
| 29 | for (const label of this.labelNames) { |
| 30 | if (label === 'le') { |
| 31 | throw new Error('le is a reserved label keyword'); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | this.upperBounds = this.buckets; |
| 36 | this.bucketValues = this.upperBounds.reduce((acc, upperBound) => { |
| 37 | acc[upperBound] = 0; |
| 38 | return acc; |
| 39 | }, {}); |
| 40 | |
| 41 | if (config.enableExemplars) { |
| 42 | this.enableExemplars = true; |
| 43 | this.bucketExemplars = this.upperBounds.reduce((acc, upperBound) => { |
| 44 | acc[upperBound] = null; |
| 45 | return acc; |
| 46 | }, {}); |
| 47 | Object.freeze(this.bucketExemplars); |
| 48 | this.observe = this.observeWithExemplar; |
| 49 | } else { |
| 50 | this.observe = this.observeWithoutExemplar; |
| 51 | } |
| 52 | |
| 53 | Object.freeze(this.bucketValues); |
| 54 | Object.freeze(this.upperBounds); |
| 55 | |
| 56 | if (this.labelNames.length === 0) { |
| 57 | this.hashMap = { |
| 58 | [hashObject({})]: createBaseValues( |
| 59 | {}, |
| 60 | this.bucketValues, |
| 61 | this.bucketExemplars, |
| 62 | ), |
| 63 | }; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Observe a value in histogram |
nothing calls this directly
no test coverage detected