All files / src/types/client InMemoryClient.ts

100% Statements 17/17
100% Branches 1/1
100% Functions 7/7
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 477x   7x         33x   33x 33x       59x       35x       8x 8x       19x   19x 19x     19x 19x       36x       36x 36x      
import { MetricClient } from './MetricClient';
 
export class InMemoryClient extends MetricClient {
  private metrics: Map<string, number>;
  private metricAttributes: Map<string, Record<string, string>>;
 
  constructor() {
    super();
 
    this.metrics = new Map<string, number>();
    this.metricAttributes = new Map<string, Record<string, string>>();
  }
 
  getMetrics(): Map<string, number> {
    return this.metrics;
  }
 
  getMetricAttributes(): Map<string, Record<string, string>> {
    return this.metricAttributes;
  }
 
  gaugeImpl(metricName: string, value: number, attributes: Record<string, string>): void {
    this.metrics.set(metricName, value);
    this.metricAttributes.set(metricName, attributes);
  }
 
  counterImpl(metricName: string, value: number, attributes: Record<string, string>): void {
    let currentValue = this.metrics.get(metricName);
 
    if (currentValue === undefined) {
      currentValue = 0;
    }
 
    this.metrics.set(metricName, currentValue + value);
    this.metricAttributes.set(metricName, attributes);
  }
 
  timeImpl(metricName: string, value: number, buckets: number[], attributes: Record<string, string>): void {
    this.recordHistogram(metricName, value, buckets, attributes);
  }
 
  histogramImpl(metricName: string, value: number, _buckets: number[], attributes: Record<string, string>): void {
    this.metrics.set(metricName, value);
    this.metricAttributes.set(metricName, attributes);
  }
}