@theotherwillembotha/node-red-plugincore 0.0.55 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +616 -217
- package/build/GenerateNodes.js +3 -6
- package/build/Nodes.html +3 -1502
- package/build/Nodes.js +5 -15
- package/build/Plugins.html +227 -0
- package/build/Plugins.js +18 -9
- package/build/core/NodeConstructor.d.ts +10 -16
- package/build/core/NodeConstructor.d.ts.map +1 -1
- package/build/core/NodeConstructor.js +112 -156
- package/build/core/NodeGenerator.d.ts.map +1 -1
- package/build/core/NodeGenerator.js +79 -29
- package/build/core/NodeManagerRuntime.d.ts +44 -0
- package/build/core/NodeManagerRuntime.d.ts.map +1 -0
- package/build/core/NodeManagerRuntime.js +140 -0
- package/build/core/Utils.d.ts.map +1 -1
- package/build/core/logger/service/LoggerService.d.ts +6 -5
- package/build/core/logger/service/LoggerService.d.ts.map +1 -1
- package/build/core/logger/service/LoggerService.js +51 -20
- package/build/core/logger/template/LoggerTemplate.d.ts.map +1 -1
- package/build/core/metrics/MetricsDecorator.d.ts +1 -2
- package/build/core/metrics/MetricsDecorator.d.ts.map +1 -1
- package/build/core/metrics/MetricsDecorator.js +89 -116
- package/build/core/metrics/node/CounterMetricConfigNode.d.ts.map +1 -1
- package/build/core/metrics/node/CounterMetricConfigNode.js +4 -5
- package/build/core/metrics/node/GaugeMetricConfigNode.d.ts.map +1 -1
- package/build/core/metrics/node/GaugeMetricConfigNode.js +5 -6
- package/build/core/metrics/node/MetricsConfigNode.d.ts +19 -9
- package/build/core/metrics/node/MetricsConfigNode.d.ts.map +1 -1
- package/build/core/metrics/node/MetricsConfigNode.js +14 -45
- package/build/core/metrics/node/TimerMetricConfigNode.d.ts.map +1 -1
- package/build/core/metrics/node/TimerMetricConfigNode.js +11 -17
- package/build/core/metrics/service/MetricsService.d.ts +110 -114
- package/build/core/metrics/service/MetricsService.d.ts.map +1 -1
- package/build/core/metrics/service/MetricsService.js +122 -339
- package/build/core/metrics/template/CounterMetricTemplate.d.ts.map +1 -1
- package/build/core/metrics/template/GaugeMetricTemplate.d.ts.map +1 -1
- package/build/core/metrics/template/MetricsTemplate.d.ts.map +1 -1
- package/build/core/metrics/template/MetricsTemplate.js +1 -2
- package/build/core/metrics/template/TimerMetricTemplate.d.ts.map +1 -1
- package/build/core/other/node/DelegatedConfigReferenceNode.d.ts +1 -1
- package/build/core/other/node/DelegatedConfigReferenceNode.d.ts.map +1 -1
- package/build/core/other/node/DelegatedConfigReferenceNode.js +1 -1
- package/build/core/other/service/InputService.d.ts.map +1 -1
- package/build/core/other/service/SettingsService.d.ts +1 -2
- package/build/core/other/service/SettingsService.d.ts.map +1 -1
- package/build/core/other/service/SettingsService.js +19 -5
- package/build/core/other/template/BasicTemplate.d.ts.map +1 -1
- package/build/core/other/template/SettingsTemplate.d.ts.map +1 -1
- package/build/core/state/node/InternalStateConfigNode.d.ts +16 -0
- package/build/core/state/node/InternalStateConfigNode.d.ts.map +1 -0
- package/build/core/state/node/InternalStateConfigNode.js +89 -0
- package/build/core/state/node/StateConfigNode.d.ts +24 -0
- package/build/core/state/node/StateConfigNode.d.ts.map +1 -0
- package/build/core/state/node/StateConfigNode.js +22 -0
- package/build/core/state/service/StateService.d.ts +34 -0
- package/build/core/state/service/StateService.d.ts.map +1 -0
- package/build/core/state/service/StateService.js +201 -0
- package/build/core/state/template/StateTemplate.d.ts +8 -0
- package/build/core/state/template/StateTemplate.d.ts.map +1 -0
- package/build/core/state/template/StateTemplate.js +11 -0
- package/build/core/tagging/ServiceDescriptionDecorator.d.ts +10 -0
- package/build/core/tagging/ServiceDescriptionDecorator.d.ts.map +1 -0
- package/build/core/tagging/ServiceDescriptionDecorator.js +10 -0
- package/build/core/tagging/service/NodeTypeService.d.ts +1 -2
- package/build/core/tagging/service/NodeTypeService.d.ts.map +1 -1
- package/build/core/tagging/service/NodeTypeService.js +19 -5
- package/build/core/ui/template/ScriptEditorTemplate.d.ts.map +1 -1
- package/build/core/ui/template/UIHelperTemplate.d.ts.map +1 -1
- package/build/core/webhook/WebhookDecorator.d.ts.map +1 -1
- package/build/core/webhook/WebhookDecorator.js +43 -6
- package/build/core/webhook/node/WebhookServerConfigNode.d.ts.map +1 -1
- package/build/core/webhook/service/ReverseProxyTypeService.d.ts +1 -0
- package/build/core/webhook/service/ReverseProxyTypeService.d.ts.map +1 -1
- package/build/core/webhook/service/WebhookServerService.d.ts +3 -4
- package/build/core/webhook/service/WebhookServerService.d.ts.map +1 -1
- package/build/core/webhook/service/WebhookServerService.js +48 -23
- package/build/core/webhook/template/WebhookTemplate.d.ts.map +1 -1
- package/build/index.d.ts +5 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +6 -2
- package/build/runtime/NodeManagerRuntime.js +140 -0
- package/documentation/CounterMetricConfigNode.png +0 -0
- package/documentation/GaugeMetricConfigNode.png +0 -0
- package/documentation/LoggerTemplate.png +0 -0
- package/documentation/MetricsTemplate.png +0 -0
- package/documentation/StateTemplate.png +0 -0
- package/documentation/TimerMetricConfigNode_histogram.png +0 -0
- package/documentation/TimerMetricConfigNode_summary.png +0 -0
- package/documentation/WebhookServerConfigNode.png +0 -0
- package/documentation/WebhookTemplate.png +0 -0
- package/package.json +5 -12
- package/src/GenerateNodes.ts +7 -11
- package/src/core/NodeConstructor.ts +134 -197
- package/src/core/NodeGenerator.ts +88 -34
- package/src/core/NodeManagerRuntime.ts +179 -0
- package/src/core/logger/service/LoggerService.ts +39 -26
- package/src/core/logger/template/LoggerTemplate.html +13 -8
- package/src/core/metrics/MetricsDecorator.ts +140 -168
- package/src/core/metrics/node/CounterMetricConfigNode.ts +20 -20
- package/src/core/metrics/node/GaugeMetricConfigNode.ts +24 -25
- package/src/core/metrics/node/MetricsConfigNode.ts +29 -48
- package/src/core/metrics/node/TimerMetricConfigNode.html +2 -2
- package/src/core/metrics/node/TimerMetricConfigNode.ts +50 -59
- package/src/core/metrics/service/MetricsService.ts +214 -489
- package/src/core/metrics/template/CounterMetricTemplate.html +0 -1
- package/src/core/metrics/template/GaugeMetricTemplate.html +1 -1
- package/src/core/metrics/template/MetricsTemplate.html +132 -13
- package/src/core/metrics/template/MetricsTemplate.ts +3 -4
- package/src/core/other/node/DelegatedConfigReferenceNode.ts +1 -1
- package/src/core/other/service/SettingsService.ts +6 -10
- package/src/core/other/template/BasicTemplate.html +5 -2
- package/src/core/state/node/InternalStateConfigNode.html +77 -0
- package/src/core/state/node/InternalStateConfigNode.ts +102 -0
- package/src/core/state/node/StateConfigNode.ts +29 -0
- package/src/core/state/service/StateService.ts +180 -0
- package/src/core/state/template/StateTemplate.html +244 -0
- package/src/core/state/template/StateTemplate.ts +17 -0
- package/src/core/tagging/ServiceDescriptionDecorator.ts +23 -0
- package/src/core/tagging/service/NodeTypeService.ts +6 -11
- package/src/core/ui/template/UIHelperTemplate.html +41 -26
- package/src/core/webhook/WebhookDecorator.ts +53 -10
- package/src/core/webhook/service/ReverseProxyTypeService.ts +1 -0
- package/src/core/webhook/service/WebhookServerService.ts +39 -28
- package/src/core/webhook/template/WebhookTemplate.html +29 -36
- package/src/index.ts +7 -2
- package/build/core/logger/node/ConsoleLoggerConfigNode.d.ts +0 -20
- package/build/core/logger/node/ConsoleLoggerConfigNode.d.ts.map +0 -1
- package/build/core/logger/node/ConsoleLoggerConfigNode.html +0 -90
- package/build/core/logger/node/ConsoleLoggerConfigNode.js +0 -62
- package/build/core/logger/node/RestLoggerConfigNode.d.ts +0 -40
- package/build/core/logger/node/RestLoggerConfigNode.d.ts.map +0 -1
- package/build/core/logger/node/RestLoggerConfigNode.html +0 -183
- package/build/core/logger/node/RestLoggerConfigNode.js +0 -128
- package/build/core/logger/template/LoggerTemplate.html +0 -331
- package/build/core/metrics/node/CounterMetricConfigNode.html +0 -48
- package/build/core/metrics/node/GaugeMetricConfigNode.html +0 -48
- package/build/core/metrics/node/MetricsConfigNode.html +0 -21
- package/build/core/metrics/node/TimerMetricConfigNode.html +0 -190
- package/build/core/metrics/template/CounterMetricTemplate.html +0 -40
- package/build/core/metrics/template/GaugeMetricTemplate.html +0 -39
- package/build/core/metrics/template/MetricsTemplate.html +0 -54
- package/build/core/metrics/template/TimerMetricTemplate.html +0 -39
- package/build/core/other/node/DelegatedConfigReferenceNode.html +0 -1
- package/build/core/other/template/BasicTemplate.html +0 -76
- package/build/core/other/template/SettingsTemplate.html +0 -128
- package/build/core/ui/template/ScriptEditorTemplate.html +0 -50
- package/build/core/ui/template/UIHelperTemplate.html +0 -229
- package/build/core/webhook/node/WebhookServerConfigNode.html +0 -61
- package/build/core/webhook/template/WebhookTemplate.html +0 -442
- package/documentation/ConsoleLoggerConfigNode.png +0 -0
- package/documentation/MetricsConfigNode.png +0 -0
- package/documentation/RestLoggerConfigNode.png +0 -0
- package/documentation/TimerMetricConfigNode.png +0 -0
- package/documentation/WebhookNode.png +0 -0
- package/src/core/logger/node/ConsoleLoggerConfigNode.html +0 -90
- package/src/core/logger/node/ConsoleLoggerConfigNode.ts +0 -71
- package/src/core/logger/node/RestLoggerConfigNode.html +0 -183
- package/src/core/logger/node/RestLoggerConfigNode.ts +0 -170
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* NodeManagerRuntime.ts
|
|
4
|
+
*
|
|
5
|
+
* STANDALONE - zero imports from the rest of plugincore.
|
|
6
|
+
*
|
|
7
|
+
* This file is compiled and copied into every plugin's build output so that
|
|
8
|
+
* plugins are self-contained and do not require plugincore to be separately
|
|
9
|
+
* installed in the user's Node-RED environment.
|
|
10
|
+
*
|
|
11
|
+
* When multiple plugins are deployed, each ships its own copy of this file.
|
|
12
|
+
* The first plugin to load registers its NodeManager and nodes; subsequent
|
|
13
|
+
* copies operate independently on their own node types with no conflict.
|
|
14
|
+
*
|
|
15
|
+
* POST_CONSTRUCT_KEY is intentionally a plain string (not a Symbol) so that
|
|
16
|
+
* the decorators (from plugincore's NodeConstructor, loaded via the plugin's
|
|
17
|
+
* dependency on plugincore) and this runtime file (a separate module instance)
|
|
18
|
+
* resolve to the same property key on node instances.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.NodeManager = exports.POST_CONSTRUCT_KEY = exports.NODEMANAGER_API_VERSION = void 0;
|
|
22
|
+
exports.runPostConstructInitializers = runPostConstructInitializers;
|
|
23
|
+
// ─── API version ────────────────────────────────────────────────────────────
|
|
24
|
+
// Semver of the NodeManager API contract - independent of plugincore's package
|
|
25
|
+
// version. Bump when the contract changes; plugins can read this to warn users
|
|
26
|
+
// that they were built against a different NodeManager version.
|
|
27
|
+
exports.NODEMANAGER_API_VERSION = "1.0.0";
|
|
28
|
+
// ─── Shared key for post-construct initializer lists ────────────────────────
|
|
29
|
+
// Must be a plain string so it resolves identically across module instances.
|
|
30
|
+
exports.POST_CONSTRUCT_KEY = '__plugincore_postConstructInitializers__';
|
|
31
|
+
// ─── Post-construct initializer runner ───────────────────────────────────────
|
|
32
|
+
function runPostConstructInitializers(instance) {
|
|
33
|
+
const initializers = instance[exports.POST_CONSTRUCT_KEY];
|
|
34
|
+
if (!initializers || initializers.length === 0)
|
|
35
|
+
return;
|
|
36
|
+
const className = instance.constructor.name;
|
|
37
|
+
initializers.forEach((init, index) => {
|
|
38
|
+
try {
|
|
39
|
+
init(instance);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error(`Post-construct initialization failed:\n` +
|
|
43
|
+
` Class: ${className}\n` +
|
|
44
|
+
` Initializer: ${index + 1}/${initializers.length}\n` +
|
|
45
|
+
` Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
delete instance[exports.POST_CONSTRUCT_KEY];
|
|
50
|
+
}
|
|
51
|
+
// ─── NodeManager ─────────────────────────────────────────────────────────────
|
|
52
|
+
// RED is stored on `global` rather than as a static class field so that all
|
|
53
|
+
// module instances of NodeManagerRuntime (the local copy bundled into Nodes.js
|
|
54
|
+
// and the copy bundled via plugincore's NodeConstructor) share the same value.
|
|
55
|
+
// Without this, esbuild's two separate inline copies would have independent
|
|
56
|
+
// static fields and the one used by decorators would never see RED being set.
|
|
57
|
+
const _GLOBAL_RED_KEY = '__plugincore_NodeManager_RED__';
|
|
58
|
+
// ─── Global node-type registration guard ─────────────────────────────────────
|
|
59
|
+
// When multiple self-contained plugins are installed they each bundle plugincore
|
|
60
|
+
// inline and each try to call RED.nodes.registerType for the same shared
|
|
61
|
+
// infrastructure node types (ConsoleLoggerConfigNode, RestLoggerConfigNode, etc.).
|
|
62
|
+
// Node-RED rejects duplicate registrations with a warning and the second
|
|
63
|
+
// plugin's Nodes.js fails to load. This global set tracks which types have
|
|
64
|
+
// already been registered so subsequent plugins silently skip them.
|
|
65
|
+
const _GLOBAL_REGISTERED_NODES_KEY = '__plugincore_registered_nodes__';
|
|
66
|
+
function getRegisteredNodes() {
|
|
67
|
+
if (!global[_GLOBAL_REGISTERED_NODES_KEY]) {
|
|
68
|
+
global[_GLOBAL_REGISTERED_NODES_KEY] = new Set();
|
|
69
|
+
}
|
|
70
|
+
return global[_GLOBAL_REGISTERED_NODES_KEY];
|
|
71
|
+
}
|
|
72
|
+
class NodeManager {
|
|
73
|
+
constructor(RED) {
|
|
74
|
+
this.typeBacklog = [];
|
|
75
|
+
global[_GLOBAL_RED_KEY] = RED;
|
|
76
|
+
const nodeTypeServiceId = "@theotherwillembotha/nodetypeservice";
|
|
77
|
+
const nodeTypeServiceListener = (pluginID) => {
|
|
78
|
+
if (pluginID === nodeTypeServiceId) {
|
|
79
|
+
RED.events.off('plugin.instantiated', nodeTypeServiceListener);
|
|
80
|
+
this.nodeTypeService = RED.plugins.get(nodeTypeServiceId).instance;
|
|
81
|
+
for (const nodeType of this.typeBacklog) {
|
|
82
|
+
for (const tag of nodeType.getNodeDescriptor().tags()) {
|
|
83
|
+
this.nodeTypeService.registerNodeType(tag, nodeType);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
this.typeBacklog = [];
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
this.nodeTypeService = RED.plugins.get(nodeTypeServiceId)?.instance;
|
|
90
|
+
if (!this.nodeTypeService) {
|
|
91
|
+
RED.events.on('plugin.instantiated', nodeTypeServiceListener);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
static get RED() {
|
|
95
|
+
return global[_GLOBAL_RED_KEY];
|
|
96
|
+
}
|
|
97
|
+
registerNodeType(typeName, type) {
|
|
98
|
+
if (!type) {
|
|
99
|
+
console.error(`[NodeManager v${exports.NODEMANAGER_API_VERSION}] Type "${typeName}" is undefined. ` +
|
|
100
|
+
`Ensure it is exported and included in GenerateNodes.`);
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
const registeredNodes = getRegisteredNodes();
|
|
104
|
+
if (registeredNodes.has(typeName)) {
|
|
105
|
+
// Already registered by another plugin - skip to avoid Node-RED duplicate-registration error.
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
registeredNodes.add(typeName);
|
|
109
|
+
const nodeConstructor = function (config) {
|
|
110
|
+
try {
|
|
111
|
+
NodeManager.RED.nodes.createNode(this, config);
|
|
112
|
+
const node = new type(this, config);
|
|
113
|
+
runPostConstructInitializers(node);
|
|
114
|
+
if (node.onInit) {
|
|
115
|
+
node.onInit();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
console.error(`[NodeManager v${exports.NODEMANAGER_API_VERSION}] Failed to construct node "${typeName}":`, error);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
try {
|
|
123
|
+
NodeManager.RED.nodes.registerType(typeName, nodeConstructor, { settings: {} });
|
|
124
|
+
const nodeDescription = type.getNodeDescriptor();
|
|
125
|
+
if (this.nodeTypeService) {
|
|
126
|
+
for (const tag of nodeDescription.tags()) {
|
|
127
|
+
this.nodeTypeService.registerNodeType(tag, type);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
this.typeBacklog.push(type);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
console.error(`[NodeManager v${exports.NODEMANAGER_API_VERSION}] Failed to register node type "${typeName}":`, error);
|
|
136
|
+
}
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.NodeManager = NodeManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../src/core/Utils.ts"],"names":[],"mappings":"AAAA,cAAM,QAAQ;
|
|
1
|
+
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../src/core/Utils.ts"],"names":[],"mappings":"AAAA,cAAM,QAAQ;IACV,OAAc,UAAU,CAAC,MAAM,EAAC;QAAC,CAAC,GAAG,EAAC,MAAM,GAAE,GAAG,CAAA;KAAC,EAAE,QAAQ,EAAC,MAAM,EAAE,QAAQ,EAAC,GAAG,GAAE,GAAG,CAYrF;CACJ;AAED,OAAO,EACH,QAAQ,EACX,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseService,
|
|
1
|
+
import { BaseService, ConfigNodeConfig, ConfigNode } from "../../NodeConstructor";
|
|
2
2
|
import { NodeAPI, NodeAPISettingsWithData, Node } from "node-red";
|
|
3
3
|
import { LoggerTemplateConfig } from "../template/LoggerTemplate";
|
|
4
4
|
export declare enum Level {
|
|
@@ -26,9 +26,11 @@ export type TagMap = {
|
|
|
26
26
|
};
|
|
27
27
|
export declare abstract class Log {
|
|
28
28
|
private _config;
|
|
29
|
-
private
|
|
29
|
+
private _templateStr;
|
|
30
|
+
private _compiledTemplate;
|
|
30
31
|
private tags;
|
|
31
32
|
protected constructor(config: LoggerTemplateConfig);
|
|
33
|
+
private getTemplate;
|
|
32
34
|
protected config(): LoggerTemplateConfig;
|
|
33
35
|
log(payload: {
|
|
34
36
|
[key: string]: any;
|
|
@@ -57,7 +59,6 @@ export declare class LoggerService extends BaseService {
|
|
|
57
59
|
constructor();
|
|
58
60
|
init(red: NodeAPI<NodeAPISettingsWithData>): void | Promise<void>;
|
|
59
61
|
deinit(red: NodeAPI<NodeAPISettingsWithData>): void | Promise<void>;
|
|
60
|
-
static getServiceDescriptor(): ServiceDescriptor;
|
|
61
62
|
}
|
|
62
63
|
export type LoggerConfigNodeConfig = ConfigNodeConfig & BaseLoggerConfig & {};
|
|
63
64
|
export declare abstract class LoggerConfigNode<CNC extends LoggerConfigNodeConfig, LoggerType extends AbstractLogger<BaseLoggerConfig>> extends ConfigNode<CNC> {
|
|
@@ -66,8 +67,8 @@ export declare abstract class LoggerConfigNode<CNC extends LoggerConfigNodeConfi
|
|
|
66
67
|
registerTemplate(config: LoggerTemplateConfig): Log;
|
|
67
68
|
}
|
|
68
69
|
export declare class DoNothingAppender extends Log {
|
|
69
|
-
private static
|
|
70
|
-
static get():
|
|
70
|
+
private static _instance;
|
|
71
|
+
static get(): DoNothingAppender;
|
|
71
72
|
private constructor();
|
|
72
73
|
log(payload: {
|
|
73
74
|
[key: string]: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LoggerService.d.ts","sourceRoot":"","sources":["../../../../src/core/logger/service/LoggerService.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"LoggerService.d.ts","sourceRoot":"","sources":["../../../../src/core/logger/service/LoggerService.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
4
7
|
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var LoggerService_1;
|
|
5
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
13
|
exports.DoNothingAppender = exports.LoggerConfigNode = exports.LoggerService = exports.AbstractLogger = exports.Log = exports.ApiKeyMechanismType = exports.RestAuthType = exports.Level = void 0;
|
|
7
14
|
const NodeConstructor_1 = require("../../NodeConstructor");
|
|
8
|
-
const
|
|
15
|
+
const ServiceDescriptionDecorator_1 = require("../../tagging/ServiceDescriptionDecorator");
|
|
9
16
|
const LoggerTemplate_1 = require("../template/LoggerTemplate");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
// Build-time / optional runtime deps - lazy so they are never required at bundle load time.
|
|
18
|
+
function getHandlebars() { return require('handlebars'); }
|
|
19
|
+
function getNetwork() { return require('network'); }
|
|
20
|
+
let _helpersRegistered = false;
|
|
21
|
+
function ensureHelpersRegistered() {
|
|
22
|
+
if (_helpersRegistered)
|
|
23
|
+
return;
|
|
24
|
+
_helpersRegistered = true;
|
|
25
|
+
// helper for serializing json objects inside handlebars tags.
|
|
26
|
+
// you can then convert it like this: {{{json myobject}}}
|
|
27
|
+
getHandlebars().registerHelper('json', function (context) {
|
|
28
|
+
return JSON.stringify(context);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
16
31
|
var Level;
|
|
17
32
|
(function (Level) {
|
|
18
33
|
Level["DEBUG"] = "DEBUG";
|
|
@@ -34,8 +49,9 @@ var ApiKeyMechanismType;
|
|
|
34
49
|
})(ApiKeyMechanismType || (exports.ApiKeyMechanismType = ApiKeyMechanismType = {}));
|
|
35
50
|
class Log {
|
|
36
51
|
constructor(config) {
|
|
52
|
+
this._compiledTemplate = null;
|
|
37
53
|
this._config = config;
|
|
38
|
-
this.
|
|
54
|
+
this._templateStr = config.template;
|
|
39
55
|
this.tags = {
|
|
40
56
|
id: config.id,
|
|
41
57
|
node: config.name,
|
|
@@ -44,13 +60,20 @@ class Log {
|
|
|
44
60
|
instance: LoggerService.instanceID
|
|
45
61
|
};
|
|
46
62
|
}
|
|
63
|
+
getTemplate() {
|
|
64
|
+
if (!this._compiledTemplate) {
|
|
65
|
+
ensureHelpersRegistered();
|
|
66
|
+
this._compiledTemplate = getHandlebars().compile(this._templateStr);
|
|
67
|
+
}
|
|
68
|
+
return this._compiledTemplate;
|
|
69
|
+
}
|
|
47
70
|
config() {
|
|
48
71
|
return this._config;
|
|
49
72
|
}
|
|
50
73
|
log(payload) {
|
|
51
74
|
try {
|
|
52
75
|
// step 1. serialize the payload using the template engine.
|
|
53
|
-
let message = (payload instanceof String) ? payload : this.
|
|
76
|
+
let message = (payload instanceof String) ? payload : this.getTemplate()({ msg: payload });
|
|
54
77
|
// step 2. write to the log appender.
|
|
55
78
|
this.writeToLog(this.config().level, message, this.tags);
|
|
56
79
|
}
|
|
@@ -79,24 +102,30 @@ class AbstractLogger {
|
|
|
79
102
|
}
|
|
80
103
|
}
|
|
81
104
|
exports.AbstractLogger = AbstractLogger;
|
|
82
|
-
class LoggerService extends NodeConstructor_1.BaseService {
|
|
105
|
+
let LoggerService = class LoggerService extends NodeConstructor_1.BaseService {
|
|
106
|
+
static { LoggerService_1 = this; }
|
|
83
107
|
constructor() {
|
|
84
108
|
super("logger");
|
|
85
109
|
}
|
|
86
110
|
init(red) {
|
|
87
111
|
this.red = red;
|
|
88
112
|
return new Promise((resolve) => {
|
|
89
|
-
|
|
90
|
-
|
|
113
|
+
getNetwork().get_active_interface((_err, obj) => {
|
|
114
|
+
LoggerService_1.instanceID = obj.ip_address;
|
|
91
115
|
});
|
|
92
116
|
});
|
|
93
117
|
}
|
|
94
118
|
deinit(red) { }
|
|
95
|
-
|
|
96
|
-
return new NodeConstructor_1.ServiceDescriptor("@theotherwillembotha/loggerservice", "LoggerService", "services-plugin", "@theotherwillembotha/node-red-plugincore", LoggerService, [LoggerTemplate_1.LoggerTemplate]);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
119
|
+
};
|
|
99
120
|
exports.LoggerService = LoggerService;
|
|
121
|
+
exports.LoggerService = LoggerService = LoggerService_1 = __decorate([
|
|
122
|
+
(0, ServiceDescriptionDecorator_1.ServiceDescription)({
|
|
123
|
+
id: "@theotherwillembotha/loggerservice",
|
|
124
|
+
sourceFile: "@theotherwillembotha/node-red-plugincore",
|
|
125
|
+
dependencies: [LoggerTemplate_1.LoggerTemplate]
|
|
126
|
+
}),
|
|
127
|
+
__metadata("design:paramtypes", [])
|
|
128
|
+
], LoggerService);
|
|
100
129
|
class LoggerConfigNode extends NodeConstructor_1.ConfigNode {
|
|
101
130
|
constructor(node, config) {
|
|
102
131
|
super(node, config);
|
|
@@ -107,9 +136,11 @@ class LoggerConfigNode extends NodeConstructor_1.ConfigNode {
|
|
|
107
136
|
}
|
|
108
137
|
exports.LoggerConfigNode = LoggerConfigNode;
|
|
109
138
|
class DoNothingAppender extends Log {
|
|
110
|
-
static { this.
|
|
139
|
+
static { this._instance = null; }
|
|
111
140
|
static get() {
|
|
112
|
-
|
|
141
|
+
if (!DoNothingAppender._instance)
|
|
142
|
+
DoNothingAppender._instance = new DoNothingAppender();
|
|
143
|
+
return DoNothingAppender._instance;
|
|
113
144
|
}
|
|
114
145
|
constructor() {
|
|
115
146
|
super({ flow: "", id: "", level: "", name: "", template: "", type: "" });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LoggerTemplate.d.ts","sourceRoot":"","sources":["../../../../src/core/logger/template/LoggerTemplate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAGpF,MAAM,WAAW,wBAAyB,SAAQ,cAAc;IAC5D,UAAU,EAAC,OAAO,CAAC;IACnB,MAAM,EAAC,MAAM,CAAC;IACd,0BAA0B,EAAC,OAAO,CAAC;IACnC,mBAAmB,EAAC,MAAM,CAAC;CAC9B;AAED,MAAM,MAAM,oBAAoB,GAAG;IAC/B,EAAE,EAAC,MAAM,CAAC;IACV,IAAI,EAAC,MAAM,CAAC;IACZ,IAAI,EAAC,MAAM,CAAC;IACZ,IAAI,EAAC,MAAM,CAAC;IACZ,QAAQ,EAAC,MAAM,CAAC;IAChB,KAAK,EAAC,MAAM,CAAC;CAChB,CAAA;AAED,qBAAa,cAAe,SAAQ,QAAQ;IAGxC,MAAM,CAAC,qBAAqB,IAAI,kBAAkB;
|
|
1
|
+
{"version":3,"file":"LoggerTemplate.d.ts","sourceRoot":"","sources":["../../../../src/core/logger/template/LoggerTemplate.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAGpF,MAAM,WAAW,wBAAyB,SAAQ,cAAc;IAC5D,UAAU,EAAC,OAAO,CAAC;IACnB,MAAM,EAAC,MAAM,CAAC;IACd,0BAA0B,EAAC,OAAO,CAAC;IACnC,mBAAmB,EAAC,MAAM,CAAC;CAC9B;AAED,MAAM,MAAM,oBAAoB,GAAG;IAC/B,EAAE,EAAC,MAAM,CAAC;IACV,IAAI,EAAC,MAAM,CAAC;IACZ,IAAI,EAAC,MAAM,CAAC;IACZ,IAAI,EAAC,MAAM,CAAC;IACZ,QAAQ,EAAC,MAAM,CAAC;IAChB,KAAK,EAAC,MAAM,CAAC;CAChB,CAAA;AAED,qBAAa,cAAe,SAAQ,QAAQ;IAGxC,MAAM,CAAC,qBAAqB,IAAI,kBAAkB,CAOjD;CACJ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BucketType
|
|
1
|
+
import { BucketType } from "./service/MetricsService";
|
|
2
2
|
export declare enum MetricType {
|
|
3
3
|
Counter = "Counter",
|
|
4
4
|
Timer = "Timer",
|
|
@@ -32,7 +32,6 @@ type HistogramTimerMetricDecoratorConfig = TimerMetricDecoratorConfig & {
|
|
|
32
32
|
};
|
|
33
33
|
type DefaultHistogramTimerMetricDecoratorConfig = HistogramTimerMetricDecoratorConfig & {
|
|
34
34
|
buckettype: BucketType.default;
|
|
35
|
-
bucketconfig?: DefaultBucketConfig;
|
|
36
35
|
};
|
|
37
36
|
type MetricsConfig = CounterMetricDecoratorConfig | GaugeMetricDecoratorConfig | SummaryTimerMetricDecoratorConfig | DefaultHistogramTimerMetricDecoratorConfig;
|
|
38
37
|
export declare function Metrics(metricsConfig: MetricsConfig): Function;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetricsDecorator.d.ts","sourceRoot":"","sources":["../../../src/core/metrics/MetricsDecorator.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"MetricsDecorator.d.ts","sourceRoot":"","sources":["../../../src/core/metrics/MetricsDecorator.ts"],"names":[],"mappings":"AAEA,OAAO,EAML,UAAU,EAUX,MAAM,0BAA0B,CAAC;AAGlC,oBAAY,UAAU;IACpB,OAAO,YAAY;IACnB,KAAK,UAAY;IACjB,KAAK,UAAY;CAClB;AAED,oBAAY,mBAAmB;IAC3B,SAAS,cAAc;IACvB,OAAO,YAAc;CACxB;AAED,KAAK,yBAAyB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACvB,CAAA;AAED,KAAK,4BAA4B,GAAG,yBAAyB,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC,OAAO,CAAA;CAAE,CAAA;AAC5F,KAAK,0BAA0B,GAAK,yBAAyB,GAAG;IAAE,IAAI,EAAE,UAAU,CAAC,KAAK,CAAA;CAAE,CAAA;AAE1F,KAAK,0BAA0B,GAAG,yBAAyB,GAAG;IAC5D,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC;IACvB,SAAS,EAAE,mBAAmB,CAAC;CAChC,CAAA;AAED,KAAK,iCAAiC,GAAG,0BAA0B,GAAG;IACpE,SAAS,EAAE,mBAAmB,CAAC,OAAO,CAAC;CACxC,CAAA;AAED,KAAK,mCAAmC,GAAG,0BAA0B,GAAG;IACtE,SAAS,EAAE,mBAAmB,CAAC,SAAS,CAAC;IACzC,UAAU,EAAE,UAAU,CAAC;CACxB,CAAA;AAED,KAAK,0CAA0C,GAAG,mCAAmC,GAAG;IACtF,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC;CAChC,CAAA;AAED,KAAK,aAAa,GAChB,4BAA4B,GAC5B,0BAA0B,GAC1B,iCAAiC,GACjC,0CAA0C,CAAA;AAkF5C,wBAAgB,OAAO,CAAC,aAAa,EAAE,aAAa,GAAG,QAAQ,CAqD9D"}
|
|
@@ -15,146 +15,119 @@ var MetricCollectorType;
|
|
|
15
15
|
MetricCollectorType["histogram"] = "histogram";
|
|
16
16
|
MetricCollectorType["summary"] = "summary";
|
|
17
17
|
})(MetricCollectorType || (exports.MetricCollectorType = MetricCollectorType = {}));
|
|
18
|
+
function resolveMetric(node, metricsConfig, _metrics) {
|
|
19
|
+
const nde = {
|
|
20
|
+
id: node.id(),
|
|
21
|
+
name: node.name(),
|
|
22
|
+
flow: node.flow(),
|
|
23
|
+
type: node.type()
|
|
24
|
+
};
|
|
25
|
+
if (metricsConfig.type === MetricType.Counter) {
|
|
26
|
+
if (!_metrics.supports(MetricsService_1.MetricCapability.Counter)) {
|
|
27
|
+
console.warn(`[PluginCore] @Metrics Counter requested by node "${node.name()}" (${node.type()}) but the selected provider does not support Counter. Using DoNothing.`);
|
|
28
|
+
}
|
|
29
|
+
const counterConfig = {
|
|
30
|
+
metricname: metricsConfig.name,
|
|
31
|
+
metricdescription: metricsConfig.description,
|
|
32
|
+
node: nde
|
|
33
|
+
};
|
|
34
|
+
return _metrics.counter(counterConfig);
|
|
35
|
+
}
|
|
36
|
+
if (metricsConfig.type === MetricType.Gauge) {
|
|
37
|
+
if (!_metrics.supports(MetricsService_1.MetricCapability.Gauge)) {
|
|
38
|
+
console.warn(`[PluginCore] @Metrics Gauge requested by node "${node.name()}" (${node.type()}) but the selected provider does not support Gauge. Using DoNothing.`);
|
|
39
|
+
}
|
|
40
|
+
const gaugeConfig = {
|
|
41
|
+
metricname: metricsConfig.name,
|
|
42
|
+
metricdescription: metricsConfig.description,
|
|
43
|
+
node: nde
|
|
44
|
+
};
|
|
45
|
+
return _metrics.gauge(gaugeConfig);
|
|
46
|
+
}
|
|
47
|
+
if (metricsConfig.type === MetricType.Timer) {
|
|
48
|
+
if (metricsConfig.collector === MetricCollectorType.histogram) {
|
|
49
|
+
if (!_metrics.supports(MetricsService_1.MetricCapability.Histogram)) {
|
|
50
|
+
console.warn(`[PluginCore] @Metrics Histogram requested by node "${node.name()}" (${node.type()}) but the selected provider does not support Histogram. Using DoNothing.`);
|
|
51
|
+
}
|
|
52
|
+
if (metricsConfig.buckettype === MetricsService_1.BucketType.default) {
|
|
53
|
+
const histogramConfig = {
|
|
54
|
+
metricname: metricsConfig.name,
|
|
55
|
+
metricdescription: metricsConfig.description,
|
|
56
|
+
buckettype: metricsConfig.buckettype,
|
|
57
|
+
bucketconfig: {},
|
|
58
|
+
node: nde
|
|
59
|
+
};
|
|
60
|
+
return _metrics.histogram(histogramConfig);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (metricsConfig.collector === MetricCollectorType.summary) {
|
|
64
|
+
if (!_metrics.supports(MetricsService_1.MetricCapability.Summary)) {
|
|
65
|
+
console.warn(`[PluginCore] @Metrics Summary requested by node "${node.name()}" (${node.type()}) but the selected provider does not support Summary. Using DoNothing.`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
console.error("[PluginCore] @Metrics: no factory matched for config", metricsConfig);
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
function resolveContainer(metricsReference) {
|
|
73
|
+
if (!metricsReference)
|
|
74
|
+
return new MetricsService_1.DoNothingMetricsContainer();
|
|
75
|
+
const refNode = NodeConstructor_1.NodeManager.RED.nodes.getNode(metricsReference);
|
|
76
|
+
return refNode ? refNode.node().metrics() : new MetricsService_1.DoNothingMetricsContainer();
|
|
77
|
+
}
|
|
78
|
+
function dudForType(metricsConfig) {
|
|
79
|
+
if (metricsConfig.type === MetricType.Counter)
|
|
80
|
+
return new MetricsService_1.DoNothingCounterMetric();
|
|
81
|
+
if (metricsConfig.type === MetricType.Gauge)
|
|
82
|
+
return new MetricsService_1.DoNothingGaugeMetric();
|
|
83
|
+
if (metricsConfig.type === MetricType.Timer) {
|
|
84
|
+
if (metricsConfig.collector === MetricCollectorType.histogram)
|
|
85
|
+
return new MetricsService_1.DoNothingHistogramMetric();
|
|
86
|
+
if (metricsConfig.collector === MetricCollectorType.summary)
|
|
87
|
+
return new MetricsService_1.DoNothingSummaryMetric();
|
|
88
|
+
}
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
18
91
|
function Metrics(metricsConfig) {
|
|
19
92
|
return function (target, propertyKey) {
|
|
20
|
-
// if the type is a string, then its probably defined in the local (core) module.
|
|
21
93
|
if (typeof propertyKey === "string") {
|
|
22
94
|
const valueSymbol = Symbol(`_${String(propertyKey)}_value`);
|
|
23
95
|
Object.defineProperty(target, propertyKey, {
|
|
24
96
|
get: function () {
|
|
25
|
-
if (this[valueSymbol])
|
|
97
|
+
if (this[valueSymbol])
|
|
26
98
|
return this[valueSymbol];
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
let node = this;
|
|
30
|
-
let config = node.config();
|
|
99
|
+
const node = this;
|
|
100
|
+
const config = node.config();
|
|
31
101
|
if (config.metricsEnabled) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
type: node.type()
|
|
38
|
-
};
|
|
39
|
-
// counter metric
|
|
40
|
-
if (metricsConfig.type === MetricType.Counter) {
|
|
41
|
-
let counterConfig = {
|
|
42
|
-
metricname: metricsConfig.name,
|
|
43
|
-
metricdescription: metricsConfig.description,
|
|
44
|
-
node: nde
|
|
45
|
-
};
|
|
46
|
-
this[valueSymbol] = _metrics.counter(counterConfig);
|
|
47
|
-
return this[valueSymbol];
|
|
48
|
-
}
|
|
49
|
-
// gauge metric
|
|
50
|
-
if (metricsConfig.type === MetricType.Gauge) {
|
|
51
|
-
let gaugeConfig = {
|
|
52
|
-
metricname: metricsConfig.name,
|
|
53
|
-
metricdescription: metricsConfig.description,
|
|
54
|
-
node: nde
|
|
55
|
-
};
|
|
56
|
-
this[valueSymbol] = _metrics.gauge(gaugeConfig);
|
|
57
|
-
return this[valueSymbol];
|
|
58
|
-
}
|
|
59
|
-
// timer metric.
|
|
60
|
-
if (metricsConfig.type === MetricType.Timer) {
|
|
61
|
-
// handle it as a histogram collector.
|
|
62
|
-
if (metricsConfig.collector === MetricCollectorType.histogram) {
|
|
63
|
-
// handle it as the default bucket.
|
|
64
|
-
if (metricsConfig.buckettype === MetricsService_1.BucketType.default) {
|
|
65
|
-
let histogramConfig = {
|
|
66
|
-
metricname: metricsConfig.name,
|
|
67
|
-
metricdescription: metricsConfig.description,
|
|
68
|
-
buckettype: metricsConfig.buckettype,
|
|
69
|
-
bucketconfig: {},
|
|
70
|
-
node: nde
|
|
71
|
-
};
|
|
72
|
-
this[valueSymbol] = _metrics.histogram(histogramConfig);
|
|
73
|
-
return this[valueSymbol];
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
console.error("No Metric Factory type defined for ", metricsConfig);
|
|
78
|
-
return this[valueSymbol];
|
|
102
|
+
const _metrics = resolveContainer(config.metricsReference);
|
|
103
|
+
this[valueSymbol] = resolveMetric(node, metricsConfig, _metrics);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
this[valueSymbol] = dudForType(metricsConfig);
|
|
79
107
|
}
|
|
80
|
-
this[valueSymbol] =
|
|
81
|
-
(metricsConfig.type === MetricType.Counter) ? { inc() { }, reset() { } } :
|
|
82
|
-
(metricsConfig.type === MetricType.Gauge) ? { inc() { }, dec() { }, reset() { } } :
|
|
83
|
-
(metricsConfig.type === MetricType.Timer) ? { observe(val) { } }
|
|
84
|
-
: undefined;
|
|
85
108
|
return this[valueSymbol];
|
|
86
109
|
},
|
|
87
110
|
enumerable: true,
|
|
88
111
|
configurable: false
|
|
89
112
|
});
|
|
90
|
-
return;
|
|
91
113
|
}
|
|
92
114
|
else {
|
|
93
115
|
let property = propertyKey;
|
|
94
116
|
property.addInitializer(function () {
|
|
95
|
-
|
|
117
|
+
const node = this;
|
|
96
118
|
const valueSymbol = Symbol(`_${String(property.name)}_value`);
|
|
97
119
|
Object.defineProperty(node, property.name, {
|
|
98
120
|
get: function () {
|
|
99
|
-
if (this[valueSymbol])
|
|
121
|
+
if (this[valueSymbol])
|
|
100
122
|
return this[valueSymbol];
|
|
101
|
-
|
|
102
|
-
//console.log("injecting metric", valueSymbol);
|
|
103
|
-
let config = node.config();
|
|
123
|
+
const config = node.config();
|
|
104
124
|
if (config.metricsEnabled) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
type: node.type()
|
|
111
|
-
};
|
|
112
|
-
// counter metric
|
|
113
|
-
if (metricsConfig.type === MetricType.Counter) {
|
|
114
|
-
let counterConfig = {
|
|
115
|
-
metricname: metricsConfig.name,
|
|
116
|
-
metricdescription: metricsConfig.description,
|
|
117
|
-
node: nde
|
|
118
|
-
};
|
|
119
|
-
this[valueSymbol] = _metrics.counter(counterConfig);
|
|
120
|
-
return this[valueSymbol];
|
|
121
|
-
}
|
|
122
|
-
// gauge metric
|
|
123
|
-
if (metricsConfig.type === MetricType.Gauge) {
|
|
124
|
-
let gaugeConfig = {
|
|
125
|
-
metricname: metricsConfig.name,
|
|
126
|
-
metricdescription: metricsConfig.description,
|
|
127
|
-
node: nde
|
|
128
|
-
};
|
|
129
|
-
this[valueSymbol] = _metrics.gauge(gaugeConfig);
|
|
130
|
-
return this[valueSymbol];
|
|
131
|
-
}
|
|
132
|
-
// timer metric.
|
|
133
|
-
if (metricsConfig.type === MetricType.Timer) {
|
|
134
|
-
// handle it as a histogram collector.
|
|
135
|
-
if (metricsConfig.collector === MetricCollectorType.histogram) {
|
|
136
|
-
// handle it as the default bucket.
|
|
137
|
-
if (metricsConfig.buckettype === MetricsService_1.BucketType.default) {
|
|
138
|
-
let histogramConfig = {
|
|
139
|
-
metricname: metricsConfig.name,
|
|
140
|
-
metricdescription: metricsConfig.description,
|
|
141
|
-
buckettype: metricsConfig.buckettype,
|
|
142
|
-
bucketconfig: {},
|
|
143
|
-
node: nde
|
|
144
|
-
};
|
|
145
|
-
this[valueSymbol] = _metrics.histogram(histogramConfig);
|
|
146
|
-
return this[valueSymbol];
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
console.error("No Metric Factory type defined for ", metricsConfig);
|
|
151
|
-
return this[valueSymbol];
|
|
125
|
+
const _metrics = resolveContainer(config.metricsReference);
|
|
126
|
+
this[valueSymbol] = resolveMetric(node, metricsConfig, _metrics);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
this[valueSymbol] = dudForType(metricsConfig);
|
|
152
130
|
}
|
|
153
|
-
this[valueSymbol] =
|
|
154
|
-
(metricsConfig.type === MetricType.Counter) ? { inc() { }, reset() { } } :
|
|
155
|
-
(metricsConfig.type === MetricType.Gauge) ? { inc() { }, dec() { }, reset() { } } :
|
|
156
|
-
(metricsConfig.type === MetricType.Timer) ? { observe(val) { } }
|
|
157
|
-
: undefined;
|
|
158
131
|
return this[valueSymbol];
|
|
159
132
|
},
|
|
160
133
|
enumerable: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CounterMetricConfigNode.d.ts","sourceRoot":"","sources":["../../../../src/core/metrics/node/CounterMetricConfigNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"CounterMetricConfigNode.d.ts","sourceRoot":"","sources":["../../../../src/core/metrics/node/CounterMetricConfigNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAe,MAAM,uBAAuB,CAAA;AACjF,OAAO,EAAE,gBAAgB,EAAkB,gBAAgB,EAAE,aAAa,EAAE,mBAAmB,EAA4B,MAAM,2BAA2B,CAAA;AAM5J,UAAU,6BAA8B,SAAQ,gBAAgB,EAAE,mBAAmB,EAAE,gBAAgB;IACnG,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,OAAO,CAAA;CACjB;AAED,qBAYa,uBAAwB,SAAQ,UAAU,CAAC,6BAA6B,CAAC;IAClF,OAAO,CAAC,QAAQ,CAAmB;IACnC,OAAO,CAAC,QAAQ,CAAgB;IAEhC,YAAY,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,6BAA6B,EAsB5D;IAEM,OAAO,IAAI,gBAAgB,CAEjC;IAEM,OAAO,IAAI,aAAa,CAE9B;CACJ"}
|
|
@@ -13,15 +13,14 @@ exports.CounterMetricConfigNode = void 0;
|
|
|
13
13
|
const NodeConstructor_1 = require("../../NodeConstructor");
|
|
14
14
|
const MetricsService_1 = require("../service/MetricsService");
|
|
15
15
|
const NodeGenerator_1 = require("../../NodeGenerator");
|
|
16
|
-
const MetricsConfigNode_1 = require("./MetricsConfigNode");
|
|
17
16
|
const MetricsTemplate_1 = require("../template/MetricsTemplate");
|
|
18
17
|
const NodeDescriptionDecorator_1 = require("../../tagging/NodeDescriptionDecorator");
|
|
19
18
|
let CounterMetricConfigNode = class CounterMetricConfigNode extends NodeConstructor_1.ConfigNode {
|
|
20
19
|
constructor(node, config) {
|
|
21
20
|
super(node, config);
|
|
22
|
-
|
|
23
|
-
this._metrics =
|
|
24
|
-
|
|
21
|
+
const refNode = config.metricsEnabled && config.metricsReference ? NodeConstructor_1.NodeManager.RED.nodes.getNode(config.metricsReference) : null;
|
|
22
|
+
this._metrics = refNode ? refNode.node().metrics() : new MetricsService_1.DoNothingMetricsContainer();
|
|
23
|
+
const counterConfig = {
|
|
25
24
|
metricname: config.name,
|
|
26
25
|
metricdescription: config.description,
|
|
27
26
|
node: {
|
|
@@ -54,7 +53,7 @@ exports.CounterMetricConfigNode = CounterMetricConfigNode = __decorate([
|
|
|
54
53
|
templates: [
|
|
55
54
|
{ template: MetricsTemplate_1.MetricsTemplate, config: {} }
|
|
56
55
|
],
|
|
57
|
-
dependencies: [
|
|
56
|
+
dependencies: [MetricsService_1.MetricsService],
|
|
58
57
|
tags: ["MetricType"]
|
|
59
58
|
}),
|
|
60
59
|
__metadata("design:paramtypes", [Object, Object])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GaugeMetricConfigNode.d.ts","sourceRoot":"","sources":["../../../../src/core/metrics/node/GaugeMetricConfigNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"GaugeMetricConfigNode.d.ts","sourceRoot":"","sources":["../../../../src/core/metrics/node/GaugeMetricConfigNode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAe,MAAM,uBAAuB,CAAA;AACjF,OAAO,EAAE,gBAAgB,EAAkB,iBAAiB,EAAE,WAAW,EAA8C,MAAM,2BAA2B,CAAA;AAExJ,OAAO,EAAmB,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAGrF,UAAU,2BAA4B,SAAQ,gBAAgB,EAAE,iBAAiB,EAAE,qBAAqB;IACpG,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,OAAO,CAAA;CACjB;AAED,qBAYa,qBAAsB,SAAQ,UAAU,CAAC,2BAA2B,CAAC;IAC9E,OAAO,CAAC,QAAQ,CAAmB;IACnC,OAAO,CAAC,MAAM,CAAc;IAE5B,YAAY,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,2BAA2B,EAsB1D;IAEM,OAAO,IAAI,gBAAgB,CAEjC;IAEM,KAAK,IAAI,WAAW,CAE1B;CACJ"}
|