@bettercorp/service-base
Advanced tools
Comparing version 8.5.68 to 8.5.70
@@ -52,1 +52,3 @@ import { DEBUG_MODE, IPluginLogger } from "../interfaces"; | ||
} | ||
export declare const NS_PER_SEC = 1000000000; | ||
export declare const MS_PER_NS = 0.000001; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BaseWithLoggingAndConfig = exports.BaseWithLogging = exports.BaseWithConfig = exports.Base = exports.MainBase = void 0; | ||
exports.MS_PER_NS = exports.NS_PER_SEC = exports.BaseWithLoggingAndConfig = exports.BaseWithLogging = exports.BaseWithConfig = exports.Base = exports.MainBase = void 0; | ||
const PluginLogger_1 = require("./PluginLogger"); | ||
@@ -55,2 +55,4 @@ class MainBase { | ||
exports.BaseWithLoggingAndConfig = BaseWithLoggingAndConfig; | ||
exports.NS_PER_SEC = 1e9; | ||
exports.MS_PER_NS = 1e-6; | ||
//# sourceMappingURL=base.js.map |
@@ -8,7 +8,7 @@ import { BaseWithConfig, BaseWithConfigConfig } from "./base"; | ||
constructor(config: BSBMetricsConstructor<ReferencedConfig>); | ||
abstract createCounter(pluginName: string, name: string, description?: string): void | Promise<void>; | ||
abstract createCounter(pluginName: string, name: string, description: string, help: string): void | Promise<void>; | ||
abstract updateCounter(event: "inc", pluginName: string, name: string, value: number, labels?: Record<string, string>): void | Promise<void>; | ||
abstract createGauge(pluginName: string, name: string, description?: string): void | Promise<void>; | ||
abstract createGauge(pluginName: string, name: string, description: string, help: string): void | Promise<void>; | ||
abstract updateGauge(event: "set" | "inc" | "dec", pluginName: string, name: string, value: number, labels?: Record<string, string>): void | Promise<void>; | ||
abstract createHistogram(pluginName: string, name: string, description?: string, boundaries?: number[] | undefined): void | Promise<void>; | ||
abstract createHistogram(pluginName: string, name: string, description: string, help: string, boundaries?: number[] | undefined): void | Promise<void>; | ||
abstract updateHistogram(event: "record", pluginName: string, name: string, value: number, labels?: Record<string, string>): void | Promise<void>; | ||
@@ -22,18 +22,16 @@ abstract startTrace(pluginName: string, traceId: string): void | Promise<void>; | ||
export declare class BSBMetricsRef extends BSBMetrics { | ||
startTrace(pluginName: string, traceId: string): void | Promise<void>; | ||
endTrace(pluginName: string, traceId: string, attributes?: Record<string, string>): void | Promise<void>; | ||
startSpan(pluginName: string, traceId: string, spanId: string, name: string, attributes?: Record<string, string>): void | Promise<void>; | ||
endSpan(pluginName: string, traceId: string, spanId: string, attributes?: Record<string, string>): void | Promise<void>; | ||
errorSpan(pluginName: string, traceId: string, spanId: string, error: BSBError<any> | Error, attributes?: Record<string, string>): void | Promise<void>; | ||
updateMetric(type: "counter" | "gauge" | "histogram", pluginName: string, name: string, value: number, labels?: Record<string, string>): void; | ||
createCounter(pluginName: string, name: string, description?: string): void; | ||
updateCounter(event: "inc", pluginName: string, name: string, value: number, labels?: Record<string, string>): void; | ||
createGauge(pluginName: string, name: string, description?: string): void; | ||
updateGauge(event: "set" | "inc" | "dec", pluginName: string, name: string, value: number, labels?: Record<string, string>): void; | ||
createHistogram(pluginName: string, name: string, description?: string, boundaries?: number[] | undefined): void; | ||
updateHistogram(event: "record", pluginName: string, name: string, value: number, labels?: Record<string, string>): void; | ||
createTrace(pluginName: string, name: string, description?: string): void; | ||
dispose?(): void; | ||
init?(): void; | ||
run?(): void; | ||
createCounter(pluginName: string, name: string, description: string, help: string): void | Promise<void>; | ||
createGauge(pluginName: string, name: string, description: string, help: string): void | Promise<void>; | ||
createHistogram(pluginName: string, name: string, description: string, help: string, boundaries: number[] | undefined): void | Promise<void>; | ||
endSpan(pluginName: string, traceId: string, spanId: string, attributes: Record<string, string> | undefined): void | Promise<void>; | ||
endTrace(pluginName: string, traceId: string, attributes: Record<string, string> | undefined): void | Promise<void>; | ||
errorSpan(pluginName: string, traceId: string, spanId: string, error: BSBError<any> | Error, attributes: Record<string, string> | undefined): void | Promise<void>; | ||
startSpan(pluginName: string, traceId: string, spanId: string, name: string, attributes: Record<string, string> | undefined): void | Promise<void>; | ||
startTrace(pluginName: string, traceId: string): void | Promise<void>; | ||
updateCounter(event: "inc", pluginName: string, name: string, value: number, labels: Record<string, string> | undefined): void | Promise<void>; | ||
updateGauge(event: "set" | "inc" | "dec", pluginName: string, name: string, value: number, labels: Record<string, string> | undefined): void | Promise<void>; | ||
updateHistogram(event: "record", pluginName: string, name: string, value: number, labels: Record<string, string> | undefined): void | Promise<void>; | ||
} |
@@ -13,10 +13,10 @@ "use strict"; | ||
class BSBMetricsRef extends BSBMetrics { | ||
startTrace(pluginName, traceId) { | ||
throw (0, errorMessages_1.BSB_ERROR_METHOD_NOT_IMPLEMENTED)("BSBMetricsRef", "startTrace"); | ||
createCounter(pluginName, name, description, help) { | ||
throw (0, errorMessages_1.BSB_ERROR_METHOD_NOT_IMPLEMENTED)("BSBMetricsRef", "createCounter"); | ||
} | ||
endTrace(pluginName, traceId, attributes) { | ||
throw (0, errorMessages_1.BSB_ERROR_METHOD_NOT_IMPLEMENTED)("BSBMetricsRef", "endTrace"); | ||
createGauge(pluginName, name, description, help) { | ||
throw (0, errorMessages_1.BSB_ERROR_METHOD_NOT_IMPLEMENTED)("BSBMetricsRef", "createGauge"); | ||
} | ||
startSpan(pluginName, traceId, spanId, name, attributes) { | ||
throw (0, errorMessages_1.BSB_ERROR_METHOD_NOT_IMPLEMENTED)("BSBMetricsRef", "startSpan"); | ||
createHistogram(pluginName, name, description, help, boundaries) { | ||
throw (0, errorMessages_1.BSB_ERROR_METHOD_NOT_IMPLEMENTED)("BSBMetricsRef", "createHistogram"); | ||
} | ||
@@ -26,10 +26,13 @@ endSpan(pluginName, traceId, spanId, attributes) { | ||
} | ||
endTrace(pluginName, traceId, attributes) { | ||
throw (0, errorMessages_1.BSB_ERROR_METHOD_NOT_IMPLEMENTED)("BSBMetricsRef", "endTrace"); | ||
} | ||
errorSpan(pluginName, traceId, spanId, error, attributes) { | ||
throw (0, errorMessages_1.BSB_ERROR_METHOD_NOT_IMPLEMENTED)("BSBMetricsRef", "errorSpan"); | ||
} | ||
updateMetric(type, pluginName, name, value, labels) { | ||
throw (0, errorMessages_1.BSB_ERROR_METHOD_NOT_IMPLEMENTED)("BSBMetricsRef", "updateMetric"); | ||
startSpan(pluginName, traceId, spanId, name, attributes) { | ||
throw (0, errorMessages_1.BSB_ERROR_METHOD_NOT_IMPLEMENTED)("BSBMetricsRef", "startSpan"); | ||
} | ||
createCounter(pluginName, name, description) { | ||
throw (0, errorMessages_1.BSB_ERROR_METHOD_NOT_IMPLEMENTED)("BSBMetricsRef", "createCounter"); | ||
startTrace(pluginName, traceId) { | ||
throw (0, errorMessages_1.BSB_ERROR_METHOD_NOT_IMPLEMENTED)("BSBMetricsRef", "startTrace"); | ||
} | ||
@@ -39,19 +42,10 @@ updateCounter(event, pluginName, name, value, labels) { | ||
} | ||
createGauge(pluginName, name, description) { | ||
throw (0, errorMessages_1.BSB_ERROR_METHOD_NOT_IMPLEMENTED)("BSBMetricsRef", "createGauge"); | ||
} | ||
updateGauge(event, pluginName, name, value, labels) { | ||
throw (0, errorMessages_1.BSB_ERROR_METHOD_NOT_IMPLEMENTED)("BSBMetricsRef", "gaugeEvent"); | ||
} | ||
createHistogram(pluginName, name, description, boundaries) { | ||
throw (0, errorMessages_1.BSB_ERROR_METHOD_NOT_IMPLEMENTED)("BSBMetricsRef", "createHistogram"); | ||
} | ||
updateHistogram(event, pluginName, name, value, labels) { | ||
throw (0, errorMessages_1.BSB_ERROR_METHOD_NOT_IMPLEMENTED)("BSBMetricsRef", "histogramEvent"); | ||
} | ||
createTrace(pluginName, name, description) { | ||
throw (0, errorMessages_1.BSB_ERROR_METHOD_NOT_IMPLEMENTED)("BSBMetricsRef", "createTrace"); | ||
} | ||
} | ||
exports.BSBMetricsRef = BSBMetricsRef; | ||
//# sourceMappingURL=BSBMetrics.js.map |
@@ -5,2 +5,3 @@ "use strict"; | ||
const errorMessages_1 = require("./errorMessages"); | ||
const tools_1 = require("./tools"); | ||
class BSBServiceClient { | ||
@@ -28,2 +29,8 @@ callMethod(...args) { | ||
super(context); | ||
if (!tools_1.Tools.isObject(service.PLUGIN_CLIENT)) { | ||
throw new errorMessages_1.BSBError("Plugin client is not defined in the service!"); | ||
} | ||
if (!tools_1.Tools.isString(service.PLUGIN_CLIENT.name)) { | ||
throw new errorMessages_1.BSBError("Plugin client name is not defined in the service!"); | ||
} | ||
this.pluginName = service.PLUGIN_CLIENT.name; | ||
@@ -30,0 +37,0 @@ this.initBeforePlugins = service.PLUGIN_CLIENT.initBeforePlugins; |
@@ -1,2 +0,2 @@ | ||
import { Counter, Gauge, Histogram, IPluginMetrics, Trace } from "../interfaces"; | ||
import { Counter, Gauge, Histogram, IPluginMetrics, Timer, Trace } from "../interfaces"; | ||
import { SBMetrics } from "../serviceBase"; | ||
@@ -8,6 +8,7 @@ export declare class PluginMetrics implements IPluginMetrics { | ||
constructor(plugin: string, metrics: SBMetrics); | ||
createCounter(name: string, description?: string): Counter; | ||
createGauge(name: string, description?: string): Gauge; | ||
createHistogram(name: string, description?: string, boundaries?: number[] | undefined): Histogram; | ||
createCounter(name: string, description: string, help: string): Counter; | ||
createGauge(name: string, description: string, help: string): Gauge; | ||
createHistogram(name: string, description: string, help: string, boundaries?: number[] | undefined): Histogram; | ||
createTrace(parentId?: string): Trace; | ||
createTimer(): Timer; | ||
} |
@@ -8,2 +8,3 @@ "use strict"; | ||
const tools_1 = require("./tools"); | ||
const base_1 = require("./base"); | ||
class PluginMetrics { | ||
@@ -18,7 +19,7 @@ metrics; | ||
} | ||
createCounter(name, description) { | ||
createCounter(name, description, help) { | ||
if (!this.metrics.isReady) { | ||
throw new errorMessages_1.BSBError("Metrics not ready!"); | ||
} | ||
this.metrics.metricsBus.emit("createCounter", this.pluginName, name, description); | ||
this.metrics.metricsBus.emit("createCounter", this.pluginName, name, description, help); | ||
return { | ||
@@ -30,7 +31,7 @@ inc: (value, labels) => { | ||
} | ||
createGauge(name, description) { | ||
createGauge(name, description, help) { | ||
if (!this.metrics.isReady) { | ||
throw new errorMessages_1.BSBError("Metrics not ready!"); | ||
} | ||
this.metrics.metricsBus.emit("createGauge", this.pluginName, name, description); | ||
this.metrics.metricsBus.emit("createGauge", this.pluginName, name, description, help); | ||
return { | ||
@@ -48,7 +49,7 @@ set: (value, labels) => { | ||
} | ||
createHistogram(name, description, boundaries) { | ||
createHistogram(name, description, help, boundaries) { | ||
if (!this.metrics.isReady) { | ||
throw new errorMessages_1.BSBError("Metrics not ready!"); | ||
} | ||
this.metrics.metricsBus.emit("createHistogram", this.pluginName, name, description, boundaries); | ||
this.metrics.metricsBus.emit("createHistogram", this.pluginName, name, description, help, boundaries); | ||
return { | ||
@@ -93,4 +94,16 @@ record: (value, labels) => { | ||
} | ||
createTimer() { | ||
if (!this.metrics.isReady) { | ||
throw new errorMessages_1.BSBError("Metrics not ready!"); | ||
} | ||
const start = process.hrtime(); | ||
return { | ||
stop: () => { | ||
const diff = process.hrtime(start); | ||
return (diff[0] * base_1.NS_PER_SEC + diff[1]) * base_1.MS_PER_NS; | ||
} | ||
}; | ||
} | ||
} | ||
exports.PluginMetrics = PluginMetrics; | ||
//# sourceMappingURL=PluginMetrics.js.map |
import { BSBError } from "../base"; | ||
export interface IPluginMetrics { | ||
createCounter(name: string, description?: string): Counter; | ||
createGauge(name: string, description?: string): Gauge; | ||
createHistogram(name: string, description?: string, boundaries?: number[]): Histogram; | ||
createCounter(name: string, description: string, help: string): Counter; | ||
createGauge(name: string, description: string, help: string): Gauge; | ||
createHistogram(name: string, description: string, help: string, boundaries?: number[]): Histogram; | ||
createTrace(parentId?: string): Trace; | ||
createTimer(): Timer; | ||
} | ||
export interface Timer { | ||
stop(): number; | ||
} | ||
export interface Trace { | ||
@@ -9,0 +13,0 @@ id: Readonly<string>; |
import { BSBPluginConfig, BSBService, BSBServiceConstructor } from "../../base"; | ||
import { z } from "zod"; | ||
import { BSBServiceClientDefinition } from "../../base"; | ||
export declare const secSchema: z.ZodObject<{ | ||
@@ -40,2 +41,3 @@ testa: z.ZodNumber; | ||
export declare class Plugin extends BSBService<Config, Events> { | ||
static PLUGIN_CLIENT: BSBServiceClientDefinition; | ||
initBeforePlugins?: string[] | undefined; | ||
@@ -42,0 +44,0 @@ initAfterPlugins?: string[] | undefined; |
@@ -30,2 +30,5 @@ "use strict"; | ||
class Plugin extends base_1.BSBService { | ||
static PLUGIN_CLIENT = { | ||
name: "service-default0", | ||
}; | ||
initBeforePlugins; | ||
@@ -32,0 +35,0 @@ initAfterPlugins; |
import { BSBService, BSBPluginEvents } from "../../index"; | ||
import { BSBServiceClientDefinition } from "../../base"; | ||
export interface Events extends BSBPluginEvents { | ||
@@ -19,2 +20,3 @@ emitEvents: { | ||
export declare class Plugin extends BSBService<null, Events> { | ||
static PLUGIN_CLIENT: BSBServiceClientDefinition; | ||
initBeforePlugins?: string[] | undefined; | ||
@@ -21,0 +23,0 @@ initAfterPlugins?: string[] | undefined; |
@@ -6,2 +6,5 @@ "use strict"; | ||
class Plugin extends index_1.BSBService { | ||
static PLUGIN_CLIENT = { | ||
name: "service-default1", | ||
}; | ||
initBeforePlugins; | ||
@@ -8,0 +11,0 @@ initAfterPlugins; |
@@ -7,3 +7,3 @@ "use strict"; | ||
const index_1 = require("../plugins/events-default/index"); | ||
const serviceBase_1 = require("./serviceBase"); | ||
const base_2 = require("../base/base"); | ||
class SBEvents { | ||
@@ -84,4 +84,4 @@ events = []; | ||
for (const event of Object.keys(interfaces_1.EventsEventTypesBase)) { | ||
this.metricCounters[event] = this.metrics.createCounter(event); | ||
this.metricGauges[event] = this.metrics.createGauge(event); | ||
this.metricCounters[event] = this.metrics.createCounter(event, 'BSB Internal Events ' + event, 'Internal metrics for BSB events'); | ||
this.metricGauges[event] = this.metrics.createGauge(event, 'BSB Internal Events ' + event, 'Internal metrics for BSB events'); | ||
} | ||
@@ -225,3 +225,3 @@ const plugins = await sbConfig.getEventsPlugins(); | ||
const diff = process.hrtime(start); | ||
const time = (diff[0] * serviceBase_1.NS_PER_SEC + diff[1]) * serviceBase_1.MS_PER_NS; | ||
const time = (diff[0] * base_2.NS_PER_SEC + diff[1]) * base_2.MS_PER_NS; | ||
this.log.debug("on-broadcast-{eventsPluginName}-{pluginName}-{event}:{time}", { | ||
@@ -265,3 +265,3 @@ eventsPluginName, | ||
const diff = process.hrtime(start); | ||
const time = (diff[0] * serviceBase_1.NS_PER_SEC + diff[1]) * serviceBase_1.MS_PER_NS; | ||
const time = (diff[0] * base_2.NS_PER_SEC + diff[1]) * base_2.MS_PER_NS; | ||
this.log.debug("on-event-{eventsPluginName}-{pluginName}-{event}:{time}", { | ||
@@ -319,3 +319,3 @@ eventsPluginName, | ||
const diff = process.hrtime(start); | ||
const time = (diff[0] * serviceBase_1.NS_PER_SEC + diff[1]) * serviceBase_1.MS_PER_NS; | ||
const time = (diff[0] * base_2.NS_PER_SEC + diff[1]) * base_2.MS_PER_NS; | ||
this.log.debug("on-returnableevent-{eventsPluginName}-{pluginName}-{event}:{time}", { | ||
@@ -357,3 +357,3 @@ eventsPluginName, | ||
const diff = process.hrtime(start); | ||
const time = (diff[0] * serviceBase_1.NS_PER_SEC + diff[1]) * serviceBase_1.MS_PER_NS; | ||
const time = (diff[0] * base_2.NS_PER_SEC + diff[1]) * base_2.MS_PER_NS; | ||
this.log.debug("emit-eventandreturn-{pluginName}-{event}:{time}", { | ||
@@ -384,3 +384,3 @@ pluginName, | ||
const diff = process.hrtime(start); | ||
const time = (diff[0] * serviceBase_1.NS_PER_SEC + diff[1]) * serviceBase_1.MS_PER_NS; | ||
const time = (diff[0] * base_2.NS_PER_SEC + diff[1]) * base_2.MS_PER_NS; | ||
this.log.debug("emit-eventandreturn-{pluginName}-{event}:{time}", { | ||
@@ -410,3 +410,3 @@ pluginName, | ||
const diff = process.hrtime(start); | ||
const time = (diff[0] * serviceBase_1.NS_PER_SEC + diff[1]) * serviceBase_1.MS_PER_NS; | ||
const time = (diff[0] * base_2.NS_PER_SEC + diff[1]) * base_2.MS_PER_NS; | ||
this.log.debug("receivestream-{eventsPluginName}-{pluginName}-{event}:{time}", { | ||
@@ -443,3 +443,3 @@ eventsPluginName, | ||
const diff = process.hrtime(start); | ||
const time = (diff[0] * serviceBase_1.NS_PER_SEC + diff[1]) * serviceBase_1.MS_PER_NS; | ||
const time = (diff[0] * base_2.NS_PER_SEC + diff[1]) * base_2.MS_PER_NS; | ||
this.log.debug("sendstream-{pluginName}-{event}:{time}", { | ||
@@ -446,0 +446,0 @@ pluginName, |
@@ -25,15 +25,15 @@ "use strict"; | ||
this.log = new base_1.PluginLogger(this.mode, metricsPluginName, sbLogging); | ||
this.metricsBus.on("createCounter", async (pluginName, name, description) => { | ||
this.metricsBus.on("createCounter", async (pluginName, name, description, help) => { | ||
for (const plugin of this.metricsPlugins) { | ||
await (0, base_1.SmartFunctionCallAsync)(plugin, plugin.createCounter, pluginName, name, description); | ||
await (0, base_1.SmartFunctionCallAsync)(plugin, plugin.createCounter, pluginName, name, description, help); | ||
} | ||
}); | ||
this.metricsBus.on("createGauge", async (pluginName, name, description) => { | ||
this.metricsBus.on("createGauge", async (pluginName, name, description, help) => { | ||
for (const plugin of this.metricsPlugins) { | ||
await (0, base_1.SmartFunctionCallAsync)(plugin, plugin.createGauge, pluginName, name, description); | ||
await (0, base_1.SmartFunctionCallAsync)(plugin, plugin.createGauge, pluginName, name, description, help); | ||
} | ||
}); | ||
this.metricsBus.on("createHistogram", async (pluginName, name, description, boundaries) => { | ||
this.metricsBus.on("createHistogram", async (pluginName, name, description, help, boundaries) => { | ||
for (const plugin of this.metricsPlugins) { | ||
await (0, base_1.SmartFunctionCallAsync)(plugin, plugin.createHistogram, pluginName, name, description, boundaries); | ||
await (0, base_1.SmartFunctionCallAsync)(plugin, plugin.createHistogram, pluginName, name, description, help, boundaries); | ||
} | ||
@@ -40,0 +40,0 @@ }); |
@@ -20,4 +20,2 @@ import { BSBConfig, BSBEvents, BSBLogging, BSBMetrics, BSBService } from "../base"; | ||
export type BootStatKeys = (typeof BOOT_STAT_KEYS)[keyof typeof BOOT_STAT_KEYS]; | ||
export declare const NS_PER_SEC = 1000000000; | ||
export declare const MS_PER_NS = 0.000001; | ||
export declare class ServiceBase { | ||
@@ -24,0 +22,0 @@ private readonly mode; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ServiceBase = exports.MS_PER_NS = exports.NS_PER_SEC = exports.BOOT_STAT_KEYS = void 0; | ||
exports.ServiceBase = exports.BOOT_STAT_KEYS = void 0; | ||
const uuid_1 = require("uuid"); | ||
@@ -24,4 +24,2 @@ const node_os_1 = require("node:os"); | ||
}; | ||
exports.NS_PER_SEC = 1e9; | ||
exports.MS_PER_NS = 1e-6; | ||
const TIMEKEEPLOG = "[TIMER] {timerName} took ({nsTime}ns) ({msTime}ms)"; | ||
@@ -61,5 +59,5 @@ class ServiceBase { | ||
const diff = process.hrtime((this._keeps[stepName] || undefined)); | ||
this._keeps[stepName] = (diff[0] * exports.NS_PER_SEC + diff[1]) * exports.MS_PER_NS; | ||
this._keeps[stepName] = (diff[0] * base_1.NS_PER_SEC + diff[1]) * base_1.MS_PER_NS; | ||
const logMeta = { | ||
nsTime: diff[0] * exports.NS_PER_SEC + diff[1], | ||
nsTime: diff[0] * base_1.NS_PER_SEC + diff[1], | ||
msTime: this._keeps[stepName], | ||
@@ -66,0 +64,0 @@ timerName: stepName, |
@@ -34,3 +34,3 @@ { | ||
"main": "lib/index.js", | ||
"version": "8.5.68", | ||
"version": "8.5.70", | ||
"devDependencies": { | ||
@@ -37,0 +37,0 @@ "@types/assert": "^1.5.10", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
519188
6753