4807 lines
166 KiB
JavaScript
4807 lines
166 KiB
JavaScript
var __bare_os_bundle_exports__ = (() => {
|
|
var __create = Object.create;
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __getProtoOf = Object.getPrototypeOf;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
}) : x)(function(x) {
|
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
});
|
|
var __esm = (fn, res) => function __init() {
|
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
};
|
|
var __commonJS = (cb, mod) => function __require2() {
|
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
};
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
// file that has been converted to a CommonJS file using a Babel-
|
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
mod
|
|
));
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
// ../../node_modules/bare-prom-client/lib/util.js
|
|
var require_util = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/util.js"(exports) {
|
|
"use strict";
|
|
exports.getValueAsString = function getValueString(value) {
|
|
if (Number.isNaN(value)) {
|
|
return "Nan";
|
|
} else if (!Number.isFinite(value)) {
|
|
if (value < 0) {
|
|
return "-Inf";
|
|
} else {
|
|
return "+Inf";
|
|
}
|
|
} else {
|
|
return `${value}`;
|
|
}
|
|
};
|
|
exports.removeLabels = function removeLabels(hashMap, labels, sortedLabelNames) {
|
|
const hash = hashObject(labels, sortedLabelNames);
|
|
delete hashMap[hash];
|
|
};
|
|
exports.setValue = function setValue(hashMap, value, labels) {
|
|
const hash = hashObject(labels);
|
|
hashMap[hash] = {
|
|
value: typeof value === "number" ? value : 0,
|
|
labels: labels || {}
|
|
};
|
|
return hashMap;
|
|
};
|
|
exports.setValueDelta = function setValueDelta(hashMap, deltaValue, labels, hash = "") {
|
|
const value = typeof deltaValue === "number" ? deltaValue : 0;
|
|
if (hashMap[hash]) {
|
|
hashMap[hash].value += value;
|
|
} else {
|
|
hashMap[hash] = { value, labels };
|
|
}
|
|
return hashMap;
|
|
};
|
|
exports.getLabels = function(labelNames, args) {
|
|
if (typeof args[0] === "object") {
|
|
return args[0];
|
|
}
|
|
if (labelNames.length !== args.length) {
|
|
throw new Error(
|
|
`Invalid number of arguments (${args.length}): "${args.join(
|
|
", "
|
|
)}" for label names (${labelNames.length}): "${labelNames.join(", ")}".`
|
|
);
|
|
}
|
|
const acc = {};
|
|
for (let i = 0; i < labelNames.length; i++) {
|
|
acc[labelNames[i]] = args[i];
|
|
}
|
|
return acc;
|
|
};
|
|
function fastHashObject(keys, labels) {
|
|
if (keys.length === 0) {
|
|
return "";
|
|
}
|
|
let hash = "";
|
|
for (let i = 0; i < keys.length; i++) {
|
|
const key = keys[i];
|
|
const value = labels[key];
|
|
if (value === void 0) continue;
|
|
hash += `${key}:${value},`;
|
|
}
|
|
return hash;
|
|
}
|
|
function hashObject(labels, labelNames) {
|
|
if (labelNames) {
|
|
return fastHashObject(labelNames, labels);
|
|
}
|
|
const keys = Object.keys(labels);
|
|
if (keys.length > 1) {
|
|
keys.sort();
|
|
}
|
|
return fastHashObject(keys, labels);
|
|
}
|
|
exports.hashObject = hashObject;
|
|
exports.isObject = function isObject(obj) {
|
|
return obj !== null && typeof obj === "object";
|
|
};
|
|
exports.nowTimestamp = function nowTimestamp() {
|
|
return Date.now() / 1e3;
|
|
};
|
|
var Grouper = class extends Map {
|
|
/**
|
|
* Adds the `value` to the `key`'s array of values.
|
|
* @param {*} key Key to set.
|
|
* @param {*} value Value to add to `key`'s array.
|
|
* @returns {undefined} undefined.
|
|
*/
|
|
add(key, value) {
|
|
if (this.has(key)) {
|
|
this.get(key).push(value);
|
|
} else {
|
|
this.set(key, [value]);
|
|
}
|
|
}
|
|
};
|
|
exports.Grouper = Grouper;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/registry.js
|
|
var require_registry = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/registry.js"(exports, module) {
|
|
"use strict";
|
|
var { getValueAsString } = require_util();
|
|
var Registry = class _Registry {
|
|
static get PROMETHEUS_CONTENT_TYPE() {
|
|
return "text/plain; version=0.0.4; charset=utf-8";
|
|
}
|
|
static get OPENMETRICS_CONTENT_TYPE() {
|
|
return "application/openmetrics-text; version=1.0.0; charset=utf-8";
|
|
}
|
|
constructor(regContentType = _Registry.PROMETHEUS_CONTENT_TYPE) {
|
|
this._metrics = {};
|
|
this._collectors = [];
|
|
this._defaultLabels = {};
|
|
if (regContentType !== _Registry.PROMETHEUS_CONTENT_TYPE && regContentType !== _Registry.OPENMETRICS_CONTENT_TYPE) {
|
|
throw new TypeError(`Content type ${regContentType} is unsupported`);
|
|
}
|
|
this._contentType = regContentType;
|
|
}
|
|
getMetricsAsArray() {
|
|
return Object.values(this._metrics);
|
|
}
|
|
async getMetricsAsString(metrics2) {
|
|
const metric = typeof metrics2.getForPromString === "function" ? await metrics2.getForPromString() : await metrics2.get();
|
|
const name = escapeString(metric.name);
|
|
const help = `# HELP ${name} ${escapeString(metric.help)}`;
|
|
const type = `# TYPE ${name} ${metric.type}`;
|
|
const values = [help, type];
|
|
const defaultLabels = Object.keys(this._defaultLabels).length > 0 ? this._defaultLabels : null;
|
|
const isOpenMetrics = this.contentType === _Registry.OPENMETRICS_CONTENT_TYPE;
|
|
for (const val of metric.values || []) {
|
|
let { metricName = name, labels = {} } = val;
|
|
const { sharedLabels = {} } = val;
|
|
if (isOpenMetrics && metric.type === "counter") {
|
|
metricName = `${metricName}_total`;
|
|
}
|
|
if (defaultLabels) {
|
|
labels = { ...labels, ...defaultLabels, ...labels };
|
|
}
|
|
const formattedLabels = formatLabels(labels, sharedLabels);
|
|
const flattenedShared = flattenSharedLabels(sharedLabels);
|
|
const labelParts = [...formattedLabels, flattenedShared].filter(Boolean);
|
|
const labelsString = labelParts.length ? `{${labelParts.join(",")}}` : "";
|
|
let fullMetricLine = `${metricName}${labelsString} ${getValueAsString(
|
|
val.value
|
|
)}`;
|
|
const { exemplar } = val;
|
|
if (exemplar && isOpenMetrics) {
|
|
const formattedExemplars = formatLabels(exemplar.labelSet);
|
|
fullMetricLine += ` # {${formattedExemplars.join(
|
|
","
|
|
)}} ${getValueAsString(exemplar.value)} ${exemplar.timestamp}`;
|
|
}
|
|
values.push(fullMetricLine);
|
|
}
|
|
return values.join("\n");
|
|
}
|
|
async metrics() {
|
|
const isOpenMetrics = this.contentType === _Registry.OPENMETRICS_CONTENT_TYPE;
|
|
const promises = this.getMetricsAsArray().map((metric) => {
|
|
if (isOpenMetrics && metric.type === "counter") {
|
|
metric.name = standardizeCounterName(metric.name);
|
|
}
|
|
return this.getMetricsAsString(metric);
|
|
});
|
|
const resolves = await Promise.all(promises);
|
|
return isOpenMetrics ? `${resolves.join("\n")}
|
|
# EOF
|
|
` : `${resolves.join("\n\n")}
|
|
`;
|
|
}
|
|
registerMetric(metric) {
|
|
if (this._metrics[metric.name] && this._metrics[metric.name] !== metric) {
|
|
throw new Error(
|
|
`A metric with the name ${metric.name} has already been registered.`
|
|
);
|
|
}
|
|
this._metrics[metric.name] = metric;
|
|
}
|
|
clear() {
|
|
this._metrics = {};
|
|
this._defaultLabels = {};
|
|
}
|
|
async getMetricsAsJSON() {
|
|
const metrics2 = [];
|
|
const defaultLabelNames = Object.keys(this._defaultLabels);
|
|
const promises = [];
|
|
for (const metric of this.getMetricsAsArray()) {
|
|
promises.push(metric.get());
|
|
}
|
|
const resolves = await Promise.all(promises);
|
|
for (const item of resolves) {
|
|
if (item.values && defaultLabelNames.length > 0) {
|
|
for (const val of item.values) {
|
|
val.labels = Object.assign({}, val.labels);
|
|
for (const labelName of defaultLabelNames) {
|
|
val.labels[labelName] = val.labels[labelName] || this._defaultLabels[labelName];
|
|
}
|
|
}
|
|
}
|
|
metrics2.push(item);
|
|
}
|
|
return metrics2;
|
|
}
|
|
removeSingleMetric(name) {
|
|
delete this._metrics[name];
|
|
}
|
|
getSingleMetricAsString(name) {
|
|
return this.getMetricsAsString(this._metrics[name]);
|
|
}
|
|
getSingleMetric(name) {
|
|
return this._metrics[name];
|
|
}
|
|
setDefaultLabels(labels) {
|
|
this._defaultLabels = labels;
|
|
}
|
|
resetMetrics() {
|
|
for (const metric in this._metrics) {
|
|
this._metrics[metric].reset();
|
|
}
|
|
}
|
|
get contentType() {
|
|
return this._contentType;
|
|
}
|
|
setContentType(metricsContentType) {
|
|
if (metricsContentType === _Registry.OPENMETRICS_CONTENT_TYPE || metricsContentType === _Registry.PROMETHEUS_CONTENT_TYPE) {
|
|
this._contentType = metricsContentType;
|
|
} else {
|
|
throw new Error(`Content type ${metricsContentType} is unsupported`);
|
|
}
|
|
}
|
|
static merge(registers) {
|
|
const regType = registers[0].contentType;
|
|
for (const reg of registers) {
|
|
if (reg.contentType !== regType) {
|
|
throw new Error(
|
|
"Registers can only be merged if they have the same content type"
|
|
);
|
|
}
|
|
}
|
|
const mergedRegistry = new _Registry(regType);
|
|
const metricsToMerge = registers.reduce(
|
|
(acc, reg) => acc.concat(reg.getMetricsAsArray()),
|
|
[]
|
|
);
|
|
metricsToMerge.forEach(mergedRegistry.registerMetric, mergedRegistry);
|
|
return mergedRegistry;
|
|
}
|
|
};
|
|
function formatLabels(labels, exclude) {
|
|
const { hasOwnProperty } = Object.prototype;
|
|
const formatted = [];
|
|
for (const [name, value] of Object.entries(labels)) {
|
|
if (!exclude || !hasOwnProperty.call(exclude, name)) {
|
|
formatted.push(`${name}="${escapeLabelValue(value)}"`);
|
|
}
|
|
}
|
|
return formatted;
|
|
}
|
|
var sharedLabelCache = /* @__PURE__ */ new WeakMap();
|
|
function flattenSharedLabels(labels) {
|
|
const cached = sharedLabelCache.get(labels);
|
|
if (cached) {
|
|
return cached;
|
|
}
|
|
const formattedLabels = formatLabels(labels);
|
|
const flattened = formattedLabels.join(",");
|
|
sharedLabelCache.set(labels, flattened);
|
|
return flattened;
|
|
}
|
|
function escapeLabelValue(str) {
|
|
if (typeof str !== "string") {
|
|
return str;
|
|
}
|
|
return escapeString(str).replace(/"/g, '\\"');
|
|
}
|
|
function escapeString(str) {
|
|
return str.replace(/\\/g, "\\\\").replace(/\n/g, "\\n");
|
|
}
|
|
function standardizeCounterName(name) {
|
|
return name.replace(/_total$/, "");
|
|
}
|
|
module.exports = Registry;
|
|
module.exports.globalRegistry = new Registry();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/validation.js
|
|
var require_validation = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/validation.js"(exports) {
|
|
"use strict";
|
|
var util = __require("util");
|
|
var metricRegexp = /^[a-zA-Z_:][a-zA-Z0-9_:]*$/;
|
|
var labelRegexp = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
exports.validateMetricName = function(name) {
|
|
return metricRegexp.test(name);
|
|
};
|
|
exports.validateLabelName = function(names = []) {
|
|
return names.every((name) => labelRegexp.test(name));
|
|
};
|
|
exports.validateLabel = function validateLabel(savedLabels, labels) {
|
|
for (const label in labels) {
|
|
if (!savedLabels.includes(label)) {
|
|
throw new Error(
|
|
`Added label "${label}" is not included in initial labelset: ${util.inspect(
|
|
savedLabels
|
|
)}`
|
|
);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metric.js
|
|
var require_metric = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metric.js"(exports, module) {
|
|
"use strict";
|
|
var Registry = require_registry();
|
|
var { isObject } = require_util();
|
|
var { validateMetricName, validateLabelName } = require_validation();
|
|
var Metric = class {
|
|
constructor(config, defaults = {}) {
|
|
if (!isObject(config)) {
|
|
throw new TypeError("constructor expected a config object");
|
|
}
|
|
Object.assign(
|
|
this,
|
|
{
|
|
labelNames: [],
|
|
registers: [Registry.globalRegistry],
|
|
aggregator: "sum",
|
|
enableExemplars: false
|
|
},
|
|
defaults,
|
|
config
|
|
);
|
|
if (!this.registers) {
|
|
this.registers = [Registry.globalRegistry];
|
|
}
|
|
if (!this.help) {
|
|
throw new Error("Missing mandatory help parameter");
|
|
}
|
|
if (!this.name) {
|
|
throw new Error("Missing mandatory name parameter");
|
|
}
|
|
if (!validateMetricName(this.name)) {
|
|
throw new Error("Invalid metric name");
|
|
}
|
|
if (!validateLabelName(this.labelNames)) {
|
|
throw new Error("Invalid label name");
|
|
}
|
|
if (this.collect && typeof this.collect !== "function") {
|
|
throw new Error('Optional "collect" parameter must be a function');
|
|
}
|
|
if (this.labelNames) {
|
|
this.sortedLabelNames = [...this.labelNames].sort();
|
|
} else {
|
|
this.sortedLabelNames = [];
|
|
}
|
|
this.reset();
|
|
for (const register of this.registers) {
|
|
if (this.enableExemplars && register.contentType === Registry.PROMETHEUS_CONTENT_TYPE) {
|
|
throw new TypeError(
|
|
"Exemplars are supported only on OpenMetrics registries"
|
|
);
|
|
}
|
|
register.registerMetric(this);
|
|
}
|
|
}
|
|
reset() {
|
|
}
|
|
};
|
|
module.exports = { Metric };
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/exemplar.js
|
|
var require_exemplar = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/exemplar.js"(exports, module) {
|
|
"use strict";
|
|
var Exemplar = class {
|
|
constructor(labelSet = {}, value = null) {
|
|
this.labelSet = labelSet;
|
|
this.value = value;
|
|
}
|
|
/**
|
|
* Validation for the label set format.
|
|
* https://github.com/OpenObservability/OpenMetrics/blob/d99b705f611b75fec8f450b05e344e02eea6921d/specification/OpenMetrics.md#exemplars
|
|
*
|
|
* @param {object} labelSet - Exemplar labels.
|
|
* @throws {RangeError}
|
|
* @return {void}
|
|
*/
|
|
validateExemplarLabelSet(labelSet) {
|
|
let res = "";
|
|
for (const [labelName, labelValue] of Object.entries(labelSet)) {
|
|
res += `${labelName}${labelValue}`;
|
|
}
|
|
if (res.length > 128) {
|
|
throw new RangeError(
|
|
"Label set size must be smaller than 128 UTF-8 chars"
|
|
);
|
|
}
|
|
}
|
|
};
|
|
module.exports = Exemplar;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/counter.js
|
|
var require_counter = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/counter.js"(exports, module) {
|
|
"use strict";
|
|
var util = __require("util");
|
|
var {
|
|
hashObject,
|
|
isObject,
|
|
getLabels,
|
|
removeLabels,
|
|
nowTimestamp
|
|
} = require_util();
|
|
var { validateLabel } = require_validation();
|
|
var { Metric } = require_metric();
|
|
var Exemplar = require_exemplar();
|
|
var Counter = class extends Metric {
|
|
constructor(config) {
|
|
super(config);
|
|
this.type = "counter";
|
|
this.defaultLabels = {};
|
|
this.defaultValue = 1;
|
|
this.defaultExemplarLabelSet = {};
|
|
if (config.enableExemplars) {
|
|
this.enableExemplars = true;
|
|
this.inc = this.incWithExemplar;
|
|
} else {
|
|
this.inc = this.incWithoutExemplar;
|
|
}
|
|
}
|
|
/**
|
|
* Increment counter
|
|
* @param {object} labels - What label you want to be incremented
|
|
* @param {Number} value - Value to increment, if omitted increment with 1
|
|
* @returns {object} results - object with information about the inc operation
|
|
* @returns {string} results.labelHash - hash representation of the labels
|
|
*/
|
|
incWithoutExemplar(labels, value) {
|
|
let hash = "";
|
|
if (isObject(labels)) {
|
|
hash = hashObject(labels, this.sortedLabelNames);
|
|
validateLabel(this.labelNames, labels);
|
|
} else {
|
|
value = labels;
|
|
labels = {};
|
|
}
|
|
if (value && !Number.isFinite(value)) {
|
|
throw new TypeError(`Value is not a valid number: ${util.format(value)}`);
|
|
}
|
|
if (value < 0) {
|
|
throw new Error("It is not possible to decrease a counter");
|
|
}
|
|
if (value === null || value === void 0) value = 1;
|
|
setValue(this.hashMap, value, labels, hash);
|
|
return { labelHash: hash };
|
|
}
|
|
/**
|
|
* Increment counter with exemplar, same as inc but accepts labels for an
|
|
* exemplar.
|
|
* If no label is provided the current exemplar labels are kept unchanged
|
|
* (defaults to empty set).
|
|
*
|
|
* @param {object} incOpts - Object with options about what metric to increase
|
|
* @param {object} incOpts.labels - What label you want to be incremented,
|
|
* defaults to null (metric with no labels)
|
|
* @param {Number} incOpts.value - Value to increment, defaults to 1
|
|
* @param {object} incOpts.exemplarLabels - Key-value labels for the
|
|
* exemplar, defaults to empty set {}
|
|
* @returns {void}
|
|
*/
|
|
incWithExemplar({
|
|
labels = this.defaultLabels,
|
|
value = this.defaultValue,
|
|
exemplarLabels = this.defaultExemplarLabelSet
|
|
} = {}) {
|
|
const res = this.incWithoutExemplar(labels, value);
|
|
this.updateExemplar(exemplarLabels, value, res.labelHash);
|
|
}
|
|
updateExemplar(exemplarLabels, value, hash) {
|
|
if (exemplarLabels === this.defaultExemplarLabelSet) return;
|
|
if (!isObject(this.hashMap[hash].exemplar)) {
|
|
this.hashMap[hash].exemplar = new Exemplar();
|
|
}
|
|
this.hashMap[hash].exemplar.validateExemplarLabelSet(exemplarLabels);
|
|
this.hashMap[hash].exemplar.labelSet = exemplarLabels;
|
|
this.hashMap[hash].exemplar.value = value ? value : 1;
|
|
this.hashMap[hash].exemplar.timestamp = nowTimestamp();
|
|
}
|
|
/**
|
|
* Reset counter
|
|
* @returns {void}
|
|
*/
|
|
reset() {
|
|
this.hashMap = {};
|
|
if (this.labelNames.length === 0) {
|
|
setValue(this.hashMap, 0);
|
|
}
|
|
}
|
|
async get() {
|
|
if (this.collect) {
|
|
const v = this.collect();
|
|
if (v instanceof Promise) await v;
|
|
}
|
|
return {
|
|
help: this.help,
|
|
name: this.name,
|
|
type: this.type,
|
|
values: Object.values(this.hashMap),
|
|
aggregator: this.aggregator
|
|
};
|
|
}
|
|
labels(...args) {
|
|
const labels = getLabels(this.labelNames, args) || {};
|
|
return {
|
|
inc: this.inc.bind(this, labels)
|
|
};
|
|
}
|
|
remove(...args) {
|
|
const labels = getLabels(this.labelNames, args) || {};
|
|
validateLabel(this.labelNames, labels);
|
|
return removeLabels.call(this, this.hashMap, labels, this.sortedLabelNames);
|
|
}
|
|
};
|
|
function setValue(hashMap, value, labels = {}, hash = "") {
|
|
if (hashMap[hash]) {
|
|
hashMap[hash].value += value;
|
|
} else {
|
|
hashMap[hash] = { value, labels };
|
|
}
|
|
return hashMap;
|
|
}
|
|
module.exports = Counter;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/gauge.js
|
|
var require_gauge = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/gauge.js"(exports, module) {
|
|
"use strict";
|
|
var process = __require("process");
|
|
var util = __require("util");
|
|
var {
|
|
setValue,
|
|
setValueDelta,
|
|
getLabels,
|
|
hashObject,
|
|
isObject,
|
|
removeLabels
|
|
} = require_util();
|
|
var { validateLabel } = require_validation();
|
|
var { Metric } = require_metric();
|
|
var Gauge = class extends Metric {
|
|
constructor(config) {
|
|
super(config);
|
|
this.type = "gauge";
|
|
}
|
|
/**
|
|
* Set a gauge to a value
|
|
* @param {object} labels - Object with labels and their values
|
|
* @param {Number} value - Value to set the gauge to, must be positive
|
|
* @returns {void}
|
|
*/
|
|
set(labels, value) {
|
|
value = getValueArg(labels, value);
|
|
labels = getLabelArg(labels);
|
|
set(this, labels, value);
|
|
}
|
|
/**
|
|
* Reset gauge
|
|
* @returns {void}
|
|
*/
|
|
reset() {
|
|
this.hashMap = {};
|
|
if (this.labelNames.length === 0) {
|
|
setValue(this.hashMap, 0, {});
|
|
}
|
|
}
|
|
/**
|
|
* Increment a gauge value
|
|
* @param {object} labels - Object with labels where key is the label key and value is label value. Can only be one level deep
|
|
* @param {Number} value - Value to increment - if omitted, increment with 1
|
|
* @returns {void}
|
|
*/
|
|
inc(labels, value) {
|
|
value = getValueArg(labels, value);
|
|
labels = getLabelArg(labels);
|
|
if (value === void 0) value = 1;
|
|
setDelta(this, labels, value);
|
|
}
|
|
/**
|
|
* Decrement a gauge value
|
|
* @param {object} labels - Object with labels where key is the label key and value is label value. Can only be one level deep
|
|
* @param {Number} value - Value to decrement - if omitted, decrement with 1
|
|
* @returns {void}
|
|
*/
|
|
dec(labels, value) {
|
|
value = getValueArg(labels, value);
|
|
labels = getLabelArg(labels);
|
|
if (value === void 0) value = 1;
|
|
setDelta(this, labels, -value);
|
|
}
|
|
/**
|
|
* Set the gauge to current unix epoch
|
|
* @param {object} labels - Object with labels where key is the label key and value is label value. Can only be one level deep
|
|
* @returns {void}
|
|
*/
|
|
setToCurrentTime(labels) {
|
|
const now = Date.now() / 1e3;
|
|
if (labels === void 0) {
|
|
this.set(now);
|
|
} else {
|
|
this.set(labels, now);
|
|
}
|
|
}
|
|
/**
|
|
* Start a timer
|
|
* @param {object} labels - Object with labels where key is the label key and value is label value. Can only be one level deep
|
|
* @returns {function} - Invoke this function to set the duration in seconds since you started the timer.
|
|
* @example
|
|
* var done = gauge.startTimer();
|
|
* makeXHRRequest(function(err, response) {
|
|
* done(); //Duration of the request will be saved
|
|
* });
|
|
*/
|
|
startTimer(labels) {
|
|
const start = process.hrtime();
|
|
return (endLabels) => {
|
|
const delta = process.hrtime(start);
|
|
const value = delta[0] + delta[1] / 1e9;
|
|
this.set(Object.assign({}, labels, endLabels), value);
|
|
return value;
|
|
};
|
|
}
|
|
async get() {
|
|
if (this.collect) {
|
|
const v = this.collect();
|
|
if (v instanceof Promise) await v;
|
|
}
|
|
return {
|
|
help: this.help,
|
|
name: this.name,
|
|
type: this.type,
|
|
values: Object.values(this.hashMap),
|
|
aggregator: this.aggregator
|
|
};
|
|
}
|
|
_getValue(labels) {
|
|
const hash = hashObject(labels || {}, this.sortedLabelNames);
|
|
return this.hashMap[hash] ? this.hashMap[hash].value : 0;
|
|
}
|
|
labels(...args) {
|
|
const labels = getLabels(this.labelNames, args);
|
|
validateLabel(this.labelNames, labels);
|
|
return {
|
|
inc: this.inc.bind(this, labels),
|
|
dec: this.dec.bind(this, labels),
|
|
set: this.set.bind(this, labels),
|
|
setToCurrentTime: this.setToCurrentTime.bind(this, labels),
|
|
startTimer: this.startTimer.bind(this, labels)
|
|
};
|
|
}
|
|
remove(...args) {
|
|
const labels = getLabels(this.labelNames, args);
|
|
validateLabel(this.labelNames, labels);
|
|
removeLabels.call(this, this.hashMap, labels, this.sortedLabelNames);
|
|
}
|
|
};
|
|
function set(gauge, labels, value) {
|
|
if (typeof value !== "number") {
|
|
throw new TypeError(`Value is not a valid number: ${util.format(value)}`);
|
|
}
|
|
validateLabel(gauge.labelNames, labels);
|
|
setValue(gauge.hashMap, value, labels);
|
|
}
|
|
function setDelta(gauge, labels, delta) {
|
|
if (typeof delta !== "number") {
|
|
throw new TypeError(`Delta is not a valid number: ${util.format(delta)}`);
|
|
}
|
|
validateLabel(gauge.labelNames, labels);
|
|
const hash = hashObject(labels, gauge.sortedLabelNames);
|
|
setValueDelta(gauge.hashMap, delta, labels, hash);
|
|
}
|
|
function getLabelArg(labels) {
|
|
return isObject(labels) ? labels : {};
|
|
}
|
|
function getValueArg(labels, value) {
|
|
return isObject(labels) ? value : labels;
|
|
}
|
|
module.exports = Gauge;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/histogram.js
|
|
var require_histogram = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/histogram.js"(exports, module) {
|
|
"use strict";
|
|
var process = __require("process");
|
|
var util = __require("util");
|
|
var {
|
|
getLabels,
|
|
hashObject,
|
|
isObject,
|
|
removeLabels,
|
|
nowTimestamp
|
|
} = require_util();
|
|
var { validateLabel } = require_validation();
|
|
var { Metric } = require_metric();
|
|
var Exemplar = require_exemplar();
|
|
var Histogram = class extends Metric {
|
|
constructor(config) {
|
|
super(config, {
|
|
buckets: [5e-3, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]
|
|
});
|
|
this.type = "histogram";
|
|
this.defaultLabels = {};
|
|
this.defaultExemplarLabelSet = {};
|
|
this.enableExemplars = false;
|
|
for (const label of this.labelNames) {
|
|
if (label === "le") {
|
|
throw new Error("le is a reserved label keyword");
|
|
}
|
|
}
|
|
this.upperBounds = this.buckets;
|
|
this.bucketValues = this.upperBounds.reduce((acc, upperBound) => {
|
|
acc[upperBound] = 0;
|
|
return acc;
|
|
}, {});
|
|
if (config.enableExemplars) {
|
|
this.enableExemplars = true;
|
|
this.bucketExemplars = this.upperBounds.reduce((acc, upperBound) => {
|
|
acc[upperBound] = null;
|
|
return acc;
|
|
}, {});
|
|
Object.freeze(this.bucketExemplars);
|
|
this.observe = this.observeWithExemplar;
|
|
} else {
|
|
this.observe = this.observeWithoutExemplar;
|
|
}
|
|
Object.freeze(this.bucketValues);
|
|
Object.freeze(this.upperBounds);
|
|
if (this.labelNames.length === 0) {
|
|
this.hashMap = {
|
|
[hashObject({})]: createBaseValues(
|
|
{},
|
|
this.bucketValues,
|
|
this.bucketExemplars
|
|
)
|
|
};
|
|
}
|
|
}
|
|
/**
|
|
* Observe a value in histogram
|
|
* @param {object} labels - Object with labels where key is the label key and value is label value. Can only be one level deep
|
|
* @param {Number} value - Value to observe in the histogram
|
|
* @returns {void}
|
|
*/
|
|
observeWithoutExemplar(labels, value) {
|
|
observe.call(this, labels === 0 ? 0 : labels || {})(value);
|
|
}
|
|
observeWithExemplar({
|
|
labels = this.defaultLabels,
|
|
value,
|
|
exemplarLabels = this.defaultExemplarLabelSet
|
|
} = {}) {
|
|
observe.call(this, labels === 0 ? 0 : labels || {})(value);
|
|
this.updateExemplar(labels, value, exemplarLabels);
|
|
}
|
|
updateExemplar(labels, value, exemplarLabels) {
|
|
if (Object.keys(exemplarLabels).length === 0) return;
|
|
const hash = hashObject(labels, this.sortedLabelNames);
|
|
const bound = findBound(this.upperBounds, value);
|
|
const { bucketExemplars } = this.hashMap[hash];
|
|
let exemplar = bucketExemplars[bound];
|
|
if (!isObject(exemplar)) {
|
|
exemplar = new Exemplar();
|
|
bucketExemplars[bound] = exemplar;
|
|
}
|
|
exemplar.validateExemplarLabelSet(exemplarLabels);
|
|
exemplar.labelSet = exemplarLabels;
|
|
exemplar.value = value;
|
|
exemplar.timestamp = nowTimestamp();
|
|
}
|
|
async get() {
|
|
const data = await this.getForPromString();
|
|
data.values = data.values.map(splayLabels);
|
|
return data;
|
|
}
|
|
async getForPromString() {
|
|
if (this.collect) {
|
|
const v = this.collect();
|
|
if (v instanceof Promise) await v;
|
|
}
|
|
const data = Object.values(this.hashMap);
|
|
const values = data.map(extractBucketValuesForExport(this)).reduce(addSumAndCountForExport(this), []);
|
|
return {
|
|
name: this.name,
|
|
help: this.help,
|
|
type: this.type,
|
|
values,
|
|
aggregator: this.aggregator
|
|
};
|
|
}
|
|
reset() {
|
|
this.hashMap = {};
|
|
}
|
|
/**
|
|
* Initialize the metrics for the given combination of labels to zero
|
|
* @param {object} labels - Object with labels where key is the label key and value is label value. Can only be one level deep
|
|
* @returns {void}
|
|
*/
|
|
zero(labels) {
|
|
const hash = hashObject(labels, this.sortedLabelNames);
|
|
this.hashMap[hash] = createBaseValues(
|
|
labels,
|
|
this.bucketValues,
|
|
this.bucketExemplars
|
|
);
|
|
}
|
|
/**
|
|
* Start a timer that could be used to logging durations
|
|
* @param {object} labels - Object with labels where key is the label key and value is label value. Can only be one level deep
|
|
* @param {object} exemplarLabels - Object with labels for exemplar where key is the label key and value is label value. Can only be one level deep
|
|
* @returns {function} - Function to invoke when you want to stop the timer and observe the duration in seconds
|
|
* @example
|
|
* var end = histogram.startTimer();
|
|
* makeExpensiveXHRRequest(function(err, res) {
|
|
* const duration = end(); //Observe the duration of expensiveXHRRequest and returns duration in seconds
|
|
* console.log('Duration', duration);
|
|
* });
|
|
*/
|
|
startTimer(labels, exemplarLabels) {
|
|
return this.enableExemplars ? startTimerWithExemplar.call(this, labels, exemplarLabels)() : startTimer.call(this, labels)();
|
|
}
|
|
labels(...args) {
|
|
const labels = getLabels(this.labelNames, args);
|
|
validateLabel(this.labelNames, labels);
|
|
return {
|
|
observe: observe.call(this, labels),
|
|
startTimer: startTimer.call(this, labels)
|
|
};
|
|
}
|
|
remove(...args) {
|
|
const labels = getLabels(this.labelNames, args);
|
|
validateLabel(this.labelNames, labels);
|
|
removeLabels.call(this, this.hashMap, labels, this.sortedLabelNames);
|
|
}
|
|
};
|
|
function startTimer(startLabels) {
|
|
return () => {
|
|
const start = process.hrtime();
|
|
return (endLabels) => {
|
|
const delta = process.hrtime(start);
|
|
const value = delta[0] + delta[1] / 1e9;
|
|
this.observe(Object.assign({}, startLabels, endLabels), value);
|
|
return value;
|
|
};
|
|
};
|
|
}
|
|
function startTimerWithExemplar(startLabels, startExemplarLabels) {
|
|
return () => {
|
|
const start = process.hrtime();
|
|
return (endLabels, endExemplarLabels) => {
|
|
const delta = process.hrtime(start);
|
|
const value = delta[0] + delta[1] / 1e9;
|
|
this.observe({
|
|
labels: Object.assign({}, startLabels, endLabels),
|
|
value,
|
|
exemplarLabels: Object.assign(
|
|
{},
|
|
startExemplarLabels,
|
|
endExemplarLabels
|
|
)
|
|
});
|
|
return value;
|
|
};
|
|
};
|
|
}
|
|
function setValuePair(labels, value, metricName, exemplar, sharedLabels = {}) {
|
|
return {
|
|
labels,
|
|
sharedLabels,
|
|
value,
|
|
metricName,
|
|
exemplar
|
|
};
|
|
}
|
|
function findBound(upperBounds, value) {
|
|
for (let i = 0; i < upperBounds.length; i++) {
|
|
const bound = upperBounds[i];
|
|
if (value <= bound) {
|
|
return bound;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
function observe(labels) {
|
|
return (value) => {
|
|
const labelValuePair = convertLabelsAndValues(labels, value);
|
|
validateLabel(this.labelNames, labelValuePair.labels);
|
|
if (!Number.isFinite(labelValuePair.value)) {
|
|
throw new TypeError(
|
|
`Value is not a valid number: ${util.format(labelValuePair.value)}`
|
|
);
|
|
}
|
|
const hash = hashObject(labelValuePair.labels, this.sortedLabelNames);
|
|
let valueFromMap = this.hashMap[hash];
|
|
if (!valueFromMap) {
|
|
valueFromMap = createBaseValues(
|
|
labelValuePair.labels,
|
|
this.bucketValues,
|
|
this.bucketExemplars
|
|
);
|
|
}
|
|
const b = findBound(this.upperBounds, labelValuePair.value);
|
|
valueFromMap.sum += labelValuePair.value;
|
|
valueFromMap.count += 1;
|
|
if (Object.prototype.hasOwnProperty.call(valueFromMap.bucketValues, b)) {
|
|
valueFromMap.bucketValues[b] += 1;
|
|
}
|
|
this.hashMap[hash] = valueFromMap;
|
|
};
|
|
}
|
|
function createBaseValues(labels, bucketValues, bucketExemplars) {
|
|
const result = {
|
|
labels,
|
|
bucketValues: { ...bucketValues },
|
|
sum: 0,
|
|
count: 0
|
|
};
|
|
if (bucketExemplars) {
|
|
result.bucketExemplars = { ...bucketExemplars };
|
|
}
|
|
return result;
|
|
}
|
|
function convertLabelsAndValues(labels, value) {
|
|
return isObject(labels) ? {
|
|
labels,
|
|
value
|
|
} : {
|
|
value: labels,
|
|
labels: {}
|
|
};
|
|
}
|
|
function extractBucketValuesForExport(histogram) {
|
|
const name = `${histogram.name}_bucket`;
|
|
return (bucketData) => {
|
|
let acc = 0;
|
|
const buckets = histogram.upperBounds.map((upperBound) => {
|
|
acc += bucketData.bucketValues[upperBound];
|
|
return setValuePair(
|
|
{ le: upperBound },
|
|
acc,
|
|
name,
|
|
bucketData.bucketExemplars ? bucketData.bucketExemplars[upperBound] : null,
|
|
bucketData.labels
|
|
);
|
|
});
|
|
return { buckets, data: bucketData };
|
|
};
|
|
}
|
|
function addSumAndCountForExport(histogram) {
|
|
return (acc, d) => {
|
|
acc.push(...d.buckets);
|
|
const infLabel = { le: "+Inf" };
|
|
acc.push(
|
|
setValuePair(
|
|
infLabel,
|
|
d.data.count,
|
|
`${histogram.name}_bucket`,
|
|
d.data.bucketExemplars ? d.data.bucketExemplars["-1"] : null,
|
|
d.data.labels
|
|
),
|
|
setValuePair(
|
|
{},
|
|
d.data.sum,
|
|
`${histogram.name}_sum`,
|
|
void 0,
|
|
d.data.labels
|
|
),
|
|
setValuePair(
|
|
{},
|
|
d.data.count,
|
|
`${histogram.name}_count`,
|
|
void 0,
|
|
d.data.labels
|
|
)
|
|
);
|
|
return acc;
|
|
};
|
|
}
|
|
function splayLabels(bucket) {
|
|
const { sharedLabels, labels, ...newBucket } = bucket;
|
|
for (const label of Object.keys(sharedLabels)) {
|
|
labels[label] = sharedLabels[label];
|
|
}
|
|
newBucket.labels = labels;
|
|
return newBucket;
|
|
}
|
|
module.exports = Histogram;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bintrees/lib/treebase.js
|
|
var require_treebase = __commonJS({
|
|
"../../node_modules/bintrees/lib/treebase.js"(exports, module) {
|
|
function TreeBase() {
|
|
}
|
|
TreeBase.prototype.clear = function() {
|
|
this._root = null;
|
|
this.size = 0;
|
|
};
|
|
TreeBase.prototype.find = function(data) {
|
|
var res = this._root;
|
|
while (res !== null) {
|
|
var c = this._comparator(data, res.data);
|
|
if (c === 0) {
|
|
return res.data;
|
|
} else {
|
|
res = res.get_child(c > 0);
|
|
}
|
|
}
|
|
return null;
|
|
};
|
|
TreeBase.prototype.findIter = function(data) {
|
|
var res = this._root;
|
|
var iter = this.iterator();
|
|
while (res !== null) {
|
|
var c = this._comparator(data, res.data);
|
|
if (c === 0) {
|
|
iter._cursor = res;
|
|
return iter;
|
|
} else {
|
|
iter._ancestors.push(res);
|
|
res = res.get_child(c > 0);
|
|
}
|
|
}
|
|
return null;
|
|
};
|
|
TreeBase.prototype.lowerBound = function(item) {
|
|
var cur = this._root;
|
|
var iter = this.iterator();
|
|
var cmp = this._comparator;
|
|
while (cur !== null) {
|
|
var c = cmp(item, cur.data);
|
|
if (c === 0) {
|
|
iter._cursor = cur;
|
|
return iter;
|
|
}
|
|
iter._ancestors.push(cur);
|
|
cur = cur.get_child(c > 0);
|
|
}
|
|
for (var i = iter._ancestors.length - 1; i >= 0; --i) {
|
|
cur = iter._ancestors[i];
|
|
if (cmp(item, cur.data) < 0) {
|
|
iter._cursor = cur;
|
|
iter._ancestors.length = i;
|
|
return iter;
|
|
}
|
|
}
|
|
iter._ancestors.length = 0;
|
|
return iter;
|
|
};
|
|
TreeBase.prototype.upperBound = function(item) {
|
|
var iter = this.lowerBound(item);
|
|
var cmp = this._comparator;
|
|
while (iter.data() !== null && cmp(iter.data(), item) === 0) {
|
|
iter.next();
|
|
}
|
|
return iter;
|
|
};
|
|
TreeBase.prototype.min = function() {
|
|
var res = this._root;
|
|
if (res === null) {
|
|
return null;
|
|
}
|
|
while (res.left !== null) {
|
|
res = res.left;
|
|
}
|
|
return res.data;
|
|
};
|
|
TreeBase.prototype.max = function() {
|
|
var res = this._root;
|
|
if (res === null) {
|
|
return null;
|
|
}
|
|
while (res.right !== null) {
|
|
res = res.right;
|
|
}
|
|
return res.data;
|
|
};
|
|
TreeBase.prototype.iterator = function() {
|
|
return new Iterator(this);
|
|
};
|
|
TreeBase.prototype.each = function(cb) {
|
|
var it = this.iterator(), data;
|
|
while ((data = it.next()) !== null) {
|
|
if (cb(data) === false) {
|
|
return;
|
|
}
|
|
}
|
|
};
|
|
TreeBase.prototype.reach = function(cb) {
|
|
var it = this.iterator(), data;
|
|
while ((data = it.prev()) !== null) {
|
|
if (cb(data) === false) {
|
|
return;
|
|
}
|
|
}
|
|
};
|
|
function Iterator(tree) {
|
|
this._tree = tree;
|
|
this._ancestors = [];
|
|
this._cursor = null;
|
|
}
|
|
Iterator.prototype.data = function() {
|
|
return this._cursor !== null ? this._cursor.data : null;
|
|
};
|
|
Iterator.prototype.next = function() {
|
|
if (this._cursor === null) {
|
|
var root = this._tree._root;
|
|
if (root !== null) {
|
|
this._minNode(root);
|
|
}
|
|
} else {
|
|
if (this._cursor.right === null) {
|
|
var save;
|
|
do {
|
|
save = this._cursor;
|
|
if (this._ancestors.length) {
|
|
this._cursor = this._ancestors.pop();
|
|
} else {
|
|
this._cursor = null;
|
|
break;
|
|
}
|
|
} while (this._cursor.right === save);
|
|
} else {
|
|
this._ancestors.push(this._cursor);
|
|
this._minNode(this._cursor.right);
|
|
}
|
|
}
|
|
return this._cursor !== null ? this._cursor.data : null;
|
|
};
|
|
Iterator.prototype.prev = function() {
|
|
if (this._cursor === null) {
|
|
var root = this._tree._root;
|
|
if (root !== null) {
|
|
this._maxNode(root);
|
|
}
|
|
} else {
|
|
if (this._cursor.left === null) {
|
|
var save;
|
|
do {
|
|
save = this._cursor;
|
|
if (this._ancestors.length) {
|
|
this._cursor = this._ancestors.pop();
|
|
} else {
|
|
this._cursor = null;
|
|
break;
|
|
}
|
|
} while (this._cursor.left === save);
|
|
} else {
|
|
this._ancestors.push(this._cursor);
|
|
this._maxNode(this._cursor.left);
|
|
}
|
|
}
|
|
return this._cursor !== null ? this._cursor.data : null;
|
|
};
|
|
Iterator.prototype._minNode = function(start) {
|
|
while (start.left !== null) {
|
|
this._ancestors.push(start);
|
|
start = start.left;
|
|
}
|
|
this._cursor = start;
|
|
};
|
|
Iterator.prototype._maxNode = function(start) {
|
|
while (start.right !== null) {
|
|
this._ancestors.push(start);
|
|
start = start.right;
|
|
}
|
|
this._cursor = start;
|
|
};
|
|
module.exports = TreeBase;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bintrees/lib/rbtree.js
|
|
var require_rbtree = __commonJS({
|
|
"../../node_modules/bintrees/lib/rbtree.js"(exports, module) {
|
|
var TreeBase = require_treebase();
|
|
function Node(data) {
|
|
this.data = data;
|
|
this.left = null;
|
|
this.right = null;
|
|
this.red = true;
|
|
}
|
|
Node.prototype.get_child = function(dir) {
|
|
return dir ? this.right : this.left;
|
|
};
|
|
Node.prototype.set_child = function(dir, val) {
|
|
if (dir) {
|
|
this.right = val;
|
|
} else {
|
|
this.left = val;
|
|
}
|
|
};
|
|
function RBTree(comparator) {
|
|
this._root = null;
|
|
this._comparator = comparator;
|
|
this.size = 0;
|
|
}
|
|
RBTree.prototype = new TreeBase();
|
|
RBTree.prototype.insert = function(data) {
|
|
var ret2 = false;
|
|
if (this._root === null) {
|
|
this._root = new Node(data);
|
|
ret2 = true;
|
|
this.size++;
|
|
} else {
|
|
var head = new Node(void 0);
|
|
var dir = 0;
|
|
var last = 0;
|
|
var gp = null;
|
|
var ggp = head;
|
|
var p = null;
|
|
var node = this._root;
|
|
ggp.right = this._root;
|
|
while (true) {
|
|
if (node === null) {
|
|
node = new Node(data);
|
|
p.set_child(dir, node);
|
|
ret2 = true;
|
|
this.size++;
|
|
} else if (is_red(node.left) && is_red(node.right)) {
|
|
node.red = true;
|
|
node.left.red = false;
|
|
node.right.red = false;
|
|
}
|
|
if (is_red(node) && is_red(p)) {
|
|
var dir2 = ggp.right === gp;
|
|
if (node === p.get_child(last)) {
|
|
ggp.set_child(dir2, single_rotate(gp, !last));
|
|
} else {
|
|
ggp.set_child(dir2, double_rotate(gp, !last));
|
|
}
|
|
}
|
|
var cmp = this._comparator(node.data, data);
|
|
if (cmp === 0) {
|
|
break;
|
|
}
|
|
last = dir;
|
|
dir = cmp < 0;
|
|
if (gp !== null) {
|
|
ggp = gp;
|
|
}
|
|
gp = p;
|
|
p = node;
|
|
node = node.get_child(dir);
|
|
}
|
|
this._root = head.right;
|
|
}
|
|
this._root.red = false;
|
|
return ret2;
|
|
};
|
|
RBTree.prototype.remove = function(data) {
|
|
if (this._root === null) {
|
|
return false;
|
|
}
|
|
var head = new Node(void 0);
|
|
var node = head;
|
|
node.right = this._root;
|
|
var p = null;
|
|
var gp = null;
|
|
var found = null;
|
|
var dir = 1;
|
|
while (node.get_child(dir) !== null) {
|
|
var last = dir;
|
|
gp = p;
|
|
p = node;
|
|
node = node.get_child(dir);
|
|
var cmp = this._comparator(data, node.data);
|
|
dir = cmp > 0;
|
|
if (cmp === 0) {
|
|
found = node;
|
|
}
|
|
if (!is_red(node) && !is_red(node.get_child(dir))) {
|
|
if (is_red(node.get_child(!dir))) {
|
|
var sr = single_rotate(node, dir);
|
|
p.set_child(last, sr);
|
|
p = sr;
|
|
} else if (!is_red(node.get_child(!dir))) {
|
|
var sibling = p.get_child(!last);
|
|
if (sibling !== null) {
|
|
if (!is_red(sibling.get_child(!last)) && !is_red(sibling.get_child(last))) {
|
|
p.red = false;
|
|
sibling.red = true;
|
|
node.red = true;
|
|
} else {
|
|
var dir2 = gp.right === p;
|
|
if (is_red(sibling.get_child(last))) {
|
|
gp.set_child(dir2, double_rotate(p, last));
|
|
} else if (is_red(sibling.get_child(!last))) {
|
|
gp.set_child(dir2, single_rotate(p, last));
|
|
}
|
|
var gpc = gp.get_child(dir2);
|
|
gpc.red = true;
|
|
node.red = true;
|
|
gpc.left.red = false;
|
|
gpc.right.red = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (found !== null) {
|
|
found.data = node.data;
|
|
p.set_child(p.right === node, node.get_child(node.left === null));
|
|
this.size--;
|
|
}
|
|
this._root = head.right;
|
|
if (this._root !== null) {
|
|
this._root.red = false;
|
|
}
|
|
return found !== null;
|
|
};
|
|
function is_red(node) {
|
|
return node !== null && node.red;
|
|
}
|
|
function single_rotate(root, dir) {
|
|
var save = root.get_child(!dir);
|
|
root.set_child(!dir, save.get_child(dir));
|
|
save.set_child(dir, root);
|
|
root.red = true;
|
|
save.red = false;
|
|
return save;
|
|
}
|
|
function double_rotate(root, dir) {
|
|
root.set_child(!dir, single_rotate(root.get_child(!dir), !dir));
|
|
return single_rotate(root, dir);
|
|
}
|
|
module.exports = RBTree;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bintrees/lib/bintree.js
|
|
var require_bintree = __commonJS({
|
|
"../../node_modules/bintrees/lib/bintree.js"(exports, module) {
|
|
var TreeBase = require_treebase();
|
|
function Node(data) {
|
|
this.data = data;
|
|
this.left = null;
|
|
this.right = null;
|
|
}
|
|
Node.prototype.get_child = function(dir) {
|
|
return dir ? this.right : this.left;
|
|
};
|
|
Node.prototype.set_child = function(dir, val) {
|
|
if (dir) {
|
|
this.right = val;
|
|
} else {
|
|
this.left = val;
|
|
}
|
|
};
|
|
function BinTree(comparator) {
|
|
this._root = null;
|
|
this._comparator = comparator;
|
|
this.size = 0;
|
|
}
|
|
BinTree.prototype = new TreeBase();
|
|
BinTree.prototype.insert = function(data) {
|
|
if (this._root === null) {
|
|
this._root = new Node(data);
|
|
this.size++;
|
|
return true;
|
|
}
|
|
var dir = 0;
|
|
var p = null;
|
|
var node = this._root;
|
|
while (true) {
|
|
if (node === null) {
|
|
node = new Node(data);
|
|
p.set_child(dir, node);
|
|
ret = true;
|
|
this.size++;
|
|
return true;
|
|
}
|
|
if (this._comparator(node.data, data) === 0) {
|
|
return false;
|
|
}
|
|
dir = this._comparator(node.data, data) < 0;
|
|
p = node;
|
|
node = node.get_child(dir);
|
|
}
|
|
};
|
|
BinTree.prototype.remove = function(data) {
|
|
if (this._root === null) {
|
|
return false;
|
|
}
|
|
var head = new Node(void 0);
|
|
var node = head;
|
|
node.right = this._root;
|
|
var p = null;
|
|
var found = null;
|
|
var dir = 1;
|
|
while (node.get_child(dir) !== null) {
|
|
p = node;
|
|
node = node.get_child(dir);
|
|
var cmp = this._comparator(data, node.data);
|
|
dir = cmp > 0;
|
|
if (cmp === 0) {
|
|
found = node;
|
|
}
|
|
}
|
|
if (found !== null) {
|
|
found.data = node.data;
|
|
p.set_child(p.right === node, node.get_child(node.left === null));
|
|
this._root = head.right;
|
|
this.size--;
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
};
|
|
module.exports = BinTree;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bintrees/index.js
|
|
var require_bintrees = __commonJS({
|
|
"../../node_modules/bintrees/index.js"(exports, module) {
|
|
module.exports = {
|
|
RBTree: require_rbtree(),
|
|
BinTree: require_bintree()
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/tdigest/tdigest.js
|
|
var require_tdigest = __commonJS({
|
|
"../../node_modules/tdigest/tdigest.js"(exports, module) {
|
|
var RBTree = require_bintrees().RBTree;
|
|
function TDigest(delta, K, CX) {
|
|
this.discrete = delta === false;
|
|
this.delta = delta || 0.01;
|
|
this.K = K === void 0 ? 25 : K;
|
|
this.CX = CX === void 0 ? 1.1 : CX;
|
|
this.centroids = new RBTree(compare_centroid_means);
|
|
this.nreset = 0;
|
|
this.reset();
|
|
}
|
|
TDigest.prototype.reset = function() {
|
|
this.centroids.clear();
|
|
this.n = 0;
|
|
this.nreset += 1;
|
|
this.last_cumulate = 0;
|
|
};
|
|
TDigest.prototype.size = function() {
|
|
return this.centroids.size;
|
|
};
|
|
TDigest.prototype.toArray = function(everything) {
|
|
var result = [];
|
|
if (everything) {
|
|
this._cumulate(true);
|
|
this.centroids.each(function(c) {
|
|
result.push(c);
|
|
});
|
|
} else {
|
|
this.centroids.each(function(c) {
|
|
result.push({ mean: c.mean, n: c.n });
|
|
});
|
|
}
|
|
return result;
|
|
};
|
|
TDigest.prototype.summary = function() {
|
|
var approx = this.discrete ? "exact " : "approximating ";
|
|
var s = [
|
|
approx + this.n + " samples using " + this.size() + " centroids",
|
|
"min = " + this.percentile(0),
|
|
"Q1 = " + this.percentile(0.25),
|
|
"Q2 = " + this.percentile(0.5),
|
|
"Q3 = " + this.percentile(0.75),
|
|
"max = " + this.percentile(1)
|
|
];
|
|
return s.join("\n");
|
|
};
|
|
function compare_centroid_means(a, b) {
|
|
return a.mean > b.mean ? 1 : a.mean < b.mean ? -1 : 0;
|
|
}
|
|
function compare_centroid_mean_cumns(a, b) {
|
|
return a.mean_cumn - b.mean_cumn;
|
|
}
|
|
TDigest.prototype.push = function(x, n) {
|
|
n = n || 1;
|
|
x = Array.isArray(x) ? x : [x];
|
|
for (var i = 0; i < x.length; i++) {
|
|
this._digest(x[i], n);
|
|
}
|
|
};
|
|
TDigest.prototype.push_centroid = function(c) {
|
|
c = Array.isArray(c) ? c : [c];
|
|
for (var i = 0; i < c.length; i++) {
|
|
this._digest(c[i].mean, c[i].n);
|
|
}
|
|
};
|
|
TDigest.prototype._cumulate = function(exact) {
|
|
if (this.n === this.last_cumulate || !exact && this.CX && this.CX > this.n / this.last_cumulate) {
|
|
return;
|
|
}
|
|
var cumn = 0;
|
|
this.centroids.each(function(c) {
|
|
c.mean_cumn = cumn + c.n / 2;
|
|
cumn = c.cumn = cumn + c.n;
|
|
});
|
|
this.n = this.last_cumulate = cumn;
|
|
};
|
|
TDigest.prototype.find_nearest = function(x) {
|
|
if (this.size() === 0) {
|
|
return null;
|
|
}
|
|
var iter = this.centroids.lowerBound({ mean: x });
|
|
var c = iter.data() === null ? iter.prev() : iter.data();
|
|
if (c.mean === x || this.discrete) {
|
|
return c;
|
|
}
|
|
var prev = iter.prev();
|
|
if (prev && Math.abs(prev.mean - x) < Math.abs(c.mean - x)) {
|
|
return prev;
|
|
} else {
|
|
return c;
|
|
}
|
|
};
|
|
TDigest.prototype._new_centroid = function(x, n, cumn) {
|
|
var c = { mean: x, n, cumn };
|
|
this.centroids.insert(c);
|
|
this.n += n;
|
|
return c;
|
|
};
|
|
TDigest.prototype._addweight = function(nearest, x, n) {
|
|
if (x !== nearest.mean) {
|
|
nearest.mean += n * (x - nearest.mean) / (nearest.n + n);
|
|
}
|
|
nearest.cumn += n;
|
|
nearest.mean_cumn += n / 2;
|
|
nearest.n += n;
|
|
this.n += n;
|
|
};
|
|
TDigest.prototype._digest = function(x, n) {
|
|
var min = this.centroids.min();
|
|
var max = this.centroids.max();
|
|
var nearest = this.find_nearest(x);
|
|
if (nearest && nearest.mean === x) {
|
|
this._addweight(nearest, x, n);
|
|
} else if (nearest === min) {
|
|
this._new_centroid(x, n, 0);
|
|
} else if (nearest === max) {
|
|
this._new_centroid(x, n, this.n);
|
|
} else if (this.discrete) {
|
|
this._new_centroid(x, n, nearest.cumn);
|
|
} else {
|
|
var p = nearest.mean_cumn / this.n;
|
|
var max_n = Math.floor(4 * this.n * this.delta * p * (1 - p));
|
|
if (max_n - nearest.n >= n) {
|
|
this._addweight(nearest, x, n);
|
|
} else {
|
|
this._new_centroid(x, n, nearest.cumn);
|
|
}
|
|
}
|
|
this._cumulate(false);
|
|
if (!this.discrete && this.K && this.size() > this.K / this.delta) {
|
|
this.compress();
|
|
}
|
|
};
|
|
TDigest.prototype.bound_mean = function(x) {
|
|
var iter = this.centroids.upperBound({ mean: x });
|
|
var lower = iter.prev();
|
|
var upper = lower.mean === x ? lower : iter.next();
|
|
return [lower, upper];
|
|
};
|
|
TDigest.prototype.p_rank = function(x_or_xlist) {
|
|
var xs = Array.isArray(x_or_xlist) ? x_or_xlist : [x_or_xlist];
|
|
var ps = xs.map(this._p_rank, this);
|
|
return Array.isArray(x_or_xlist) ? ps : ps[0];
|
|
};
|
|
TDigest.prototype._p_rank = function(x) {
|
|
if (this.size() === 0) {
|
|
return void 0;
|
|
} else if (x < this.centroids.min().mean) {
|
|
return 0;
|
|
} else if (x > this.centroids.max().mean) {
|
|
return 1;
|
|
}
|
|
this._cumulate(true);
|
|
var bound = this.bound_mean(x);
|
|
var lower = bound[0], upper = bound[1];
|
|
if (this.discrete) {
|
|
return lower.cumn / this.n;
|
|
} else {
|
|
var cumn = lower.mean_cumn;
|
|
if (lower !== upper) {
|
|
cumn += (x - lower.mean) * (upper.mean_cumn - lower.mean_cumn) / (upper.mean - lower.mean);
|
|
}
|
|
return cumn / this.n;
|
|
}
|
|
};
|
|
TDigest.prototype.bound_mean_cumn = function(cumn) {
|
|
this.centroids._comparator = compare_centroid_mean_cumns;
|
|
var iter = this.centroids.upperBound({ mean_cumn: cumn });
|
|
this.centroids._comparator = compare_centroid_means;
|
|
var lower = iter.prev();
|
|
var upper = lower && lower.mean_cumn === cumn ? lower : iter.next();
|
|
return [lower, upper];
|
|
};
|
|
TDigest.prototype.percentile = function(p_or_plist) {
|
|
var ps = Array.isArray(p_or_plist) ? p_or_plist : [p_or_plist];
|
|
var qs = ps.map(this._percentile, this);
|
|
return Array.isArray(p_or_plist) ? qs : qs[0];
|
|
};
|
|
TDigest.prototype._percentile = function(p) {
|
|
if (this.size() === 0) {
|
|
return void 0;
|
|
}
|
|
this._cumulate(true);
|
|
var h = this.n * p;
|
|
var bound = this.bound_mean_cumn(h);
|
|
var lower = bound[0], upper = bound[1];
|
|
if (upper === lower || lower === null || upper === null) {
|
|
return (lower || upper).mean;
|
|
} else if (!this.discrete) {
|
|
return lower.mean + (h - lower.mean_cumn) * (upper.mean - lower.mean) / (upper.mean_cumn - lower.mean_cumn);
|
|
} else if (h <= lower.cumn) {
|
|
return lower.mean;
|
|
} else {
|
|
return upper.mean;
|
|
}
|
|
};
|
|
function pop_random(choices) {
|
|
var idx = Math.floor(Math.random() * choices.length);
|
|
return choices.splice(idx, 1)[0];
|
|
}
|
|
TDigest.prototype.compress = function() {
|
|
if (this.compressing) {
|
|
return;
|
|
}
|
|
var points = this.toArray();
|
|
this.reset();
|
|
this.compressing = true;
|
|
while (points.length > 0) {
|
|
this.push_centroid(pop_random(points));
|
|
}
|
|
this._cumulate(true);
|
|
this.compressing = false;
|
|
};
|
|
function Digest(config) {
|
|
this.config = config || {};
|
|
this.mode = this.config.mode || "auto";
|
|
TDigest.call(this, this.mode === "cont" ? config.delta : false);
|
|
this.digest_ratio = this.config.ratio || 0.9;
|
|
this.digest_thresh = this.config.thresh || 1e3;
|
|
this.n_unique = 0;
|
|
}
|
|
Digest.prototype = Object.create(TDigest.prototype);
|
|
Digest.prototype.constructor = Digest;
|
|
Digest.prototype.push = function(x_or_xlist) {
|
|
TDigest.prototype.push.call(this, x_or_xlist);
|
|
this.check_continuous();
|
|
};
|
|
Digest.prototype._new_centroid = function(x, n, cumn) {
|
|
this.n_unique += 1;
|
|
TDigest.prototype._new_centroid.call(this, x, n, cumn);
|
|
};
|
|
Digest.prototype._addweight = function(nearest, x, n) {
|
|
if (nearest.n === 1) {
|
|
this.n_unique -= 1;
|
|
}
|
|
TDigest.prototype._addweight.call(this, nearest, x, n);
|
|
};
|
|
Digest.prototype.check_continuous = function() {
|
|
if (this.mode !== "auto" || this.size() < this.digest_thresh) {
|
|
return false;
|
|
}
|
|
if (this.n_unique / this.size() > this.digest_ratio) {
|
|
this.mode = "cont";
|
|
this.discrete = false;
|
|
this.delta = this.config.delta || 0.01;
|
|
this.compress();
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
module.exports = {
|
|
"TDigest": TDigest,
|
|
"Digest": Digest
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/timeWindowQuantiles.js
|
|
var require_timeWindowQuantiles = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/timeWindowQuantiles.js"(exports, module) {
|
|
"use strict";
|
|
var { TDigest } = require_tdigest();
|
|
var TimeWindowQuantiles = class {
|
|
constructor(maxAgeSeconds, ageBuckets) {
|
|
this.maxAgeSeconds = maxAgeSeconds || 0;
|
|
this.ageBuckets = ageBuckets || 0;
|
|
this.shouldRotate = maxAgeSeconds && ageBuckets;
|
|
this.ringBuffer = Array(ageBuckets).fill(new TDigest());
|
|
this.currentBuffer = 0;
|
|
this.lastRotateTimestampMillis = Date.now();
|
|
this.durationBetweenRotatesMillis = maxAgeSeconds * 1e3 / ageBuckets || Infinity;
|
|
}
|
|
size() {
|
|
const bucket = rotate.call(this);
|
|
return bucket.size();
|
|
}
|
|
percentile(quantile) {
|
|
const bucket = rotate.call(this);
|
|
return bucket.percentile(quantile);
|
|
}
|
|
push(value) {
|
|
rotate.call(this);
|
|
this.ringBuffer.forEach((bucket) => {
|
|
bucket.push(value);
|
|
});
|
|
}
|
|
reset() {
|
|
this.ringBuffer.forEach((bucket) => {
|
|
bucket.reset();
|
|
});
|
|
}
|
|
compress() {
|
|
this.ringBuffer.forEach((bucket) => {
|
|
bucket.compress();
|
|
});
|
|
}
|
|
};
|
|
function rotate() {
|
|
let timeSinceLastRotateMillis = Date.now() - this.lastRotateTimestampMillis;
|
|
while (timeSinceLastRotateMillis > this.durationBetweenRotatesMillis && this.shouldRotate) {
|
|
this.ringBuffer[this.currentBuffer] = new TDigest();
|
|
if (++this.currentBuffer >= this.ringBuffer.length) {
|
|
this.currentBuffer = 0;
|
|
}
|
|
timeSinceLastRotateMillis -= this.durationBetweenRotatesMillis;
|
|
this.lastRotateTimestampMillis += this.durationBetweenRotatesMillis;
|
|
}
|
|
return this.ringBuffer[this.currentBuffer];
|
|
}
|
|
module.exports = TimeWindowQuantiles;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/summary.js
|
|
var require_summary = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/summary.js"(exports, module) {
|
|
"use strict";
|
|
var process = __require("process");
|
|
var util = __require("util");
|
|
var { getLabels, hashObject, removeLabels } = require_util();
|
|
var { validateLabel } = require_validation();
|
|
var { Metric } = require_metric();
|
|
var timeWindowQuantiles = require_timeWindowQuantiles();
|
|
var DEFAULT_COMPRESS_COUNT = 1e3;
|
|
var Summary = class extends Metric {
|
|
constructor(config) {
|
|
super(config, {
|
|
percentiles: [0.01, 0.05, 0.5, 0.9, 0.95, 0.99, 0.999],
|
|
compressCount: DEFAULT_COMPRESS_COUNT,
|
|
hashMap: {}
|
|
});
|
|
this.type = "summary";
|
|
for (const label of this.labelNames) {
|
|
if (label === "quantile")
|
|
throw new Error("quantile is a reserved label keyword");
|
|
}
|
|
if (this.labelNames.length === 0) {
|
|
this.hashMap = {
|
|
[hashObject({})]: {
|
|
labels: {},
|
|
td: new timeWindowQuantiles(this.maxAgeSeconds, this.ageBuckets),
|
|
count: 0,
|
|
sum: 0
|
|
}
|
|
};
|
|
}
|
|
}
|
|
/**
|
|
* Observe a value
|
|
* @param {object} labels - Object with labels where key is the label key and value is label value. Can only be one level deep
|
|
* @param {Number} value - Value to observe
|
|
* @returns {void}
|
|
*/
|
|
observe(labels, value) {
|
|
observe.call(this, labels === 0 ? 0 : labels || {})(value);
|
|
}
|
|
async get() {
|
|
if (this.collect) {
|
|
const v = this.collect();
|
|
if (v instanceof Promise) await v;
|
|
}
|
|
const hashKeys = Object.keys(this.hashMap);
|
|
const values = [];
|
|
hashKeys.forEach((hashKey) => {
|
|
const s = this.hashMap[hashKey];
|
|
if (s) {
|
|
if (this.pruneAgedBuckets && s.td.size() === 0) {
|
|
delete this.hashMap[hashKey];
|
|
} else {
|
|
extractSummariesForExport(s, this.percentiles).forEach((v) => {
|
|
values.push(v);
|
|
});
|
|
values.push(getSumForExport(s, this));
|
|
values.push(getCountForExport(s, this));
|
|
}
|
|
}
|
|
});
|
|
return {
|
|
name: this.name,
|
|
help: this.help,
|
|
type: this.type,
|
|
values,
|
|
aggregator: this.aggregator
|
|
};
|
|
}
|
|
reset() {
|
|
const data = Object.values(this.hashMap);
|
|
data.forEach((s) => {
|
|
s.td.reset();
|
|
s.count = 0;
|
|
s.sum = 0;
|
|
});
|
|
}
|
|
/**
|
|
* Start a timer that could be used to logging durations
|
|
* @param {object} labels - Object with labels where key is the label key and value is label value. Can only be one level deep
|
|
* @returns {function} - Function to invoke when you want to stop the timer and observe the duration in seconds
|
|
* @example
|
|
* var end = summary.startTimer();
|
|
* makeExpensiveXHRRequest(function(err, res) {
|
|
* end(); //Observe the duration of expensiveXHRRequest
|
|
* });
|
|
*/
|
|
startTimer(labels) {
|
|
return startTimer.call(this, labels)();
|
|
}
|
|
labels(...args) {
|
|
const labels = getLabels(this.labelNames, args);
|
|
validateLabel(this.labelNames, labels);
|
|
return {
|
|
observe: observe.call(this, labels),
|
|
startTimer: startTimer.call(this, labels)
|
|
};
|
|
}
|
|
remove(...args) {
|
|
const labels = getLabels(this.labelNames, args);
|
|
validateLabel(this.labelNames, labels);
|
|
removeLabels.call(this, this.hashMap, labels, this.sortedLabelNames);
|
|
}
|
|
};
|
|
function extractSummariesForExport(summaryOfLabels, percentiles) {
|
|
summaryOfLabels.td.compress();
|
|
return percentiles.map((percentile) => {
|
|
const percentileValue = summaryOfLabels.td.percentile(percentile);
|
|
return {
|
|
labels: Object.assign({ quantile: percentile }, summaryOfLabels.labels),
|
|
value: percentileValue ? percentileValue : 0
|
|
};
|
|
});
|
|
}
|
|
function getCountForExport(value, summary) {
|
|
return {
|
|
metricName: `${summary.name}_count`,
|
|
labels: value.labels,
|
|
value: value.count
|
|
};
|
|
}
|
|
function getSumForExport(value, summary) {
|
|
return {
|
|
metricName: `${summary.name}_sum`,
|
|
labels: value.labels,
|
|
value: value.sum
|
|
};
|
|
}
|
|
function startTimer(startLabels) {
|
|
return () => {
|
|
const start = process.hrtime();
|
|
return (endLabels) => {
|
|
const delta = process.hrtime(start);
|
|
const value = delta[0] + delta[1] / 1e9;
|
|
this.observe(Object.assign({}, startLabels, endLabels), value);
|
|
return value;
|
|
};
|
|
};
|
|
}
|
|
function observe(labels) {
|
|
return (value) => {
|
|
const labelValuePair = convertLabelsAndValues(labels, value);
|
|
validateLabel(this.labelNames, labels);
|
|
if (!Number.isFinite(labelValuePair.value)) {
|
|
throw new TypeError(
|
|
`Value is not a valid number: ${util.format(labelValuePair.value)}`
|
|
);
|
|
}
|
|
const hash = hashObject(labelValuePair.labels, this.sortedLabelNames);
|
|
let summaryOfLabel = this.hashMap[hash];
|
|
if (!summaryOfLabel) {
|
|
summaryOfLabel = {
|
|
labels: labelValuePair.labels,
|
|
td: new timeWindowQuantiles(this.maxAgeSeconds, this.ageBuckets),
|
|
count: 0,
|
|
sum: 0
|
|
};
|
|
}
|
|
summaryOfLabel.td.push(labelValuePair.value);
|
|
summaryOfLabel.count++;
|
|
if (summaryOfLabel.count % this.compressCount === 0) {
|
|
summaryOfLabel.td.compress();
|
|
}
|
|
summaryOfLabel.sum += labelValuePair.value;
|
|
this.hashMap[hash] = summaryOfLabel;
|
|
};
|
|
}
|
|
function convertLabelsAndValues(labels, value) {
|
|
if (value === void 0) {
|
|
return {
|
|
value: labels,
|
|
labels: {}
|
|
};
|
|
}
|
|
return {
|
|
labels,
|
|
value
|
|
};
|
|
}
|
|
module.exports = Summary;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/pushgateway.js
|
|
var require_pushgateway = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/pushgateway.js"(exports, module) {
|
|
"use strict";
|
|
var url = __require("url");
|
|
var http = __require("http");
|
|
var https = __require("https");
|
|
var { gzipSync } = __require("zlib");
|
|
var { globalRegistry } = require_registry();
|
|
var Pushgateway = class {
|
|
constructor(gatewayUrl, options, registry) {
|
|
if (!registry) {
|
|
registry = globalRegistry;
|
|
}
|
|
this.registry = registry;
|
|
this.gatewayUrl = gatewayUrl;
|
|
const { requireJobName, ...requestOptions } = {
|
|
requireJobName: true,
|
|
...options
|
|
};
|
|
this.requireJobName = requireJobName;
|
|
this.requestOptions = requestOptions;
|
|
}
|
|
pushAdd(params = {}) {
|
|
if (this.requireJobName && !params.jobName) {
|
|
throw new Error("Missing jobName parameter");
|
|
}
|
|
return useGateway.call(this, "POST", params.jobName, params.groupings);
|
|
}
|
|
push(params = {}) {
|
|
if (this.requireJobName && !params.jobName) {
|
|
throw new Error("Missing jobName parameter");
|
|
}
|
|
return useGateway.call(this, "PUT", params.jobName, params.groupings);
|
|
}
|
|
delete(params = {}) {
|
|
if (this.requireJobName && !params.jobName) {
|
|
throw new Error("Missing jobName parameter");
|
|
}
|
|
return useGateway.call(this, "DELETE", params.jobName, params.groupings);
|
|
}
|
|
};
|
|
async function useGateway(method, job, groupings) {
|
|
const gatewayUrlParsed = url.parse(this.gatewayUrl);
|
|
const gatewayUrlPath = gatewayUrlParsed.pathname && gatewayUrlParsed.pathname !== "/" ? gatewayUrlParsed.pathname : "";
|
|
const jobPath = job ? `/job/${encodeURIComponent(job)}${generateGroupings(groupings)}` : "";
|
|
const path = `${gatewayUrlPath}/metrics${jobPath}`;
|
|
const target = url.resolve(this.gatewayUrl, path);
|
|
const requestParams = url.parse(target);
|
|
const httpModule = isHttps(requestParams.href) ? https : http;
|
|
const options = Object.assign(requestParams, this.requestOptions, {
|
|
method
|
|
});
|
|
return new Promise((resolve, reject) => {
|
|
if (method === "DELETE" && options.headers) {
|
|
delete options.headers["Content-Encoding"];
|
|
}
|
|
const req = httpModule.request(options, (resp) => {
|
|
let body = "";
|
|
resp.setEncoding("utf8");
|
|
resp.on("data", (chunk) => {
|
|
body += chunk;
|
|
});
|
|
resp.on("end", () => {
|
|
if (resp.statusCode >= 400) {
|
|
reject(
|
|
new Error(`push failed with status ${resp.statusCode}, ${body}`)
|
|
);
|
|
} else {
|
|
resolve({ resp, body });
|
|
}
|
|
});
|
|
});
|
|
req.on("error", (err) => {
|
|
reject(err);
|
|
});
|
|
req.on("timeout", () => {
|
|
req.destroy(new Error("Pushgateway request timed out"));
|
|
});
|
|
if (method !== "DELETE") {
|
|
this.registry.metrics().then((metrics2) => {
|
|
if (options.headers && options.headers["Content-Encoding"] === "gzip") {
|
|
metrics2 = gzipSync(metrics2);
|
|
}
|
|
req.write(metrics2);
|
|
req.end();
|
|
}).catch((err) => {
|
|
reject(err);
|
|
});
|
|
} else {
|
|
req.end();
|
|
}
|
|
});
|
|
}
|
|
function generateGroupings(groupings) {
|
|
if (!groupings) {
|
|
return "";
|
|
}
|
|
return Object.keys(groupings).map(
|
|
(key) => `/${encodeURIComponent(key)}/${encodeURIComponent(groupings[key])}`
|
|
).join("");
|
|
}
|
|
function isHttps(href) {
|
|
return href.search(/^https/) !== -1;
|
|
}
|
|
module.exports = Pushgateway;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/bucketGenerators.js
|
|
var require_bucketGenerators = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/bucketGenerators.js"(exports) {
|
|
"use strict";
|
|
exports.linearBuckets = (start, width, count) => {
|
|
if (count < 1) {
|
|
throw new Error("Linear buckets needs a positive count");
|
|
}
|
|
const buckets = new Array(count);
|
|
for (let i = 0; i < count; i++) {
|
|
buckets[i] = start + i * width;
|
|
}
|
|
return buckets;
|
|
};
|
|
exports.exponentialBuckets = (start, factor, count) => {
|
|
if (start <= 0) {
|
|
throw new Error("Exponential buckets needs a positive start");
|
|
}
|
|
if (count < 1) {
|
|
throw new Error("Exponential buckets needs a positive count");
|
|
}
|
|
if (factor <= 1) {
|
|
throw new Error("Exponential buckets needs a factor greater than 1");
|
|
}
|
|
const buckets = new Array(count);
|
|
for (let i = 0; i < count; i++) {
|
|
buckets[i] = start;
|
|
start *= factor;
|
|
}
|
|
return buckets;
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/version.js
|
|
var VERSION;
|
|
var init_version = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/version.js"() {
|
|
VERSION = "1.9.1";
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/internal/semver.js
|
|
function _makeCompatibilityCheck(ownVersion) {
|
|
const acceptedVersions = /* @__PURE__ */ new Set([ownVersion]);
|
|
const rejectedVersions = /* @__PURE__ */ new Set();
|
|
const myVersionMatch = ownVersion.match(re);
|
|
if (!myVersionMatch) {
|
|
return () => false;
|
|
}
|
|
const ownVersionParsed = {
|
|
major: +myVersionMatch[1],
|
|
minor: +myVersionMatch[2],
|
|
patch: +myVersionMatch[3],
|
|
prerelease: myVersionMatch[4]
|
|
};
|
|
if (ownVersionParsed.prerelease != null) {
|
|
return function isExactmatch(globalVersion) {
|
|
return globalVersion === ownVersion;
|
|
};
|
|
}
|
|
function _reject(v) {
|
|
rejectedVersions.add(v);
|
|
return false;
|
|
}
|
|
function _accept(v) {
|
|
acceptedVersions.add(v);
|
|
return true;
|
|
}
|
|
return function isCompatible2(globalVersion) {
|
|
if (acceptedVersions.has(globalVersion)) {
|
|
return true;
|
|
}
|
|
if (rejectedVersions.has(globalVersion)) {
|
|
return false;
|
|
}
|
|
const globalVersionMatch = globalVersion.match(re);
|
|
if (!globalVersionMatch) {
|
|
return _reject(globalVersion);
|
|
}
|
|
const globalVersionParsed = {
|
|
major: +globalVersionMatch[1],
|
|
minor: +globalVersionMatch[2],
|
|
patch: +globalVersionMatch[3],
|
|
prerelease: globalVersionMatch[4]
|
|
};
|
|
if (globalVersionParsed.prerelease != null) {
|
|
return _reject(globalVersion);
|
|
}
|
|
if (ownVersionParsed.major !== globalVersionParsed.major) {
|
|
return _reject(globalVersion);
|
|
}
|
|
if (ownVersionParsed.major === 0) {
|
|
if (ownVersionParsed.minor === globalVersionParsed.minor && ownVersionParsed.patch <= globalVersionParsed.patch) {
|
|
return _accept(globalVersion);
|
|
}
|
|
return _reject(globalVersion);
|
|
}
|
|
if (ownVersionParsed.minor <= globalVersionParsed.minor) {
|
|
return _accept(globalVersion);
|
|
}
|
|
return _reject(globalVersion);
|
|
};
|
|
}
|
|
var re, isCompatible;
|
|
var init_semver = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/internal/semver.js"() {
|
|
init_version();
|
|
re = /^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;
|
|
isCompatible = _makeCompatibilityCheck(VERSION);
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/internal/global-utils.js
|
|
function registerGlobal(type, instance, diag3, allowOverride = false) {
|
|
var _a;
|
|
const api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a !== void 0 ? _a : {
|
|
version: VERSION
|
|
};
|
|
if (!allowOverride && api[type]) {
|
|
const err = new Error(`@opentelemetry/api: Attempted duplicate registration of API: ${type}`);
|
|
diag3.error(err.stack || err.message);
|
|
return false;
|
|
}
|
|
if (api.version !== VERSION) {
|
|
const err = new Error(`@opentelemetry/api: Registration of version v${api.version} for ${type} does not match previously registered API v${VERSION}`);
|
|
diag3.error(err.stack || err.message);
|
|
return false;
|
|
}
|
|
api[type] = instance;
|
|
diag3.debug(`@opentelemetry/api: Registered a global for ${type} v${VERSION}.`);
|
|
return true;
|
|
}
|
|
function getGlobal(type) {
|
|
var _a, _b;
|
|
const globalVersion = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _a === void 0 ? void 0 : _a.version;
|
|
if (!globalVersion || !isCompatible(globalVersion)) {
|
|
return;
|
|
}
|
|
return (_b = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _b === void 0 ? void 0 : _b[type];
|
|
}
|
|
function unregisterGlobal(type, diag3) {
|
|
diag3.debug(`@opentelemetry/api: Unregistering a global for ${type} v${VERSION}.`);
|
|
const api = _global[GLOBAL_OPENTELEMETRY_API_KEY];
|
|
if (api) {
|
|
delete api[type];
|
|
}
|
|
}
|
|
var major, GLOBAL_OPENTELEMETRY_API_KEY, _global;
|
|
var init_global_utils = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/internal/global-utils.js"() {
|
|
init_version();
|
|
init_semver();
|
|
major = VERSION.split(".")[0];
|
|
GLOBAL_OPENTELEMETRY_API_KEY = Symbol.for(`opentelemetry.js.api.${major}`);
|
|
_global = typeof globalThis === "object" ? globalThis : typeof self === "object" ? self : typeof window === "object" ? window : typeof global === "object" ? global : {};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/diag/ComponentLogger.js
|
|
function logProxy(funcName, namespace, args) {
|
|
const logger = getGlobal("diag");
|
|
if (!logger) {
|
|
return;
|
|
}
|
|
return logger[funcName](namespace, ...args);
|
|
}
|
|
var DiagComponentLogger;
|
|
var init_ComponentLogger = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/diag/ComponentLogger.js"() {
|
|
init_global_utils();
|
|
DiagComponentLogger = class {
|
|
constructor(props) {
|
|
this._namespace = props.namespace || "DiagComponentLogger";
|
|
}
|
|
debug(...args) {
|
|
return logProxy("debug", this._namespace, args);
|
|
}
|
|
error(...args) {
|
|
return logProxy("error", this._namespace, args);
|
|
}
|
|
info(...args) {
|
|
return logProxy("info", this._namespace, args);
|
|
}
|
|
warn(...args) {
|
|
return logProxy("warn", this._namespace, args);
|
|
}
|
|
verbose(...args) {
|
|
return logProxy("verbose", this._namespace, args);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/diag/types.js
|
|
var DiagLogLevel;
|
|
var init_types = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/diag/types.js"() {
|
|
(function(DiagLogLevel2) {
|
|
DiagLogLevel2[DiagLogLevel2["NONE"] = 0] = "NONE";
|
|
DiagLogLevel2[DiagLogLevel2["ERROR"] = 30] = "ERROR";
|
|
DiagLogLevel2[DiagLogLevel2["WARN"] = 50] = "WARN";
|
|
DiagLogLevel2[DiagLogLevel2["INFO"] = 60] = "INFO";
|
|
DiagLogLevel2[DiagLogLevel2["DEBUG"] = 70] = "DEBUG";
|
|
DiagLogLevel2[DiagLogLevel2["VERBOSE"] = 80] = "VERBOSE";
|
|
DiagLogLevel2[DiagLogLevel2["ALL"] = 9999] = "ALL";
|
|
})(DiagLogLevel || (DiagLogLevel = {}));
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/diag/internal/logLevelLogger.js
|
|
function createLogLevelDiagLogger(maxLevel, logger) {
|
|
if (maxLevel < DiagLogLevel.NONE) {
|
|
maxLevel = DiagLogLevel.NONE;
|
|
} else if (maxLevel > DiagLogLevel.ALL) {
|
|
maxLevel = DiagLogLevel.ALL;
|
|
}
|
|
logger = logger || {};
|
|
function _filterFunc(funcName, theLevel) {
|
|
const theFunc = logger[funcName];
|
|
if (typeof theFunc === "function" && maxLevel >= theLevel) {
|
|
return theFunc.bind(logger);
|
|
}
|
|
return function() {
|
|
};
|
|
}
|
|
return {
|
|
error: _filterFunc("error", DiagLogLevel.ERROR),
|
|
warn: _filterFunc("warn", DiagLogLevel.WARN),
|
|
info: _filterFunc("info", DiagLogLevel.INFO),
|
|
debug: _filterFunc("debug", DiagLogLevel.DEBUG),
|
|
verbose: _filterFunc("verbose", DiagLogLevel.VERBOSE)
|
|
};
|
|
}
|
|
var init_logLevelLogger = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/diag/internal/logLevelLogger.js"() {
|
|
init_types();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/api/diag.js
|
|
var API_NAME, DiagAPI;
|
|
var init_diag = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/api/diag.js"() {
|
|
init_ComponentLogger();
|
|
init_logLevelLogger();
|
|
init_types();
|
|
init_global_utils();
|
|
API_NAME = "diag";
|
|
DiagAPI = class _DiagAPI {
|
|
/** Get the singleton instance of the DiagAPI API */
|
|
static instance() {
|
|
if (!this._instance) {
|
|
this._instance = new _DiagAPI();
|
|
}
|
|
return this._instance;
|
|
}
|
|
/**
|
|
* Private internal constructor
|
|
* @private
|
|
*/
|
|
constructor() {
|
|
function _logProxy(funcName) {
|
|
return function(...args) {
|
|
const logger = getGlobal("diag");
|
|
if (!logger)
|
|
return;
|
|
return logger[funcName](...args);
|
|
};
|
|
}
|
|
const self2 = this;
|
|
const setLogger = (logger, optionsOrLogLevel = { logLevel: DiagLogLevel.INFO }) => {
|
|
var _a, _b, _c;
|
|
if (logger === self2) {
|
|
const err = new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
|
|
self2.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
|
|
return false;
|
|
}
|
|
if (typeof optionsOrLogLevel === "number") {
|
|
optionsOrLogLevel = {
|
|
logLevel: optionsOrLogLevel
|
|
};
|
|
}
|
|
const oldLogger = getGlobal("diag");
|
|
const newLogger = createLogLevelDiagLogger((_b = optionsOrLogLevel.logLevel) !== null && _b !== void 0 ? _b : DiagLogLevel.INFO, logger);
|
|
if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
|
|
const stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : "<failed to generate stacktrace>";
|
|
oldLogger.warn(`Current logger will be overwritten from ${stack}`);
|
|
newLogger.warn(`Current logger will overwrite one already registered from ${stack}`);
|
|
}
|
|
return registerGlobal("diag", newLogger, self2, true);
|
|
};
|
|
self2.setLogger = setLogger;
|
|
self2.disable = () => {
|
|
unregisterGlobal(API_NAME, self2);
|
|
};
|
|
self2.createComponentLogger = (options) => {
|
|
return new DiagComponentLogger(options);
|
|
};
|
|
self2.verbose = _logProxy("verbose");
|
|
self2.debug = _logProxy("debug");
|
|
self2.info = _logProxy("info");
|
|
self2.warn = _logProxy("warn");
|
|
self2.error = _logProxy("error");
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/baggage/internal/baggage-impl.js
|
|
var BaggageImpl;
|
|
var init_baggage_impl = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/baggage/internal/baggage-impl.js"() {
|
|
BaggageImpl = class _BaggageImpl {
|
|
constructor(entries) {
|
|
this._entries = entries ? new Map(entries) : /* @__PURE__ */ new Map();
|
|
}
|
|
getEntry(key) {
|
|
const entry = this._entries.get(key);
|
|
if (!entry) {
|
|
return void 0;
|
|
}
|
|
return Object.assign({}, entry);
|
|
}
|
|
getAllEntries() {
|
|
return Array.from(this._entries.entries());
|
|
}
|
|
setEntry(key, entry) {
|
|
const newBaggage = new _BaggageImpl(this._entries);
|
|
newBaggage._entries.set(key, entry);
|
|
return newBaggage;
|
|
}
|
|
removeEntry(key) {
|
|
const newBaggage = new _BaggageImpl(this._entries);
|
|
newBaggage._entries.delete(key);
|
|
return newBaggage;
|
|
}
|
|
removeEntries(...keys) {
|
|
const newBaggage = new _BaggageImpl(this._entries);
|
|
for (const key of keys) {
|
|
newBaggage._entries.delete(key);
|
|
}
|
|
return newBaggage;
|
|
}
|
|
clear() {
|
|
return new _BaggageImpl();
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/baggage/internal/symbol.js
|
|
var baggageEntryMetadataSymbol;
|
|
var init_symbol = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/baggage/internal/symbol.js"() {
|
|
baggageEntryMetadataSymbol = Symbol("BaggageEntryMetadata");
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/baggage/utils.js
|
|
function createBaggage(entries = {}) {
|
|
return new BaggageImpl(new Map(Object.entries(entries)));
|
|
}
|
|
function baggageEntryMetadataFromString(str) {
|
|
if (typeof str !== "string") {
|
|
diag.error(`Cannot create baggage metadata from unknown type: ${typeof str}`);
|
|
str = "";
|
|
}
|
|
return {
|
|
__TYPE__: baggageEntryMetadataSymbol,
|
|
toString() {
|
|
return str;
|
|
}
|
|
};
|
|
}
|
|
var diag;
|
|
var init_utils = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/baggage/utils.js"() {
|
|
init_diag();
|
|
init_baggage_impl();
|
|
init_symbol();
|
|
diag = DiagAPI.instance();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/context/context.js
|
|
function createContextKey(description) {
|
|
return Symbol.for(description);
|
|
}
|
|
var BaseContext, ROOT_CONTEXT;
|
|
var init_context = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/context/context.js"() {
|
|
BaseContext = class _BaseContext {
|
|
/**
|
|
* Construct a new context which inherits values from an optional parent context.
|
|
*
|
|
* @param parentContext a context from which to inherit values
|
|
*/
|
|
constructor(parentContext) {
|
|
const self2 = this;
|
|
self2._currentContext = parentContext ? new Map(parentContext) : /* @__PURE__ */ new Map();
|
|
self2.getValue = (key) => self2._currentContext.get(key);
|
|
self2.setValue = (key, value) => {
|
|
const context2 = new _BaseContext(self2._currentContext);
|
|
context2._currentContext.set(key, value);
|
|
return context2;
|
|
};
|
|
self2.deleteValue = (key) => {
|
|
const context2 = new _BaseContext(self2._currentContext);
|
|
context2._currentContext.delete(key);
|
|
return context2;
|
|
};
|
|
}
|
|
};
|
|
ROOT_CONTEXT = new BaseContext();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/diag/consoleLogger.js
|
|
var consoleMap, _originalConsoleMethods, DiagConsoleLogger;
|
|
var init_consoleLogger = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/diag/consoleLogger.js"() {
|
|
consoleMap = [
|
|
{ n: "error", c: "error" },
|
|
{ n: "warn", c: "warn" },
|
|
{ n: "info", c: "info" },
|
|
{ n: "debug", c: "debug" },
|
|
{ n: "verbose", c: "trace" }
|
|
];
|
|
_originalConsoleMethods = {};
|
|
if (typeof console !== "undefined") {
|
|
const keys = [
|
|
"error",
|
|
"warn",
|
|
"info",
|
|
"debug",
|
|
"trace",
|
|
"log"
|
|
];
|
|
for (const key of keys) {
|
|
if (typeof console[key] === "function") {
|
|
_originalConsoleMethods[key] = console[key];
|
|
}
|
|
}
|
|
}
|
|
DiagConsoleLogger = class {
|
|
constructor() {
|
|
function _consoleFunc(funcName) {
|
|
return function(...args) {
|
|
let theFunc = _originalConsoleMethods[funcName];
|
|
if (typeof theFunc !== "function") {
|
|
theFunc = _originalConsoleMethods["log"];
|
|
}
|
|
if (typeof theFunc !== "function" && console) {
|
|
theFunc = console[funcName];
|
|
if (typeof theFunc !== "function") {
|
|
theFunc = console.log;
|
|
}
|
|
}
|
|
if (typeof theFunc === "function") {
|
|
return theFunc.apply(console, args);
|
|
}
|
|
};
|
|
}
|
|
for (let i = 0; i < consoleMap.length; i++) {
|
|
this[consoleMap[i].n] = _consoleFunc(consoleMap[i].c);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/metrics/NoopMeter.js
|
|
function createNoopMeter() {
|
|
return NOOP_METER;
|
|
}
|
|
var NoopMeter, NoopMetric, NoopCounterMetric, NoopUpDownCounterMetric, NoopGaugeMetric, NoopHistogramMetric, NoopObservableMetric, NoopObservableCounterMetric, NoopObservableGaugeMetric, NoopObservableUpDownCounterMetric, NOOP_METER, NOOP_COUNTER_METRIC, NOOP_GAUGE_METRIC, NOOP_HISTOGRAM_METRIC, NOOP_UP_DOWN_COUNTER_METRIC, NOOP_OBSERVABLE_COUNTER_METRIC, NOOP_OBSERVABLE_GAUGE_METRIC, NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC;
|
|
var init_NoopMeter = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/metrics/NoopMeter.js"() {
|
|
NoopMeter = class {
|
|
constructor() {
|
|
}
|
|
/**
|
|
* @see {@link Meter.createGauge}
|
|
*/
|
|
createGauge(_name, _options) {
|
|
return NOOP_GAUGE_METRIC;
|
|
}
|
|
/**
|
|
* @see {@link Meter.createHistogram}
|
|
*/
|
|
createHistogram(_name, _options) {
|
|
return NOOP_HISTOGRAM_METRIC;
|
|
}
|
|
/**
|
|
* @see {@link Meter.createCounter}
|
|
*/
|
|
createCounter(_name, _options) {
|
|
return NOOP_COUNTER_METRIC;
|
|
}
|
|
/**
|
|
* @see {@link Meter.createUpDownCounter}
|
|
*/
|
|
createUpDownCounter(_name, _options) {
|
|
return NOOP_UP_DOWN_COUNTER_METRIC;
|
|
}
|
|
/**
|
|
* @see {@link Meter.createObservableGauge}
|
|
*/
|
|
createObservableGauge(_name, _options) {
|
|
return NOOP_OBSERVABLE_GAUGE_METRIC;
|
|
}
|
|
/**
|
|
* @see {@link Meter.createObservableCounter}
|
|
*/
|
|
createObservableCounter(_name, _options) {
|
|
return NOOP_OBSERVABLE_COUNTER_METRIC;
|
|
}
|
|
/**
|
|
* @see {@link Meter.createObservableUpDownCounter}
|
|
*/
|
|
createObservableUpDownCounter(_name, _options) {
|
|
return NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC;
|
|
}
|
|
/**
|
|
* @see {@link Meter.addBatchObservableCallback}
|
|
*/
|
|
addBatchObservableCallback(_callback, _observables) {
|
|
}
|
|
/**
|
|
* @see {@link Meter.removeBatchObservableCallback}
|
|
*/
|
|
removeBatchObservableCallback(_callback) {
|
|
}
|
|
};
|
|
NoopMetric = class {
|
|
};
|
|
NoopCounterMetric = class extends NoopMetric {
|
|
add(_value, _attributes) {
|
|
}
|
|
};
|
|
NoopUpDownCounterMetric = class extends NoopMetric {
|
|
add(_value, _attributes) {
|
|
}
|
|
};
|
|
NoopGaugeMetric = class extends NoopMetric {
|
|
record(_value, _attributes) {
|
|
}
|
|
};
|
|
NoopHistogramMetric = class extends NoopMetric {
|
|
record(_value, _attributes) {
|
|
}
|
|
};
|
|
NoopObservableMetric = class {
|
|
addCallback(_callback) {
|
|
}
|
|
removeCallback(_callback) {
|
|
}
|
|
};
|
|
NoopObservableCounterMetric = class extends NoopObservableMetric {
|
|
};
|
|
NoopObservableGaugeMetric = class extends NoopObservableMetric {
|
|
};
|
|
NoopObservableUpDownCounterMetric = class extends NoopObservableMetric {
|
|
};
|
|
NOOP_METER = new NoopMeter();
|
|
NOOP_COUNTER_METRIC = new NoopCounterMetric();
|
|
NOOP_GAUGE_METRIC = new NoopGaugeMetric();
|
|
NOOP_HISTOGRAM_METRIC = new NoopHistogramMetric();
|
|
NOOP_UP_DOWN_COUNTER_METRIC = new NoopUpDownCounterMetric();
|
|
NOOP_OBSERVABLE_COUNTER_METRIC = new NoopObservableCounterMetric();
|
|
NOOP_OBSERVABLE_GAUGE_METRIC = new NoopObservableGaugeMetric();
|
|
NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC = new NoopObservableUpDownCounterMetric();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/metrics/Metric.js
|
|
var ValueType;
|
|
var init_Metric = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/metrics/Metric.js"() {
|
|
(function(ValueType2) {
|
|
ValueType2[ValueType2["INT"] = 0] = "INT";
|
|
ValueType2[ValueType2["DOUBLE"] = 1] = "DOUBLE";
|
|
})(ValueType || (ValueType = {}));
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/propagation/TextMapPropagator.js
|
|
var defaultTextMapGetter, defaultTextMapSetter;
|
|
var init_TextMapPropagator = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/propagation/TextMapPropagator.js"() {
|
|
defaultTextMapGetter = {
|
|
get(carrier, key) {
|
|
if (carrier == null) {
|
|
return void 0;
|
|
}
|
|
return carrier[key];
|
|
},
|
|
keys(carrier) {
|
|
if (carrier == null) {
|
|
return [];
|
|
}
|
|
return Object.keys(carrier);
|
|
}
|
|
};
|
|
defaultTextMapSetter = {
|
|
set(carrier, key, value) {
|
|
if (carrier == null) {
|
|
return;
|
|
}
|
|
carrier[key] = value;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/context/NoopContextManager.js
|
|
var NoopContextManager;
|
|
var init_NoopContextManager = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/context/NoopContextManager.js"() {
|
|
init_context();
|
|
NoopContextManager = class {
|
|
active() {
|
|
return ROOT_CONTEXT;
|
|
}
|
|
with(_context, fn, thisArg, ...args) {
|
|
return fn.call(thisArg, ...args);
|
|
}
|
|
bind(_context, target) {
|
|
return target;
|
|
}
|
|
enable() {
|
|
return this;
|
|
}
|
|
disable() {
|
|
return this;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/api/context.js
|
|
var API_NAME2, NOOP_CONTEXT_MANAGER, ContextAPI;
|
|
var init_context2 = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/api/context.js"() {
|
|
init_NoopContextManager();
|
|
init_global_utils();
|
|
init_diag();
|
|
API_NAME2 = "context";
|
|
NOOP_CONTEXT_MANAGER = new NoopContextManager();
|
|
ContextAPI = class _ContextAPI {
|
|
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
|
constructor() {
|
|
}
|
|
/** Get the singleton instance of the Context API */
|
|
static getInstance() {
|
|
if (!this._instance) {
|
|
this._instance = new _ContextAPI();
|
|
}
|
|
return this._instance;
|
|
}
|
|
/**
|
|
* Set the current context manager.
|
|
*
|
|
* @returns true if the context manager was successfully registered, else false
|
|
*/
|
|
setGlobalContextManager(contextManager) {
|
|
return registerGlobal(API_NAME2, contextManager, DiagAPI.instance());
|
|
}
|
|
/**
|
|
* Get the currently active context
|
|
*/
|
|
active() {
|
|
return this._getContextManager().active();
|
|
}
|
|
/**
|
|
* Execute a function with an active context
|
|
*
|
|
* @param context context to be active during function execution
|
|
* @param fn function to execute in a context
|
|
* @param thisArg optional receiver to be used for calling fn
|
|
* @param args optional arguments forwarded to fn
|
|
*/
|
|
with(context2, fn, thisArg, ...args) {
|
|
return this._getContextManager().with(context2, fn, thisArg, ...args);
|
|
}
|
|
/**
|
|
* Bind a context to a target function or event emitter
|
|
*
|
|
* @param context context to bind to the event emitter or function. Defaults to the currently active context
|
|
* @param target function or event emitter to bind
|
|
*/
|
|
bind(context2, target) {
|
|
return this._getContextManager().bind(context2, target);
|
|
}
|
|
_getContextManager() {
|
|
return getGlobal(API_NAME2) || NOOP_CONTEXT_MANAGER;
|
|
}
|
|
/** Disable and remove the global context manager */
|
|
disable() {
|
|
this._getContextManager().disable();
|
|
unregisterGlobal(API_NAME2, DiagAPI.instance());
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/trace/trace_flags.js
|
|
var TraceFlags;
|
|
var init_trace_flags = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/trace/trace_flags.js"() {
|
|
(function(TraceFlags2) {
|
|
TraceFlags2[TraceFlags2["NONE"] = 0] = "NONE";
|
|
TraceFlags2[TraceFlags2["SAMPLED"] = 1] = "SAMPLED";
|
|
})(TraceFlags || (TraceFlags = {}));
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/trace/invalid-span-constants.js
|
|
var INVALID_SPANID, INVALID_TRACEID, INVALID_SPAN_CONTEXT;
|
|
var init_invalid_span_constants = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/trace/invalid-span-constants.js"() {
|
|
init_trace_flags();
|
|
INVALID_SPANID = "0000000000000000";
|
|
INVALID_TRACEID = "00000000000000000000000000000000";
|
|
INVALID_SPAN_CONTEXT = {
|
|
traceId: INVALID_TRACEID,
|
|
spanId: INVALID_SPANID,
|
|
traceFlags: TraceFlags.NONE
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/trace/NonRecordingSpan.js
|
|
var NonRecordingSpan;
|
|
var init_NonRecordingSpan = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/trace/NonRecordingSpan.js"() {
|
|
init_invalid_span_constants();
|
|
NonRecordingSpan = class {
|
|
constructor(spanContext = INVALID_SPAN_CONTEXT) {
|
|
this._spanContext = spanContext;
|
|
}
|
|
// Returns a SpanContext.
|
|
spanContext() {
|
|
return this._spanContext;
|
|
}
|
|
// By default does nothing
|
|
setAttribute(_key, _value) {
|
|
return this;
|
|
}
|
|
// By default does nothing
|
|
setAttributes(_attributes) {
|
|
return this;
|
|
}
|
|
// By default does nothing
|
|
addEvent(_name, _attributes) {
|
|
return this;
|
|
}
|
|
addLink(_link) {
|
|
return this;
|
|
}
|
|
addLinks(_links) {
|
|
return this;
|
|
}
|
|
// By default does nothing
|
|
setStatus(_status) {
|
|
return this;
|
|
}
|
|
// By default does nothing
|
|
updateName(_name) {
|
|
return this;
|
|
}
|
|
// By default does nothing
|
|
end(_endTime) {
|
|
}
|
|
// isRecording always returns false for NonRecordingSpan.
|
|
isRecording() {
|
|
return false;
|
|
}
|
|
// By default does nothing
|
|
recordException(_exception, _time) {
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/trace/context-utils.js
|
|
function getSpan(context2) {
|
|
return context2.getValue(SPAN_KEY) || void 0;
|
|
}
|
|
function getActiveSpan() {
|
|
return getSpan(ContextAPI.getInstance().active());
|
|
}
|
|
function setSpan(context2, span) {
|
|
return context2.setValue(SPAN_KEY, span);
|
|
}
|
|
function deleteSpan(context2) {
|
|
return context2.deleteValue(SPAN_KEY);
|
|
}
|
|
function setSpanContext(context2, spanContext) {
|
|
return setSpan(context2, new NonRecordingSpan(spanContext));
|
|
}
|
|
function getSpanContext(context2) {
|
|
var _a;
|
|
return (_a = getSpan(context2)) === null || _a === void 0 ? void 0 : _a.spanContext();
|
|
}
|
|
var SPAN_KEY;
|
|
var init_context_utils = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/trace/context-utils.js"() {
|
|
init_context();
|
|
init_NonRecordingSpan();
|
|
init_context2();
|
|
SPAN_KEY = createContextKey("OpenTelemetry Context Key SPAN");
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/trace/spancontext-utils.js
|
|
function isValidHex(id, length) {
|
|
if (typeof id !== "string" || id.length !== length)
|
|
return false;
|
|
let r = 0;
|
|
for (let i = 0; i < id.length; i += 4) {
|
|
r += (isHex[id.charCodeAt(i)] | 0) + (isHex[id.charCodeAt(i + 1)] | 0) + (isHex[id.charCodeAt(i + 2)] | 0) + (isHex[id.charCodeAt(i + 3)] | 0);
|
|
}
|
|
return r === length;
|
|
}
|
|
function isValidTraceId(traceId) {
|
|
return isValidHex(traceId, 32) && traceId !== INVALID_TRACEID;
|
|
}
|
|
function isValidSpanId(spanId) {
|
|
return isValidHex(spanId, 16) && spanId !== INVALID_SPANID;
|
|
}
|
|
function isSpanContextValid(spanContext) {
|
|
return isValidTraceId(spanContext.traceId) && isValidSpanId(spanContext.spanId);
|
|
}
|
|
function wrapSpanContext(spanContext) {
|
|
return new NonRecordingSpan(spanContext);
|
|
}
|
|
var isHex;
|
|
var init_spancontext_utils = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/trace/spancontext-utils.js"() {
|
|
init_invalid_span_constants();
|
|
init_NonRecordingSpan();
|
|
isHex = new Uint8Array([
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
1,
|
|
1,
|
|
1,
|
|
1,
|
|
1,
|
|
1,
|
|
1,
|
|
1,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
1,
|
|
1,
|
|
1,
|
|
1,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
1,
|
|
1,
|
|
1,
|
|
1,
|
|
1
|
|
]);
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/trace/NoopTracer.js
|
|
function isSpanContext(spanContext) {
|
|
return spanContext !== null && typeof spanContext === "object" && "spanId" in spanContext && typeof spanContext["spanId"] === "string" && "traceId" in spanContext && typeof spanContext["traceId"] === "string" && "traceFlags" in spanContext && typeof spanContext["traceFlags"] === "number";
|
|
}
|
|
var contextApi, NoopTracer;
|
|
var init_NoopTracer = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/trace/NoopTracer.js"() {
|
|
init_context2();
|
|
init_context_utils();
|
|
init_NonRecordingSpan();
|
|
init_spancontext_utils();
|
|
contextApi = ContextAPI.getInstance();
|
|
NoopTracer = class {
|
|
// startSpan starts a noop span.
|
|
startSpan(name, options, context2 = contextApi.active()) {
|
|
const root = Boolean(options === null || options === void 0 ? void 0 : options.root);
|
|
if (root) {
|
|
return new NonRecordingSpan();
|
|
}
|
|
const parentFromContext = context2 && getSpanContext(context2);
|
|
if (isSpanContext(parentFromContext) && isSpanContextValid(parentFromContext)) {
|
|
return new NonRecordingSpan(parentFromContext);
|
|
} else {
|
|
return new NonRecordingSpan();
|
|
}
|
|
}
|
|
startActiveSpan(name, arg2, arg3, arg4) {
|
|
let opts;
|
|
let ctx;
|
|
let fn;
|
|
if (arguments.length < 2) {
|
|
return;
|
|
} else if (arguments.length === 2) {
|
|
fn = arg2;
|
|
} else if (arguments.length === 3) {
|
|
opts = arg2;
|
|
fn = arg3;
|
|
} else {
|
|
opts = arg2;
|
|
ctx = arg3;
|
|
fn = arg4;
|
|
}
|
|
const parentContext = ctx !== null && ctx !== void 0 ? ctx : contextApi.active();
|
|
const span = this.startSpan(name, opts, parentContext);
|
|
const contextWithSpanSet = setSpan(parentContext, span);
|
|
return contextApi.with(contextWithSpanSet, fn, void 0, span);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/trace/ProxyTracer.js
|
|
var NOOP_TRACER, ProxyTracer;
|
|
var init_ProxyTracer = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/trace/ProxyTracer.js"() {
|
|
init_NoopTracer();
|
|
NOOP_TRACER = new NoopTracer();
|
|
ProxyTracer = class {
|
|
constructor(provider, name, version, options) {
|
|
this._provider = provider;
|
|
this.name = name;
|
|
this.version = version;
|
|
this.options = options;
|
|
}
|
|
startSpan(name, options, context2) {
|
|
return this._getTracer().startSpan(name, options, context2);
|
|
}
|
|
startActiveSpan(_name, _options, _context, _fn) {
|
|
const tracer = this._getTracer();
|
|
return Reflect.apply(tracer.startActiveSpan, tracer, arguments);
|
|
}
|
|
/**
|
|
* Try to get a tracer from the proxy tracer provider.
|
|
* If the proxy tracer provider has no delegate, return a noop tracer.
|
|
*/
|
|
_getTracer() {
|
|
if (this._delegate) {
|
|
return this._delegate;
|
|
}
|
|
const tracer = this._provider.getDelegateTracer(this.name, this.version, this.options);
|
|
if (!tracer) {
|
|
return NOOP_TRACER;
|
|
}
|
|
this._delegate = tracer;
|
|
return this._delegate;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/trace/NoopTracerProvider.js
|
|
var NoopTracerProvider;
|
|
var init_NoopTracerProvider = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/trace/NoopTracerProvider.js"() {
|
|
init_NoopTracer();
|
|
NoopTracerProvider = class {
|
|
getTracer(_name, _version, _options) {
|
|
return new NoopTracer();
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/trace/ProxyTracerProvider.js
|
|
var NOOP_TRACER_PROVIDER, ProxyTracerProvider;
|
|
var init_ProxyTracerProvider = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/trace/ProxyTracerProvider.js"() {
|
|
init_ProxyTracer();
|
|
init_NoopTracerProvider();
|
|
NOOP_TRACER_PROVIDER = new NoopTracerProvider();
|
|
ProxyTracerProvider = class {
|
|
/**
|
|
* Get a {@link ProxyTracer}
|
|
*/
|
|
getTracer(name, version, options) {
|
|
var _a;
|
|
return (_a = this.getDelegateTracer(name, version, options)) !== null && _a !== void 0 ? _a : new ProxyTracer(this, name, version, options);
|
|
}
|
|
getDelegate() {
|
|
var _a;
|
|
return (_a = this._delegate) !== null && _a !== void 0 ? _a : NOOP_TRACER_PROVIDER;
|
|
}
|
|
/**
|
|
* Set the delegate tracer provider
|
|
*/
|
|
setDelegate(delegate) {
|
|
this._delegate = delegate;
|
|
}
|
|
getDelegateTracer(name, version, options) {
|
|
var _a;
|
|
return (_a = this._delegate) === null || _a === void 0 ? void 0 : _a.getTracer(name, version, options);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/trace/SamplingResult.js
|
|
var SamplingDecision;
|
|
var init_SamplingResult = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/trace/SamplingResult.js"() {
|
|
(function(SamplingDecision2) {
|
|
SamplingDecision2[SamplingDecision2["NOT_RECORD"] = 0] = "NOT_RECORD";
|
|
SamplingDecision2[SamplingDecision2["RECORD"] = 1] = "RECORD";
|
|
SamplingDecision2[SamplingDecision2["RECORD_AND_SAMPLED"] = 2] = "RECORD_AND_SAMPLED";
|
|
})(SamplingDecision || (SamplingDecision = {}));
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/trace/span_kind.js
|
|
var SpanKind;
|
|
var init_span_kind = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/trace/span_kind.js"() {
|
|
(function(SpanKind2) {
|
|
SpanKind2[SpanKind2["INTERNAL"] = 0] = "INTERNAL";
|
|
SpanKind2[SpanKind2["SERVER"] = 1] = "SERVER";
|
|
SpanKind2[SpanKind2["CLIENT"] = 2] = "CLIENT";
|
|
SpanKind2[SpanKind2["PRODUCER"] = 3] = "PRODUCER";
|
|
SpanKind2[SpanKind2["CONSUMER"] = 4] = "CONSUMER";
|
|
})(SpanKind || (SpanKind = {}));
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/trace/status.js
|
|
var SpanStatusCode;
|
|
var init_status = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/trace/status.js"() {
|
|
(function(SpanStatusCode2) {
|
|
SpanStatusCode2[SpanStatusCode2["UNSET"] = 0] = "UNSET";
|
|
SpanStatusCode2[SpanStatusCode2["OK"] = 1] = "OK";
|
|
SpanStatusCode2[SpanStatusCode2["ERROR"] = 2] = "ERROR";
|
|
})(SpanStatusCode || (SpanStatusCode = {}));
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/trace/internal/tracestate-validators.js
|
|
function validateKey(key) {
|
|
return VALID_KEY_REGEX.test(key);
|
|
}
|
|
function validateValue(value) {
|
|
return VALID_VALUE_BASE_REGEX.test(value) && !INVALID_VALUE_COMMA_EQUAL_REGEX.test(value);
|
|
}
|
|
var VALID_KEY_CHAR_RANGE, VALID_KEY, VALID_VENDOR_KEY, VALID_KEY_REGEX, VALID_VALUE_BASE_REGEX, INVALID_VALUE_COMMA_EQUAL_REGEX;
|
|
var init_tracestate_validators = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/trace/internal/tracestate-validators.js"() {
|
|
VALID_KEY_CHAR_RANGE = "[_0-9a-z-*/]";
|
|
VALID_KEY = `[a-z]${VALID_KEY_CHAR_RANGE}{0,255}`;
|
|
VALID_VENDOR_KEY = `[a-z0-9]${VALID_KEY_CHAR_RANGE}{0,240}@[a-z]${VALID_KEY_CHAR_RANGE}{0,13}`;
|
|
VALID_KEY_REGEX = new RegExp(`^(?:${VALID_KEY}|${VALID_VENDOR_KEY})$`);
|
|
VALID_VALUE_BASE_REGEX = /^[ -~]{0,255}[!-~]$/;
|
|
INVALID_VALUE_COMMA_EQUAL_REGEX = /,|=/;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/trace/internal/tracestate-impl.js
|
|
var MAX_TRACE_STATE_ITEMS, MAX_TRACE_STATE_LEN, LIST_MEMBERS_SEPARATOR, LIST_MEMBER_KEY_VALUE_SPLITTER, TraceStateImpl;
|
|
var init_tracestate_impl = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/trace/internal/tracestate-impl.js"() {
|
|
init_tracestate_validators();
|
|
MAX_TRACE_STATE_ITEMS = 32;
|
|
MAX_TRACE_STATE_LEN = 512;
|
|
LIST_MEMBERS_SEPARATOR = ",";
|
|
LIST_MEMBER_KEY_VALUE_SPLITTER = "=";
|
|
TraceStateImpl = class _TraceStateImpl {
|
|
constructor(rawTraceState) {
|
|
this._internalState = /* @__PURE__ */ new Map();
|
|
if (rawTraceState)
|
|
this._parse(rawTraceState);
|
|
}
|
|
set(key, value) {
|
|
const traceState = this._clone();
|
|
if (traceState._internalState.has(key)) {
|
|
traceState._internalState.delete(key);
|
|
}
|
|
traceState._internalState.set(key, value);
|
|
return traceState;
|
|
}
|
|
unset(key) {
|
|
const traceState = this._clone();
|
|
traceState._internalState.delete(key);
|
|
return traceState;
|
|
}
|
|
get(key) {
|
|
return this._internalState.get(key);
|
|
}
|
|
serialize() {
|
|
return Array.from(this._internalState.keys()).reduceRight((agg, key) => {
|
|
agg.push(key + LIST_MEMBER_KEY_VALUE_SPLITTER + this.get(key));
|
|
return agg;
|
|
}, []).join(LIST_MEMBERS_SEPARATOR);
|
|
}
|
|
_parse(rawTraceState) {
|
|
if (rawTraceState.length > MAX_TRACE_STATE_LEN)
|
|
return;
|
|
this._internalState = rawTraceState.split(LIST_MEMBERS_SEPARATOR).reduceRight((agg, part) => {
|
|
const listMember = part.trim();
|
|
const i = listMember.indexOf(LIST_MEMBER_KEY_VALUE_SPLITTER);
|
|
if (i !== -1) {
|
|
const key = listMember.slice(0, i);
|
|
const value = listMember.slice(i + 1, part.length);
|
|
if (validateKey(key) && validateValue(value)) {
|
|
agg.set(key, value);
|
|
} else {
|
|
}
|
|
}
|
|
return agg;
|
|
}, /* @__PURE__ */ new Map());
|
|
if (this._internalState.size > MAX_TRACE_STATE_ITEMS) {
|
|
this._internalState = new Map(Array.from(this._internalState.entries()).reverse().slice(0, MAX_TRACE_STATE_ITEMS));
|
|
}
|
|
}
|
|
// @ts-expect-error TS6133 Accessed in tests only.
|
|
_keys() {
|
|
return Array.from(this._internalState.keys()).reverse();
|
|
}
|
|
_clone() {
|
|
const traceState = new _TraceStateImpl();
|
|
traceState._internalState = new Map(this._internalState);
|
|
return traceState;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/trace/internal/utils.js
|
|
function createTraceState(rawTraceState) {
|
|
return new TraceStateImpl(rawTraceState);
|
|
}
|
|
var init_utils2 = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/trace/internal/utils.js"() {
|
|
init_tracestate_impl();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/context-api.js
|
|
var context;
|
|
var init_context_api = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/context-api.js"() {
|
|
init_context2();
|
|
context = ContextAPI.getInstance();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/diag-api.js
|
|
var diag2;
|
|
var init_diag_api = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/diag-api.js"() {
|
|
init_diag();
|
|
diag2 = DiagAPI.instance();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/metrics/NoopMeterProvider.js
|
|
var NoopMeterProvider, NOOP_METER_PROVIDER;
|
|
var init_NoopMeterProvider = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/metrics/NoopMeterProvider.js"() {
|
|
init_NoopMeter();
|
|
NoopMeterProvider = class {
|
|
getMeter(_name, _version, _options) {
|
|
return NOOP_METER;
|
|
}
|
|
};
|
|
NOOP_METER_PROVIDER = new NoopMeterProvider();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/api/metrics.js
|
|
var API_NAME3, MetricsAPI;
|
|
var init_metrics = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/api/metrics.js"() {
|
|
init_NoopMeterProvider();
|
|
init_global_utils();
|
|
init_diag();
|
|
API_NAME3 = "metrics";
|
|
MetricsAPI = class _MetricsAPI {
|
|
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
|
constructor() {
|
|
}
|
|
/** Get the singleton instance of the Metrics API */
|
|
static getInstance() {
|
|
if (!this._instance) {
|
|
this._instance = new _MetricsAPI();
|
|
}
|
|
return this._instance;
|
|
}
|
|
/**
|
|
* Set the current global meter provider.
|
|
* Returns true if the meter provider was successfully registered, else false.
|
|
*/
|
|
setGlobalMeterProvider(provider) {
|
|
return registerGlobal(API_NAME3, provider, DiagAPI.instance());
|
|
}
|
|
/**
|
|
* Returns the global meter provider.
|
|
*/
|
|
getMeterProvider() {
|
|
return getGlobal(API_NAME3) || NOOP_METER_PROVIDER;
|
|
}
|
|
/**
|
|
* Returns a meter from the global meter provider.
|
|
*/
|
|
getMeter(name, version, options) {
|
|
return this.getMeterProvider().getMeter(name, version, options);
|
|
}
|
|
/** Remove the global meter provider */
|
|
disable() {
|
|
unregisterGlobal(API_NAME3, DiagAPI.instance());
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/metrics-api.js
|
|
var metrics;
|
|
var init_metrics_api = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/metrics-api.js"() {
|
|
init_metrics();
|
|
metrics = MetricsAPI.getInstance();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/propagation/NoopTextMapPropagator.js
|
|
var NoopTextMapPropagator;
|
|
var init_NoopTextMapPropagator = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/propagation/NoopTextMapPropagator.js"() {
|
|
NoopTextMapPropagator = class {
|
|
/** Noop inject function does nothing */
|
|
inject(_context, _carrier) {
|
|
}
|
|
/** Noop extract function does nothing and returns the input context */
|
|
extract(context2, _carrier) {
|
|
return context2;
|
|
}
|
|
fields() {
|
|
return [];
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/baggage/context-helpers.js
|
|
function getBaggage(context2) {
|
|
return context2.getValue(BAGGAGE_KEY) || void 0;
|
|
}
|
|
function getActiveBaggage() {
|
|
return getBaggage(ContextAPI.getInstance().active());
|
|
}
|
|
function setBaggage(context2, baggage) {
|
|
return context2.setValue(BAGGAGE_KEY, baggage);
|
|
}
|
|
function deleteBaggage(context2) {
|
|
return context2.deleteValue(BAGGAGE_KEY);
|
|
}
|
|
var BAGGAGE_KEY;
|
|
var init_context_helpers = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/baggage/context-helpers.js"() {
|
|
init_context2();
|
|
init_context();
|
|
BAGGAGE_KEY = createContextKey("OpenTelemetry Baggage Key");
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/api/propagation.js
|
|
var API_NAME4, NOOP_TEXT_MAP_PROPAGATOR, PropagationAPI;
|
|
var init_propagation = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/api/propagation.js"() {
|
|
init_global_utils();
|
|
init_NoopTextMapPropagator();
|
|
init_TextMapPropagator();
|
|
init_context_helpers();
|
|
init_utils();
|
|
init_diag();
|
|
API_NAME4 = "propagation";
|
|
NOOP_TEXT_MAP_PROPAGATOR = new NoopTextMapPropagator();
|
|
PropagationAPI = class _PropagationAPI {
|
|
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
|
constructor() {
|
|
this.createBaggage = createBaggage;
|
|
this.getBaggage = getBaggage;
|
|
this.getActiveBaggage = getActiveBaggage;
|
|
this.setBaggage = setBaggage;
|
|
this.deleteBaggage = deleteBaggage;
|
|
}
|
|
/** Get the singleton instance of the Propagator API */
|
|
static getInstance() {
|
|
if (!this._instance) {
|
|
this._instance = new _PropagationAPI();
|
|
}
|
|
return this._instance;
|
|
}
|
|
/**
|
|
* Set the current propagator.
|
|
*
|
|
* @returns true if the propagator was successfully registered, else false
|
|
*/
|
|
setGlobalPropagator(propagator) {
|
|
return registerGlobal(API_NAME4, propagator, DiagAPI.instance());
|
|
}
|
|
/**
|
|
* Inject context into a carrier to be propagated inter-process
|
|
*
|
|
* @param context Context carrying tracing data to inject
|
|
* @param carrier carrier to inject context into
|
|
* @param setter Function used to set values on the carrier
|
|
*/
|
|
inject(context2, carrier, setter = defaultTextMapSetter) {
|
|
return this._getGlobalPropagator().inject(context2, carrier, setter);
|
|
}
|
|
/**
|
|
* Extract context from a carrier
|
|
*
|
|
* @param context Context which the newly created context will inherit from
|
|
* @param carrier Carrier to extract context from
|
|
* @param getter Function used to extract keys from a carrier
|
|
*/
|
|
extract(context2, carrier, getter = defaultTextMapGetter) {
|
|
return this._getGlobalPropagator().extract(context2, carrier, getter);
|
|
}
|
|
/**
|
|
* Return a list of all fields which may be used by the propagator.
|
|
*/
|
|
fields() {
|
|
return this._getGlobalPropagator().fields();
|
|
}
|
|
/** Remove the global propagator */
|
|
disable() {
|
|
unregisterGlobal(API_NAME4, DiagAPI.instance());
|
|
}
|
|
_getGlobalPropagator() {
|
|
return getGlobal(API_NAME4) || NOOP_TEXT_MAP_PROPAGATOR;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/propagation-api.js
|
|
var propagation;
|
|
var init_propagation_api = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/propagation-api.js"() {
|
|
init_propagation();
|
|
propagation = PropagationAPI.getInstance();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/api/trace.js
|
|
var API_NAME5, TraceAPI;
|
|
var init_trace = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/api/trace.js"() {
|
|
init_global_utils();
|
|
init_ProxyTracerProvider();
|
|
init_spancontext_utils();
|
|
init_context_utils();
|
|
init_diag();
|
|
API_NAME5 = "trace";
|
|
TraceAPI = class _TraceAPI {
|
|
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
|
constructor() {
|
|
this._proxyTracerProvider = new ProxyTracerProvider();
|
|
this.wrapSpanContext = wrapSpanContext;
|
|
this.isSpanContextValid = isSpanContextValid;
|
|
this.deleteSpan = deleteSpan;
|
|
this.getSpan = getSpan;
|
|
this.getActiveSpan = getActiveSpan;
|
|
this.getSpanContext = getSpanContext;
|
|
this.setSpan = setSpan;
|
|
this.setSpanContext = setSpanContext;
|
|
}
|
|
/** Get the singleton instance of the Trace API */
|
|
static getInstance() {
|
|
if (!this._instance) {
|
|
this._instance = new _TraceAPI();
|
|
}
|
|
return this._instance;
|
|
}
|
|
/**
|
|
* Set the current global tracer.
|
|
*
|
|
* @returns true if the tracer provider was successfully registered, else false
|
|
*/
|
|
setGlobalTracerProvider(provider) {
|
|
const success = registerGlobal(API_NAME5, this._proxyTracerProvider, DiagAPI.instance());
|
|
if (success) {
|
|
this._proxyTracerProvider.setDelegate(provider);
|
|
}
|
|
return success;
|
|
}
|
|
/**
|
|
* Returns the global tracer provider.
|
|
*/
|
|
getTracerProvider() {
|
|
return getGlobal(API_NAME5) || this._proxyTracerProvider;
|
|
}
|
|
/**
|
|
* Returns a tracer from the global tracer provider.
|
|
*/
|
|
getTracer(name, version) {
|
|
return this.getTracerProvider().getTracer(name, version);
|
|
}
|
|
/** Remove the global tracer provider */
|
|
disable() {
|
|
unregisterGlobal(API_NAME5, DiagAPI.instance());
|
|
this._proxyTracerProvider = new ProxyTracerProvider();
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/trace-api.js
|
|
var trace;
|
|
var init_trace_api = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/trace-api.js"() {
|
|
init_trace();
|
|
trace = TraceAPI.getInstance();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/@opentelemetry/api/build/esm/index.js
|
|
var esm_exports = {};
|
|
__export(esm_exports, {
|
|
DiagConsoleLogger: () => DiagConsoleLogger,
|
|
DiagLogLevel: () => DiagLogLevel,
|
|
INVALID_SPANID: () => INVALID_SPANID,
|
|
INVALID_SPAN_CONTEXT: () => INVALID_SPAN_CONTEXT,
|
|
INVALID_TRACEID: () => INVALID_TRACEID,
|
|
ProxyTracer: () => ProxyTracer,
|
|
ProxyTracerProvider: () => ProxyTracerProvider,
|
|
ROOT_CONTEXT: () => ROOT_CONTEXT,
|
|
SamplingDecision: () => SamplingDecision,
|
|
SpanKind: () => SpanKind,
|
|
SpanStatusCode: () => SpanStatusCode,
|
|
TraceFlags: () => TraceFlags,
|
|
ValueType: () => ValueType,
|
|
baggageEntryMetadataFromString: () => baggageEntryMetadataFromString,
|
|
context: () => context,
|
|
createContextKey: () => createContextKey,
|
|
createNoopMeter: () => createNoopMeter,
|
|
createTraceState: () => createTraceState,
|
|
default: () => esm_default,
|
|
defaultTextMapGetter: () => defaultTextMapGetter,
|
|
defaultTextMapSetter: () => defaultTextMapSetter,
|
|
diag: () => diag2,
|
|
isSpanContextValid: () => isSpanContextValid,
|
|
isValidSpanId: () => isValidSpanId,
|
|
isValidTraceId: () => isValidTraceId,
|
|
metrics: () => metrics,
|
|
propagation: () => propagation,
|
|
trace: () => trace
|
|
});
|
|
var esm_default;
|
|
var init_esm = __esm({
|
|
"../../node_modules/@opentelemetry/api/build/esm/index.js"() {
|
|
init_utils();
|
|
init_context();
|
|
init_consoleLogger();
|
|
init_types();
|
|
init_NoopMeter();
|
|
init_Metric();
|
|
init_TextMapPropagator();
|
|
init_ProxyTracer();
|
|
init_ProxyTracerProvider();
|
|
init_SamplingResult();
|
|
init_span_kind();
|
|
init_status();
|
|
init_trace_flags();
|
|
init_utils2();
|
|
init_spancontext_utils();
|
|
init_invalid_span_constants();
|
|
init_context_api();
|
|
init_diag_api();
|
|
init_metrics_api();
|
|
init_propagation_api();
|
|
init_trace_api();
|
|
esm_default = {
|
|
context,
|
|
diag: diag2,
|
|
metrics,
|
|
propagation,
|
|
trace
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metrics/processCpuTotal.js
|
|
var require_processCpuTotal = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metrics/processCpuTotal.js"(exports, module) {
|
|
"use strict";
|
|
var process = __require("process");
|
|
var OtelApi = (init_esm(), __toCommonJS(esm_exports));
|
|
var Counter = require_counter();
|
|
var PROCESS_CPU_USER_SECONDS = "process_cpu_user_seconds_total";
|
|
var PROCESS_CPU_SYSTEM_SECONDS = "process_cpu_system_seconds_total";
|
|
var PROCESS_CPU_SECONDS = "process_cpu_seconds_total";
|
|
module.exports = (registry, config = {}) => {
|
|
const registers = registry ? [registry] : void 0;
|
|
const namePrefix = config.prefix ? config.prefix : "";
|
|
const labels = config.labels ? config.labels : {};
|
|
const exemplars = config.enableExemplars ? config.enableExemplars : false;
|
|
const labelNames = Object.keys(labels);
|
|
let lastCpuUsage = process.cpuUsage();
|
|
const cpuUserUsageCounter = new Counter({
|
|
name: namePrefix + PROCESS_CPU_USER_SECONDS,
|
|
help: "Total user CPU time spent in seconds.",
|
|
enableExemplars: exemplars,
|
|
registers,
|
|
labelNames,
|
|
// Use this one metric's `collect` to set all metrics' values.
|
|
collect() {
|
|
const cpuUsage = process.cpuUsage();
|
|
const userUsageMicros = cpuUsage.user - lastCpuUsage.user;
|
|
const systemUsageMicros = cpuUsage.system - lastCpuUsage.system;
|
|
lastCpuUsage = cpuUsage;
|
|
if (this.enableExemplars) {
|
|
let exemplarLabels = {};
|
|
const currentSpan = OtelApi.trace.getSpan(OtelApi.context.active());
|
|
if (currentSpan) {
|
|
exemplarLabels = {
|
|
traceId: currentSpan.spanContext().traceId,
|
|
spanId: currentSpan.spanContext().spanId
|
|
};
|
|
}
|
|
cpuUserUsageCounter.inc({
|
|
labels,
|
|
value: userUsageMicros / 1e6,
|
|
exemplarLabels
|
|
});
|
|
cpuSystemUsageCounter.inc({
|
|
labels,
|
|
value: systemUsageMicros / 1e6,
|
|
exemplarLabels
|
|
});
|
|
cpuUsageCounter.inc({
|
|
labels,
|
|
value: (userUsageMicros + systemUsageMicros) / 1e6,
|
|
exemplarLabels
|
|
});
|
|
} else {
|
|
cpuUserUsageCounter.inc(labels, userUsageMicros / 1e6);
|
|
cpuSystemUsageCounter.inc(labels, systemUsageMicros / 1e6);
|
|
cpuUsageCounter.inc(
|
|
labels,
|
|
(userUsageMicros + systemUsageMicros) / 1e6
|
|
);
|
|
}
|
|
}
|
|
});
|
|
const cpuSystemUsageCounter = new Counter({
|
|
name: namePrefix + PROCESS_CPU_SYSTEM_SECONDS,
|
|
help: "Total system CPU time spent in seconds.",
|
|
enableExemplars: exemplars,
|
|
registers,
|
|
labelNames
|
|
});
|
|
const cpuUsageCounter = new Counter({
|
|
name: namePrefix + PROCESS_CPU_SECONDS,
|
|
help: "Total user and system CPU time spent in seconds.",
|
|
enableExemplars: exemplars,
|
|
registers,
|
|
labelNames
|
|
});
|
|
};
|
|
module.exports.metricNames = [
|
|
PROCESS_CPU_USER_SECONDS,
|
|
PROCESS_CPU_SYSTEM_SECONDS,
|
|
PROCESS_CPU_SECONDS
|
|
];
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metrics/processStartTime.js
|
|
var require_processStartTime = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metrics/processStartTime.js"(exports, module) {
|
|
"use strict";
|
|
var process = __require("process");
|
|
var Gauge = require_gauge();
|
|
var startInSeconds = Math.round(Date.now() / 1e3 - process.uptime());
|
|
var PROCESS_START_TIME = "process_start_time_seconds";
|
|
module.exports = (registry, config = {}) => {
|
|
const namePrefix = config.prefix ? config.prefix : "";
|
|
const labels = config.labels ? config.labels : {};
|
|
const labelNames = Object.keys(labels);
|
|
new Gauge({
|
|
name: namePrefix + PROCESS_START_TIME,
|
|
help: "Start time of the process since unix epoch in seconds.",
|
|
registers: registry ? [registry] : void 0,
|
|
labelNames,
|
|
aggregator: "omit",
|
|
collect() {
|
|
this.set(labels, startInSeconds);
|
|
}
|
|
});
|
|
};
|
|
module.exports.metricNames = [PROCESS_START_TIME];
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metrics/osMemoryHeapLinux.js
|
|
var require_osMemoryHeapLinux = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metrics/osMemoryHeapLinux.js"(exports, module) {
|
|
"use strict";
|
|
var Gauge = require_gauge();
|
|
var fs = __require("fs");
|
|
var values = ["VmSize", "VmRSS", "VmData"];
|
|
var PROCESS_RESIDENT_MEMORY = "process_resident_memory_bytes";
|
|
var PROCESS_VIRTUAL_MEMORY = "process_virtual_memory_bytes";
|
|
var PROCESS_HEAP = "process_heap_bytes";
|
|
function structureOutput(input) {
|
|
return input.split("\n").reduce((acc, string) => {
|
|
if (!values.some((value2) => string.startsWith(value2))) {
|
|
return acc;
|
|
}
|
|
const split = string.split(":");
|
|
let value = split[1].trim();
|
|
value = value.substr(0, value.length - 3);
|
|
value = Number(value) * 1024;
|
|
acc[split[0]] = value;
|
|
return acc;
|
|
}, {});
|
|
}
|
|
module.exports = (registry, config = {}) => {
|
|
const registers = registry ? [registry] : void 0;
|
|
const namePrefix = config.prefix ? config.prefix : "";
|
|
const labels = config.labels ? config.labels : {};
|
|
const labelNames = Object.keys(labels);
|
|
const residentMemGauge = new Gauge({
|
|
name: namePrefix + PROCESS_RESIDENT_MEMORY,
|
|
help: "Resident memory size in bytes.",
|
|
registers,
|
|
labelNames,
|
|
// Use this one metric's `collect` to set all metrics' values.
|
|
collect() {
|
|
try {
|
|
const stat = fs.readFileSync("/proc/self/status", "utf8");
|
|
const structuredOutput = structureOutput(stat);
|
|
residentMemGauge.set(labels, structuredOutput.VmRSS);
|
|
virtualMemGauge.set(labels, structuredOutput.VmSize);
|
|
heapSizeMemGauge.set(labels, structuredOutput.VmData);
|
|
} catch {
|
|
}
|
|
}
|
|
});
|
|
const virtualMemGauge = new Gauge({
|
|
name: namePrefix + PROCESS_VIRTUAL_MEMORY,
|
|
help: "Virtual memory size in bytes.",
|
|
registers,
|
|
labelNames
|
|
});
|
|
const heapSizeMemGauge = new Gauge({
|
|
name: namePrefix + PROCESS_HEAP,
|
|
help: "Process heap size in bytes.",
|
|
registers,
|
|
labelNames
|
|
});
|
|
};
|
|
module.exports.metricNames = [
|
|
PROCESS_RESIDENT_MEMORY,
|
|
PROCESS_VIRTUAL_MEMORY,
|
|
PROCESS_HEAP
|
|
];
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metrics/helpers/safeMemoryUsage.js
|
|
var require_safeMemoryUsage = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metrics/helpers/safeMemoryUsage.js"(exports, module) {
|
|
"use strict";
|
|
var process = __require("process");
|
|
function safeMemoryUsage() {
|
|
try {
|
|
return process.memoryUsage();
|
|
} catch {
|
|
return;
|
|
}
|
|
}
|
|
module.exports = safeMemoryUsage;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metrics/osMemoryHeap.js
|
|
var require_osMemoryHeap = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metrics/osMemoryHeap.js"(exports, module) {
|
|
"use strict";
|
|
var process = __require("process");
|
|
var Gauge = require_gauge();
|
|
var linuxVariant = require_osMemoryHeapLinux();
|
|
var safeMemoryUsage = require_safeMemoryUsage();
|
|
var PROCESS_RESIDENT_MEMORY = "process_resident_memory_bytes";
|
|
function notLinuxVariant(registry, config = {}) {
|
|
const namePrefix = config.prefix ? config.prefix : "";
|
|
const labels = config.labels ? config.labels : {};
|
|
const labelNames = Object.keys(labels);
|
|
new Gauge({
|
|
name: namePrefix + PROCESS_RESIDENT_MEMORY,
|
|
help: "Resident memory size in bytes.",
|
|
registers: registry ? [registry] : void 0,
|
|
labelNames,
|
|
collect() {
|
|
const memUsage = safeMemoryUsage();
|
|
if (memUsage) {
|
|
this.set(labels, memUsage.rss);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
module.exports = (registry, config) => process.platform === "linux" ? linuxVariant(registry, config) : notLinuxVariant(registry, config);
|
|
module.exports.metricNames = process.platform === "linux" ? linuxVariant.metricNames : [PROCESS_RESIDENT_MEMORY];
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metrics/processOpenFileDescriptors.js
|
|
var require_processOpenFileDescriptors = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metrics/processOpenFileDescriptors.js"(exports, module) {
|
|
"use strict";
|
|
var Gauge = require_gauge();
|
|
var fs = __require("fs");
|
|
var process = __require("process");
|
|
var PROCESS_OPEN_FDS = "process_open_fds";
|
|
module.exports = (registry, config = {}) => {
|
|
if (process.platform !== "linux") {
|
|
return;
|
|
}
|
|
const namePrefix = config.prefix ? config.prefix : "";
|
|
const labels = config.labels ? config.labels : {};
|
|
const labelNames = Object.keys(labels);
|
|
new Gauge({
|
|
name: namePrefix + PROCESS_OPEN_FDS,
|
|
help: "Number of open file descriptors.",
|
|
registers: registry ? [registry] : void 0,
|
|
labelNames,
|
|
collect() {
|
|
try {
|
|
const fds = fs.readdirSync("/proc/self/fd");
|
|
this.set(labels, fds.length - 1);
|
|
} catch {
|
|
}
|
|
}
|
|
});
|
|
};
|
|
module.exports.metricNames = [PROCESS_OPEN_FDS];
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metrics/processMaxFileDescriptors.js
|
|
var require_processMaxFileDescriptors = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metrics/processMaxFileDescriptors.js"(exports, module) {
|
|
"use strict";
|
|
var Gauge = require_gauge();
|
|
var fs = __require("fs");
|
|
var PROCESS_MAX_FDS = "process_max_fds";
|
|
var maxFds;
|
|
module.exports = (registry, config = {}) => {
|
|
if (maxFds === void 0) {
|
|
try {
|
|
const limits = fs.readFileSync("/proc/self/limits", "utf8");
|
|
const lines = limits.split("\n");
|
|
for (const line of lines) {
|
|
if (line.startsWith("Max open files")) {
|
|
const parts = line.split(/ +/);
|
|
maxFds = Number(parts[1]);
|
|
break;
|
|
}
|
|
}
|
|
} catch {
|
|
return;
|
|
}
|
|
}
|
|
if (maxFds === void 0) return;
|
|
const namePrefix = config.prefix ? config.prefix : "";
|
|
const labels = config.labels ? config.labels : {};
|
|
const labelNames = Object.keys(labels);
|
|
new Gauge({
|
|
name: namePrefix + PROCESS_MAX_FDS,
|
|
help: "Maximum number of open file descriptors.",
|
|
registers: registry ? [registry] : void 0,
|
|
labelNames,
|
|
collect() {
|
|
if (maxFds !== void 0) this.set(labels, maxFds);
|
|
}
|
|
});
|
|
};
|
|
module.exports.metricNames = [PROCESS_MAX_FDS];
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metrics/eventLoopLag.js
|
|
var require_eventLoopLag = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metrics/eventLoopLag.js"(exports, module) {
|
|
"use strict";
|
|
var process = __require("process");
|
|
var Gauge = require_gauge();
|
|
var perf_hooks;
|
|
try {
|
|
perf_hooks = __require("perf_hooks");
|
|
} catch {
|
|
}
|
|
var NODEJS_EVENTLOOP_LAG = "nodejs_eventloop_lag_seconds";
|
|
var NODEJS_EVENTLOOP_LAG_MIN = "nodejs_eventloop_lag_min_seconds";
|
|
var NODEJS_EVENTLOOP_LAG_MAX = "nodejs_eventloop_lag_max_seconds";
|
|
var NODEJS_EVENTLOOP_LAG_MEAN = "nodejs_eventloop_lag_mean_seconds";
|
|
var NODEJS_EVENTLOOP_LAG_STDDEV = "nodejs_eventloop_lag_stddev_seconds";
|
|
var NODEJS_EVENTLOOP_LAG_P50 = "nodejs_eventloop_lag_p50_seconds";
|
|
var NODEJS_EVENTLOOP_LAG_P90 = "nodejs_eventloop_lag_p90_seconds";
|
|
var NODEJS_EVENTLOOP_LAG_P99 = "nodejs_eventloop_lag_p99_seconds";
|
|
function reportEventloopLag(start, gauge, labels) {
|
|
const delta = process.hrtime(start);
|
|
const nanosec = delta[0] * 1e9 + delta[1];
|
|
const seconds = nanosec / 1e9;
|
|
gauge.set(labels, seconds);
|
|
}
|
|
module.exports = (registry, config = {}) => {
|
|
const namePrefix = config.prefix ? config.prefix : "";
|
|
const labels = config.labels ? config.labels : {};
|
|
const labelNames = Object.keys(labels);
|
|
const registers = registry ? [registry] : void 0;
|
|
let collect = () => {
|
|
const start = process.hrtime();
|
|
setImmediate(reportEventloopLag, start, lag, labels);
|
|
};
|
|
if (perf_hooks && perf_hooks.monitorEventLoopDelay) {
|
|
try {
|
|
const histogram = perf_hooks.monitorEventLoopDelay({
|
|
resolution: config.eventLoopMonitoringPrecision
|
|
});
|
|
histogram.enable();
|
|
collect = () => {
|
|
const start = process.hrtime();
|
|
setImmediate(reportEventloopLag, start, lag, labels);
|
|
lagMin.set(labels, histogram.min / 1e9);
|
|
lagMax.set(labels, histogram.max / 1e9);
|
|
lagMean.set(labels, histogram.mean / 1e9);
|
|
lagStddev.set(labels, histogram.stddev / 1e9);
|
|
lagP50.set(labels, histogram.percentile(50) / 1e9);
|
|
lagP90.set(labels, histogram.percentile(90) / 1e9);
|
|
lagP99.set(labels, histogram.percentile(99) / 1e9);
|
|
histogram.reset();
|
|
};
|
|
} catch (e) {
|
|
if (e.code === "ERR_NOT_IMPLEMENTED") {
|
|
return;
|
|
}
|
|
throw e;
|
|
}
|
|
}
|
|
const lag = new Gauge({
|
|
name: namePrefix + NODEJS_EVENTLOOP_LAG,
|
|
help: "Lag of event loop in seconds.",
|
|
registers,
|
|
labelNames,
|
|
aggregator: "average",
|
|
// Use this one metric's `collect` to set all metrics' values.
|
|
collect
|
|
});
|
|
const lagMin = new Gauge({
|
|
name: namePrefix + NODEJS_EVENTLOOP_LAG_MIN,
|
|
help: "The minimum recorded event loop delay.",
|
|
registers,
|
|
labelNames,
|
|
aggregator: "min"
|
|
});
|
|
const lagMax = new Gauge({
|
|
name: namePrefix + NODEJS_EVENTLOOP_LAG_MAX,
|
|
help: "The maximum recorded event loop delay.",
|
|
registers,
|
|
labelNames,
|
|
aggregator: "max"
|
|
});
|
|
const lagMean = new Gauge({
|
|
name: namePrefix + NODEJS_EVENTLOOP_LAG_MEAN,
|
|
help: "The mean of the recorded event loop delays.",
|
|
registers,
|
|
labelNames,
|
|
aggregator: "average"
|
|
});
|
|
const lagStddev = new Gauge({
|
|
name: namePrefix + NODEJS_EVENTLOOP_LAG_STDDEV,
|
|
help: "The standard deviation of the recorded event loop delays.",
|
|
registers,
|
|
labelNames,
|
|
aggregator: "average"
|
|
});
|
|
const lagP50 = new Gauge({
|
|
name: namePrefix + NODEJS_EVENTLOOP_LAG_P50,
|
|
help: "The 50th percentile of the recorded event loop delays.",
|
|
registers,
|
|
labelNames,
|
|
aggregator: "average"
|
|
});
|
|
const lagP90 = new Gauge({
|
|
name: namePrefix + NODEJS_EVENTLOOP_LAG_P90,
|
|
help: "The 90th percentile of the recorded event loop delays.",
|
|
registers,
|
|
labelNames,
|
|
aggregator: "average"
|
|
});
|
|
const lagP99 = new Gauge({
|
|
name: namePrefix + NODEJS_EVENTLOOP_LAG_P99,
|
|
help: "The 99th percentile of the recorded event loop delays.",
|
|
registers,
|
|
labelNames,
|
|
aggregator: "average"
|
|
});
|
|
};
|
|
module.exports.metricNames = [
|
|
NODEJS_EVENTLOOP_LAG,
|
|
NODEJS_EVENTLOOP_LAG_MIN,
|
|
NODEJS_EVENTLOOP_LAG_MAX,
|
|
NODEJS_EVENTLOOP_LAG_MEAN,
|
|
NODEJS_EVENTLOOP_LAG_STDDEV,
|
|
NODEJS_EVENTLOOP_LAG_P50,
|
|
NODEJS_EVENTLOOP_LAG_P90,
|
|
NODEJS_EVENTLOOP_LAG_P99
|
|
];
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metrics/helpers/processMetricsHelpers.js
|
|
var require_processMetricsHelpers = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metrics/helpers/processMetricsHelpers.js"(exports, module) {
|
|
"use strict";
|
|
function aggregateByObjectName(list) {
|
|
const data = {};
|
|
for (let i = 0; i < list.length; i++) {
|
|
const listElement = list[i];
|
|
if (!listElement || typeof listElement.constructor === "undefined") {
|
|
continue;
|
|
}
|
|
if (Object.hasOwnProperty.call(data, listElement.constructor.name)) {
|
|
data[listElement.constructor.name] += 1;
|
|
} else {
|
|
data[listElement.constructor.name] = 1;
|
|
}
|
|
}
|
|
return data;
|
|
}
|
|
function updateMetrics(gauge, data, labels) {
|
|
gauge.reset();
|
|
for (const key in data) {
|
|
gauge.set(Object.assign({ type: key }, labels || {}), data[key]);
|
|
}
|
|
}
|
|
module.exports = {
|
|
aggregateByObjectName,
|
|
updateMetrics
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metrics/processHandles.js
|
|
var require_processHandles = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metrics/processHandles.js"(exports, module) {
|
|
"use strict";
|
|
var process = __require("process");
|
|
var { aggregateByObjectName } = require_processMetricsHelpers();
|
|
var { updateMetrics } = require_processMetricsHelpers();
|
|
var Gauge = require_gauge();
|
|
var NODEJS_ACTIVE_HANDLES = "nodejs_active_handles";
|
|
var NODEJS_ACTIVE_HANDLES_TOTAL = "nodejs_active_handles_total";
|
|
module.exports = (registry, config = {}) => {
|
|
if (typeof process._getActiveHandles !== "function") {
|
|
return;
|
|
}
|
|
const registers = registry ? [registry] : void 0;
|
|
const namePrefix = config.prefix ? config.prefix : "";
|
|
const labels = config.labels ? config.labels : {};
|
|
const labelNames = Object.keys(labels);
|
|
new Gauge({
|
|
name: namePrefix + NODEJS_ACTIVE_HANDLES,
|
|
help: "Number of active libuv handles grouped by handle type. Every handle type is C++ class name.",
|
|
labelNames: ["type", ...labelNames],
|
|
registers,
|
|
collect() {
|
|
const handles = process._getActiveHandles();
|
|
updateMetrics(this, aggregateByObjectName(handles), labels);
|
|
}
|
|
});
|
|
new Gauge({
|
|
name: namePrefix + NODEJS_ACTIVE_HANDLES_TOTAL,
|
|
help: "Total number of active handles.",
|
|
registers,
|
|
labelNames,
|
|
collect() {
|
|
const handles = process._getActiveHandles();
|
|
this.set(labels, handles.length);
|
|
}
|
|
});
|
|
};
|
|
module.exports.metricNames = [
|
|
NODEJS_ACTIVE_HANDLES,
|
|
NODEJS_ACTIVE_HANDLES_TOTAL
|
|
];
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metrics/processRequests.js
|
|
var require_processRequests = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metrics/processRequests.js"(exports, module) {
|
|
"use strict";
|
|
var process = __require("process");
|
|
var Gauge = require_gauge();
|
|
var { aggregateByObjectName } = require_processMetricsHelpers();
|
|
var { updateMetrics } = require_processMetricsHelpers();
|
|
var NODEJS_ACTIVE_REQUESTS = "nodejs_active_requests";
|
|
var NODEJS_ACTIVE_REQUESTS_TOTAL = "nodejs_active_requests_total";
|
|
module.exports = (registry, config = {}) => {
|
|
if (typeof process._getActiveRequests !== "function") {
|
|
return;
|
|
}
|
|
const namePrefix = config.prefix ? config.prefix : "";
|
|
const labels = config.labels ? config.labels : {};
|
|
const labelNames = Object.keys(labels);
|
|
new Gauge({
|
|
name: namePrefix + NODEJS_ACTIVE_REQUESTS,
|
|
help: "Number of active libuv requests grouped by request type. Every request type is C++ class name.",
|
|
labelNames: ["type", ...labelNames],
|
|
registers: registry ? [registry] : void 0,
|
|
collect() {
|
|
const requests = process._getActiveRequests();
|
|
updateMetrics(this, aggregateByObjectName(requests), labels);
|
|
}
|
|
});
|
|
new Gauge({
|
|
name: namePrefix + NODEJS_ACTIVE_REQUESTS_TOTAL,
|
|
help: "Total number of active requests.",
|
|
registers: registry ? [registry] : void 0,
|
|
labelNames,
|
|
collect() {
|
|
const requests = process._getActiveRequests();
|
|
this.set(labels, requests.length);
|
|
}
|
|
});
|
|
};
|
|
module.exports.metricNames = [
|
|
NODEJS_ACTIVE_REQUESTS,
|
|
NODEJS_ACTIVE_REQUESTS_TOTAL
|
|
];
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metrics/processResources.js
|
|
var require_processResources = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metrics/processResources.js"(exports, module) {
|
|
"use strict";
|
|
var process = __require("process");
|
|
var Gauge = require_gauge();
|
|
var { updateMetrics } = require_processMetricsHelpers();
|
|
var NODEJS_ACTIVE_RESOURCES = "nodejs_active_resources";
|
|
var NODEJS_ACTIVE_RESOURCES_TOTAL = "nodejs_active_resources_total";
|
|
module.exports = (registry, config = {}) => {
|
|
if (typeof process.getActiveResourcesInfo !== "function") {
|
|
return;
|
|
}
|
|
const namePrefix = config.prefix ? config.prefix : "";
|
|
const labels = config.labels ? config.labels : {};
|
|
const labelNames = Object.keys(labels);
|
|
new Gauge({
|
|
name: namePrefix + NODEJS_ACTIVE_RESOURCES,
|
|
help: "Number of active resources that are currently keeping the event loop alive, grouped by async resource type.",
|
|
labelNames: ["type", ...labelNames],
|
|
registers: registry ? [registry] : void 0,
|
|
collect() {
|
|
const resources = process.getActiveResourcesInfo();
|
|
const data = {};
|
|
for (let i = 0; i < resources.length; i++) {
|
|
const resource = resources[i];
|
|
if (Object.hasOwn(data, resource)) {
|
|
data[resource] += 1;
|
|
} else {
|
|
data[resource] = 1;
|
|
}
|
|
}
|
|
updateMetrics(this, data, labels);
|
|
}
|
|
});
|
|
new Gauge({
|
|
name: namePrefix + NODEJS_ACTIVE_RESOURCES_TOTAL,
|
|
help: "Total number of active resources.",
|
|
registers: registry ? [registry] : void 0,
|
|
labelNames,
|
|
collect() {
|
|
const resources = process.getActiveResourcesInfo();
|
|
this.set(labels, resources.length);
|
|
}
|
|
});
|
|
};
|
|
module.exports.metricNames = [
|
|
NODEJS_ACTIVE_RESOURCES,
|
|
NODEJS_ACTIVE_RESOURCES_TOTAL
|
|
];
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metrics/heapSizeAndUsed.js
|
|
var require_heapSizeAndUsed = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metrics/heapSizeAndUsed.js"(exports, module) {
|
|
"use strict";
|
|
var process = __require("process");
|
|
var Gauge = require_gauge();
|
|
var safeMemoryUsage = require_safeMemoryUsage();
|
|
var NODEJS_HEAP_SIZE_TOTAL = "nodejs_heap_size_total_bytes";
|
|
var NODEJS_HEAP_SIZE_USED = "nodejs_heap_size_used_bytes";
|
|
var NODEJS_EXTERNAL_MEMORY = "nodejs_external_memory_bytes";
|
|
module.exports = (registry, config = {}) => {
|
|
if (typeof process.memoryUsage !== "function") {
|
|
return;
|
|
}
|
|
const labels = config.labels ? config.labels : {};
|
|
const labelNames = Object.keys(labels);
|
|
const registers = registry ? [registry] : void 0;
|
|
const namePrefix = config.prefix ? config.prefix : "";
|
|
const collect = () => {
|
|
const memUsage = safeMemoryUsage();
|
|
if (memUsage) {
|
|
heapSizeTotal.set(labels, memUsage.heapTotal);
|
|
heapSizeUsed.set(labels, memUsage.heapUsed);
|
|
if (memUsage.external !== void 0) {
|
|
externalMemUsed.set(labels, memUsage.external);
|
|
}
|
|
}
|
|
};
|
|
const heapSizeTotal = new Gauge({
|
|
name: namePrefix + NODEJS_HEAP_SIZE_TOTAL,
|
|
help: "Process heap size from Node.js in bytes.",
|
|
registers,
|
|
labelNames,
|
|
// Use this one metric's `collect` to set all metrics' values.
|
|
collect
|
|
});
|
|
const heapSizeUsed = new Gauge({
|
|
name: namePrefix + NODEJS_HEAP_SIZE_USED,
|
|
help: "Process heap size used from Node.js in bytes.",
|
|
registers,
|
|
labelNames
|
|
});
|
|
const externalMemUsed = new Gauge({
|
|
name: namePrefix + NODEJS_EXTERNAL_MEMORY,
|
|
help: "Node.js external memory size in bytes.",
|
|
registers,
|
|
labelNames
|
|
});
|
|
};
|
|
module.exports.metricNames = [
|
|
NODEJS_HEAP_SIZE_TOTAL,
|
|
NODEJS_HEAP_SIZE_USED,
|
|
NODEJS_EXTERNAL_MEMORY
|
|
];
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metrics/heapSpacesSizeAndUsed.js
|
|
var require_heapSpacesSizeAndUsed = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metrics/heapSpacesSizeAndUsed.js"(exports, module) {
|
|
"use strict";
|
|
var Gauge = require_gauge();
|
|
var v8 = __require("v8");
|
|
var METRICS = ["total", "used", "available"];
|
|
var NODEJS_HEAP_SIZE = {};
|
|
METRICS.forEach((metricType) => {
|
|
NODEJS_HEAP_SIZE[metricType] = `nodejs_heap_space_size_${metricType}_bytes`;
|
|
});
|
|
module.exports = (registry, config = {}) => {
|
|
try {
|
|
v8.getHeapSpaceStatistics();
|
|
} catch (e) {
|
|
if (e.code === "ERR_NOT_IMPLEMENTED") {
|
|
return;
|
|
}
|
|
throw e;
|
|
}
|
|
const registers = registry ? [registry] : void 0;
|
|
const namePrefix = config.prefix ? config.prefix : "";
|
|
const labels = config.labels ? config.labels : {};
|
|
const labelNames = ["space", ...Object.keys(labels)];
|
|
const gauges = {};
|
|
METRICS.forEach((metricType) => {
|
|
gauges[metricType] = new Gauge({
|
|
name: namePrefix + NODEJS_HEAP_SIZE[metricType],
|
|
help: `Process heap space size ${metricType} from Node.js in bytes.`,
|
|
labelNames,
|
|
registers
|
|
});
|
|
});
|
|
gauges.total.collect = () => {
|
|
for (const space of v8.getHeapSpaceStatistics()) {
|
|
const spaceName = space.space_name.substr(
|
|
0,
|
|
space.space_name.indexOf("_space")
|
|
);
|
|
gauges.total.set({ space: spaceName, ...labels }, space.space_size);
|
|
gauges.used.set({ space: spaceName, ...labels }, space.space_used_size);
|
|
gauges.available.set(
|
|
{ space: spaceName, ...labels },
|
|
space.space_available_size
|
|
);
|
|
}
|
|
};
|
|
};
|
|
module.exports.metricNames = Object.values(NODEJS_HEAP_SIZE);
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metrics/version.js
|
|
var require_version = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metrics/version.js"(exports, module) {
|
|
"use strict";
|
|
var process = __require("process");
|
|
var Gauge = require_gauge();
|
|
var version = process.version;
|
|
var versionSegments = version.slice(1).split(".").map(Number);
|
|
var NODE_VERSION_INFO = "nodejs_version_info";
|
|
module.exports = (registry, config = {}) => {
|
|
const namePrefix = config.prefix ? config.prefix : "";
|
|
const labels = config.labels ? config.labels : {};
|
|
const labelNames = Object.keys(labels);
|
|
new Gauge({
|
|
name: namePrefix + NODE_VERSION_INFO,
|
|
help: "Node.js version info.",
|
|
labelNames: ["version", "major", "minor", "patch", ...labelNames],
|
|
registers: registry ? [registry] : void 0,
|
|
aggregator: "first",
|
|
collect() {
|
|
this.labels(
|
|
version,
|
|
versionSegments[0],
|
|
versionSegments[1],
|
|
versionSegments[2],
|
|
...Object.values(labels)
|
|
).set(1);
|
|
}
|
|
});
|
|
};
|
|
module.exports.metricNames = [NODE_VERSION_INFO];
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metrics/gc.js
|
|
var require_gc = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metrics/gc.js"(exports, module) {
|
|
"use strict";
|
|
var Histogram = require_histogram();
|
|
var perf_hooks;
|
|
try {
|
|
perf_hooks = __require("perf_hooks");
|
|
} catch {
|
|
}
|
|
var NODEJS_GC_DURATION_SECONDS = "nodejs_gc_duration_seconds";
|
|
var DEFAULT_GC_DURATION_BUCKETS = [1e-3, 0.01, 0.1, 1, 2, 5];
|
|
var kinds = [];
|
|
if (perf_hooks && perf_hooks.constants) {
|
|
kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR] = "major";
|
|
kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_MINOR] = "minor";
|
|
kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL] = "incremental";
|
|
kinds[perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB] = "weakcb";
|
|
}
|
|
module.exports = (registry, config = {}) => {
|
|
if (!perf_hooks) {
|
|
return;
|
|
}
|
|
const namePrefix = config.prefix ? config.prefix : "";
|
|
const labels = config.labels ? config.labels : {};
|
|
const labelNames = Object.keys(labels);
|
|
const buckets = config.gcDurationBuckets ? config.gcDurationBuckets : DEFAULT_GC_DURATION_BUCKETS;
|
|
const gcHistogram = new Histogram({
|
|
name: namePrefix + NODEJS_GC_DURATION_SECONDS,
|
|
help: "Garbage collection duration by kind, one of major, minor, incremental or weakcb.",
|
|
labelNames: ["kind", ...labelNames],
|
|
enableExemplars: false,
|
|
buckets,
|
|
registers: registry ? [registry] : void 0
|
|
});
|
|
const obs = new perf_hooks.PerformanceObserver((list) => {
|
|
const entry = list.getEntries()[0];
|
|
const kind = entry.detail ? kinds[entry.detail.kind] : kinds[entry.kind];
|
|
gcHistogram.observe(Object.assign({ kind }, labels), entry.duration / 1e3);
|
|
});
|
|
obs.observe({ entryTypes: ["gc"] });
|
|
};
|
|
module.exports.metricNames = [NODEJS_GC_DURATION_SECONDS];
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/defaultMetrics.js
|
|
var require_defaultMetrics = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/defaultMetrics.js"(exports, module) {
|
|
"use strict";
|
|
var process = __require("process");
|
|
var { isObject } = require_util();
|
|
var processCpuTotal = require_processCpuTotal();
|
|
var processStartTime = require_processStartTime();
|
|
var osMemoryHeap = require_osMemoryHeap();
|
|
var processOpenFileDescriptors = require_processOpenFileDescriptors();
|
|
var processMaxFileDescriptors = require_processMaxFileDescriptors();
|
|
var eventLoopLag = require_eventLoopLag();
|
|
var processHandles = require_processHandles();
|
|
var processRequests = require_processRequests();
|
|
var processResources = require_processResources();
|
|
var heapSizeAndUsed = require_heapSizeAndUsed();
|
|
var heapSpacesSizeAndUsed = require_heapSpacesSizeAndUsed();
|
|
var version = require_version();
|
|
var gc = require_gc();
|
|
var metrics2 = {
|
|
processCpuTotal,
|
|
processStartTime,
|
|
osMemoryHeap,
|
|
processOpenFileDescriptors,
|
|
processMaxFileDescriptors,
|
|
eventLoopLag,
|
|
...typeof process.getActiveResourcesInfo === "function" ? { processResources } : {},
|
|
processHandles,
|
|
processRequests,
|
|
heapSizeAndUsed,
|
|
heapSpacesSizeAndUsed,
|
|
version,
|
|
gc
|
|
};
|
|
var metricsList = Object.keys(metrics2);
|
|
module.exports = function collectDefaultMetrics(config) {
|
|
if (config !== null && config !== void 0 && !isObject(config)) {
|
|
throw new TypeError("config must be null, undefined, or an object");
|
|
}
|
|
config = { eventLoopMonitoringPrecision: 10, ...config };
|
|
for (const metric of Object.values(metrics2)) {
|
|
metric(config.register, config);
|
|
}
|
|
};
|
|
module.exports.metricsList = metricsList;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/metricAggregators.js
|
|
var require_metricAggregators = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/metricAggregators.js"(exports) {
|
|
"use strict";
|
|
var { Grouper, hashObject } = require_util();
|
|
function AggregatorFactory(aggregatorFn) {
|
|
return (metrics2) => {
|
|
if (metrics2.length === 0) return;
|
|
const result = {
|
|
help: metrics2[0].help,
|
|
name: metrics2[0].name,
|
|
type: metrics2[0].type,
|
|
values: [],
|
|
aggregator: metrics2[0].aggregator
|
|
};
|
|
const byLabels = new Grouper();
|
|
metrics2.forEach((metric) => {
|
|
metric.values.forEach((value) => {
|
|
const key = hashObject(value.labels);
|
|
byLabels.add(`${value.metricName}_${key}`, value);
|
|
});
|
|
});
|
|
byLabels.forEach((values) => {
|
|
if (values.length === 0) return;
|
|
const valObj = {
|
|
value: aggregatorFn(values),
|
|
labels: values[0].labels
|
|
};
|
|
if (values[0].metricName) {
|
|
valObj.metricName = values[0].metricName;
|
|
}
|
|
result.values.push(valObj);
|
|
});
|
|
return result;
|
|
};
|
|
}
|
|
exports.AggregatorFactory = AggregatorFactory;
|
|
exports.aggregators = {
|
|
/**
|
|
* @return The sum of values.
|
|
*/
|
|
sum: AggregatorFactory((v) => v.reduce((p, c) => p + c.value, 0)),
|
|
/**
|
|
* @return The first value.
|
|
*/
|
|
first: AggregatorFactory((v) => v[0].value),
|
|
/**
|
|
* @return {undefined} Undefined; omits the metric.
|
|
*/
|
|
omit: () => {
|
|
},
|
|
/**
|
|
* @return The arithmetic mean of the values.
|
|
*/
|
|
average: AggregatorFactory(
|
|
(v) => v.reduce((p, c) => p + c.value, 0) / v.length
|
|
),
|
|
/**
|
|
* @return The minimum of the values.
|
|
*/
|
|
min: AggregatorFactory(
|
|
(v) => v.reduce((p, c) => Math.min(p, c.value), Infinity)
|
|
),
|
|
/**
|
|
* @return The maximum of the values.
|
|
*/
|
|
max: AggregatorFactory(
|
|
(v) => v.reduce((p, c) => Math.max(p, c.value), -Infinity)
|
|
)
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/lib/cluster.js
|
|
var require_cluster = __commonJS({
|
|
"../../node_modules/bare-prom-client/lib/cluster.js"(exports, module) {
|
|
"use strict";
|
|
var process = __require("process");
|
|
var Registry = require_registry();
|
|
var { Grouper } = require_util();
|
|
var { aggregators } = require_metricAggregators();
|
|
var cluster = () => {
|
|
const data = __require("cluster");
|
|
cluster = () => data;
|
|
return data;
|
|
};
|
|
var GET_METRICS_REQ = "prom-client:getMetricsReq";
|
|
var GET_METRICS_RES = "prom-client:getMetricsRes";
|
|
var registries = [Registry.globalRegistry];
|
|
var requestCtr = 0;
|
|
var listenersAdded = false;
|
|
var requests = /* @__PURE__ */ new Map();
|
|
var AggregatorRegistry = class extends Registry {
|
|
constructor(regContentType = Registry.PROMETHEUS_CONTENT_TYPE) {
|
|
super(regContentType);
|
|
addListeners();
|
|
}
|
|
/**
|
|
* Gets aggregated metrics for all workers. The optional callback and
|
|
* returned Promise resolve with the same value; either may be used.
|
|
* @return {Promise<string>} Promise that resolves with the aggregated
|
|
* metrics.
|
|
*/
|
|
clusterMetrics() {
|
|
const requestId = requestCtr++;
|
|
return new Promise((resolve, reject) => {
|
|
let settled = false;
|
|
function done(err, result) {
|
|
if (settled) return;
|
|
settled = true;
|
|
if (err) reject(err);
|
|
else resolve(result);
|
|
}
|
|
const request = {
|
|
responses: [],
|
|
pending: 0,
|
|
done,
|
|
errorTimeout: setTimeout(() => {
|
|
const err = new Error("Operation timed out.");
|
|
request.done(err);
|
|
}, 5e3)
|
|
};
|
|
requests.set(requestId, request);
|
|
const message = {
|
|
type: GET_METRICS_REQ,
|
|
requestId
|
|
};
|
|
for (const id in cluster().workers) {
|
|
if (cluster().workers[id].isConnected()) {
|
|
cluster().workers[id].send(message);
|
|
request.pending++;
|
|
}
|
|
}
|
|
if (request.pending === 0) {
|
|
clearTimeout(request.errorTimeout);
|
|
process.nextTick(() => done(null, ""));
|
|
}
|
|
});
|
|
}
|
|
get contentType() {
|
|
return super.contentType;
|
|
}
|
|
/**
|
|
* Creates a new Registry instance from an array of metrics that were
|
|
* created by `registry.getMetricsAsJSON()`. Metrics are aggregated using
|
|
* the method specified by their `aggregator` property, or by summation if
|
|
* `aggregator` is undefined.
|
|
* @param {Array} metricsArr Array of metrics, each of which created by
|
|
* `registry.getMetricsAsJSON()`.
|
|
* @param {string} registryType content type of the new registry. Defaults
|
|
* to PROMETHEUS_CONTENT_TYPE.
|
|
* @return {Registry} aggregated registry.
|
|
*/
|
|
static aggregate(metricsArr, registryType = Registry.PROMETHEUS_CONTENT_TYPE) {
|
|
const aggregatedRegistry = new Registry();
|
|
const metricsByName = new Grouper();
|
|
aggregatedRegistry.setContentType(registryType);
|
|
metricsArr.forEach((metrics2) => {
|
|
metrics2.forEach((metric) => {
|
|
metricsByName.add(metric.name, metric);
|
|
});
|
|
});
|
|
metricsByName.forEach((metrics2) => {
|
|
const aggregatorName = metrics2[0].aggregator;
|
|
const aggregatorFn = aggregators[aggregatorName];
|
|
if (typeof aggregatorFn !== "function") {
|
|
throw new Error(`'${aggregatorName}' is not a defined aggregator.`);
|
|
}
|
|
const aggregatedMetric = aggregatorFn(metrics2);
|
|
if (aggregatedMetric) {
|
|
const aggregatedMetricWrapper = Object.assign(
|
|
{
|
|
get: () => aggregatedMetric
|
|
},
|
|
aggregatedMetric
|
|
);
|
|
aggregatedRegistry.registerMetric(aggregatedMetricWrapper);
|
|
}
|
|
});
|
|
return aggregatedRegistry;
|
|
}
|
|
/**
|
|
* Sets the registry or registries to be aggregated. Call from workers to
|
|
* use a registry/registries other than the default global registry.
|
|
* @param {Array<Registry>|Registry} regs Registry or registries to be
|
|
* aggregated.
|
|
* @return {void}
|
|
*/
|
|
static setRegistries(regs) {
|
|
if (!Array.isArray(regs)) regs = [regs];
|
|
regs.forEach((reg) => {
|
|
if (!(reg instanceof Registry)) {
|
|
throw new TypeError(`Expected Registry, got ${typeof reg}`);
|
|
}
|
|
});
|
|
registries = regs;
|
|
}
|
|
};
|
|
function addListeners() {
|
|
if (listenersAdded) return;
|
|
listenersAdded = true;
|
|
if (cluster().isMaster) {
|
|
cluster().on("message", (worker, message) => {
|
|
if (message.type === GET_METRICS_RES) {
|
|
const request = requests.get(message.requestId);
|
|
if (message.error) {
|
|
request.done(new Error(message.error));
|
|
return;
|
|
}
|
|
message.metrics.forEach((registry) => request.responses.push(registry));
|
|
request.pending--;
|
|
if (request.pending === 0) {
|
|
requests.delete(message.requestId);
|
|
clearTimeout(request.errorTimeout);
|
|
const registry = AggregatorRegistry.aggregate(request.responses);
|
|
const promString = registry.metrics();
|
|
request.done(null, promString);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
if (cluster().isWorker) {
|
|
process.on("message", (message) => {
|
|
if (message.type === GET_METRICS_REQ) {
|
|
Promise.all(registries.map((r) => r.getMetricsAsJSON())).then((metrics2) => {
|
|
process.send({
|
|
type: GET_METRICS_RES,
|
|
requestId: message.requestId,
|
|
metrics: metrics2
|
|
});
|
|
}).catch((error) => {
|
|
process.send({
|
|
type: GET_METRICS_RES,
|
|
requestId: message.requestId,
|
|
error: error.message
|
|
});
|
|
});
|
|
}
|
|
});
|
|
}
|
|
}
|
|
module.exports = AggregatorRegistry;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-prom-client/index.js
|
|
var require_bare_prom_client = __commonJS({
|
|
"../../node_modules/bare-prom-client/index.js"(exports) {
|
|
"use strict";
|
|
exports.register = require_registry().globalRegistry;
|
|
exports.Registry = require_registry();
|
|
Object.defineProperty(exports, "contentType", {
|
|
configurable: false,
|
|
enumerable: true,
|
|
get() {
|
|
return exports.register.contentType;
|
|
},
|
|
set(value) {
|
|
exports.register.setContentType(value);
|
|
}
|
|
});
|
|
exports.prometheusContentType = exports.Registry.PROMETHEUS_CONTENT_TYPE;
|
|
exports.openMetricsContentType = exports.Registry.OPENMETRICS_CONTENT_TYPE;
|
|
exports.validateMetricName = require_validation().validateMetricName;
|
|
exports.Counter = require_counter();
|
|
exports.Gauge = require_gauge();
|
|
exports.Histogram = require_histogram();
|
|
exports.Summary = require_summary();
|
|
exports.Pushgateway = require_pushgateway();
|
|
exports.linearBuckets = require_bucketGenerators().linearBuckets;
|
|
exports.exponentialBuckets = require_bucketGenerators().exponentialBuckets;
|
|
exports.collectDefaultMetrics = require_defaultMetrics();
|
|
exports.aggregators = require_metricAggregators().aggregators;
|
|
exports.AggregatorRegistry = require_cluster();
|
|
}
|
|
});
|
|
|
|
// ../../bare-lib-entry-barePromClient.js
|
|
var bare_lib_entry_barePromClient_exports = {};
|
|
__export(bare_lib_entry_barePromClient_exports, {
|
|
default: () => bare_lib_entry_barePromClient_default
|
|
});
|
|
var import_bare_prom_client = __toESM(require_bare_prom_client());
|
|
var bare_lib_entry_barePromClient_default = import_bare_prom_client.default;
|
|
return __toCommonJS(bare_lib_entry_barePromClient_exports);
|
|
})();
|
|
;(function(){var g=globalThis;var s="__bare_os_stdlib__";g[s]=g[s]||{};g[s]["barePromClient"]=typeof __bare_os_bundle_exports__!=="undefined"?__bare_os_bundle_exports__:void 0;})();
|