126 lines
3.7 KiB
JavaScript
126 lines
3.7 KiB
JavaScript
// Metro module 6468 (f6469).
|
|
import * as _slicedToArray from "./_slicedToArray";
|
|
import * as _classCallCheck from "./_classCallCheck";
|
|
import * as __createClass from "./_createClass";
|
|
import { DEFAULT_FLUSH_INTERVAL, SET_METRIC_TYPE, MAX_WEIGHT } from "./Module6465";
|
|
import { timestampInSeconds } from "./Module6382";
|
|
import { sanitizeMetricKey, sanitizeTags, sanitizeUnit, getBucketKey } from "./Module6469";
|
|
import { METRIC_MAP } from "./CounterMetric";
|
|
import { updateMetricSummaryOnActiveSpan } from "./spanTimeInputToSeconds";
|
|
import { captureAggregateMetrics } from "./createMetricEnvelope";
|
|
let env4163 = {};
|
|
const MetricsAggregator = function MetricsAggregator(a0) {
|
|
"use strict";
|
|
_classCallCheck(this, MetricsAggregator);
|
|
this._client = a0;
|
|
this._buckets = new Map();
|
|
this._bucketsTotalWeight = 0;
|
|
this._interval = setInterval(() => this._flush(), DEFAULT_FLUSH_INTERVAL);
|
|
if (this._interval.unref) {
|
|
this._interval.unref();
|
|
}
|
|
this._flushShift = Math.floor(Math.random() * DEFAULT_FLUSH_INTERVAL / 1000);
|
|
this._forceFlush = false;
|
|
};
|
|
exports.MetricsAggregator = __createClass(MetricsAggregator, [{
|
|
key: "add",
|
|
value: function add(a0, a1, a2) {
|
|
"use strict";
|
|
let r61;
|
|
let r7 = arguments[3];
|
|
if (r7 === void 0) {
|
|
r7 = "none";
|
|
}
|
|
let r13 = arguments[4];
|
|
if (r13 === void 0) {
|
|
r13 = {};
|
|
}
|
|
let r6 = arguments[5];
|
|
if (r6 === void 0) {
|
|
r6 = timestampInSeconds();
|
|
}
|
|
const timestamp2 = Math.floor(r6);
|
|
const name = sanitizeMetricKey(a1);
|
|
const tags = sanitizeTags(r13);
|
|
const unit = sanitizeUnit(r7);
|
|
const bucketKey = getBucketKey(a0, name, unit, tags);
|
|
const r47 = this._buckets.get(bucketKey);
|
|
const r48 = r47 ? a0 === SET_METRIC_TYPE ? r47.metric.weight : 0 : 0;
|
|
if (r47) {
|
|
r47.metric.add(a2);
|
|
const timestamp = r47.timestamp;
|
|
r61 = r47;
|
|
if (timestamp < timestamp2) {
|
|
r47.timestamp = timestamp2;
|
|
r61 = r47;
|
|
}
|
|
} else {
|
|
r61 = {
|
|
metric: new METRIC_MAP[a0](a2),
|
|
timestamp: timestamp2,
|
|
metricType: a0,
|
|
name,
|
|
unit,
|
|
tags
|
|
};
|
|
this._buckets.set(bucketKey, r61);
|
|
}
|
|
updateMetricSummaryOnActiveSpan(a0, name, typeof a2 === "string" ? r61.metric.weight - r48 : a2, unit, r13, bucketKey);
|
|
this._bucketsTotalWeight = this._bucketsTotalWeight + r61.metric.weight;
|
|
if (this._bucketsTotalWeight >= MAX_WEIGHT) {
|
|
this.flush();
|
|
}
|
|
}
|
|
}, {
|
|
key: "flush",
|
|
value: function flush() {
|
|
"use strict";
|
|
this._forceFlush = true;
|
|
this._flush();
|
|
}
|
|
}, {
|
|
key: "close",
|
|
value: function close() {
|
|
"use strict";
|
|
this._forceFlush = true;
|
|
clearInterval(this._interval);
|
|
this._flush();
|
|
}
|
|
}, {
|
|
key: "_flush",
|
|
value: function _flush() {
|
|
"use strict";
|
|
if (this._forceFlush) {
|
|
this._forceFlush = false;
|
|
this._bucketsTotalWeight = 0;
|
|
this._captureMetrics(this._buckets);
|
|
this._buckets.clear();
|
|
return void 0;
|
|
}
|
|
const r37 = Math.floor(timestampInSeconds()) - DEFAULT_FLUSH_INTERVAL / 1000 - this._flushShift;
|
|
const map = new Map();
|
|
for (const _bucket of this._buckets) {
|
|
const [r52, r53] = _bucket;
|
|
if (r53.timestamp <= r37) {
|
|
map.set(r52, r53);
|
|
this._bucketsTotalWeight = this._bucketsTotalWeight - r53.metric.weight;
|
|
}
|
|
}
|
|
for (const item of map) {
|
|
this._buckets.delete(_slicedToArray(item, 1)[0]);
|
|
}
|
|
this._captureMetrics(map);
|
|
}
|
|
}, {
|
|
key: "_captureMetrics",
|
|
value: function _captureMetrics(a0) {
|
|
"use strict";
|
|
if (a0.size > 0) {
|
|
captureAggregateMetrics(this._client, Array.from(a0).map((item) => {
|
|
const [, r12] = item;
|
|
return r12;
|
|
}));
|
|
}
|
|
}
|
|
}]);
|