Code coverage report for core/src/apm/local/gauge.ts

Statements: 19.05% (4 / 21)      Branches: 0% (0 / 26)      Functions: 0% (0 / 9)      Lines: 19.05% (4 / 21)      Ignored: none     

All files » core/src/apm/local/ » gauge.ts
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 641     1     1                                                             1                                                    
import {InternalLog, logger} from '../../internal/log';
import {Tags} from '../../util';
import {Gauge} from '../gauge';
import {LocalSettable} from './settable';
 
 
export class LocalGauge extends LocalSettable<number> implements Gauge<number> {
 
  protected readonly log: InternalLog = logger('LocalGauge');
 
 
  decrement(value = 0, tags: Tags = {}): void {
    const update = (this.raw || 0) - value;
    this.log.debug('%d - %d = %d', this.raw, value, update);
    this.set(update, tags);
  }
 
 
  increment(value = 1, tags: Tags = {}): void {
    const update = (this.raw || 0) + value;
    this.log.debug('%d + %d = %d', this.raw, value, update);
    this.set(update, tags);
  }
 
 
  get raw(): number {
    return this._val?.value || 0;
  }
 
 
  reset(): void {
    this.set(0);
  }
 
}
 
 
export class LocalBigIntGauge extends LocalSettable<bigint> implements Gauge<bigint> {
 
  decrement(value?: bigint, tags: Tags = {}): void {
    value = value || BigInt(1);
    const update = (this.raw || BigInt(0)) - value;
    this.set(update, tags);
  }
 
 
  increment(value?: bigint, tags: Tags = {}): void {
    value = value || BigInt(1);
    const update = (this.raw || BigInt(0)) + value;
    this.set(update, tags);
  }
 
 
  get raw(): bigint {
    return this._val.value || BigInt(0);
  }
 
 
  reset(): void {
    this.set(BigInt(0));
  }
 
}