"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.TaskClaimMetricsAggregator = void 0; var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _result_type = require("../lib/result_type"); var _simple_histogram = require("./simple_histogram"); var _success_rate_counter = require("./success_rate_counter"); /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ const HDR_HISTOGRAM_MAX = 30000; // 30 seconds const HDR_HISTOGRAM_BUCKET_SIZE = 100; // 100 millis class TaskClaimMetricsAggregator { constructor() { (0, _defineProperty2.default)(this, "claimSuccessRate", new _success_rate_counter.SuccessRateCounter()); (0, _defineProperty2.default)(this, "durationHistogram", new _simple_histogram.SimpleHistogram(HDR_HISTOGRAM_MAX, HDR_HISTOGRAM_BUCKET_SIZE)); } initialMetric() { return { ...this.claimSuccessRate.initialMetric(), duration: { counts: [], values: [] } }; } collect() { return { ...this.claimSuccessRate.get(), duration: this.serializeHistogram() }; } reset() { this.claimSuccessRate.reset(); this.durationHistogram.reset(); } processTaskLifecycleEvent(taskEvent) { const success = (0, _result_type.isOk)(taskEvent.event); this.claimSuccessRate.increment(success); if (taskEvent.timing) { const durationInMs = taskEvent.timing.stop - taskEvent.timing.start; this.durationHistogram.record(durationInMs); } } serializeHistogram() { const counts = []; const values = []; for (const { count, value } of this.durationHistogram.get(true)) { counts.push(count); values.push(value); } return { counts, values }; } } exports.TaskClaimMetricsAggregator = TaskClaimMetricsAggregator;