@sentio/sdk 1.40.5-rc.3 → 1.40.5-rc.5
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/lib/core/meter.d.ts +10 -2
- package/lib/core/meter.js +18 -7
- package/lib/core/meter.js.map +1 -1
- package/lib/core/meter.test.js.map +1 -1
- package/package.json +5 -5
- package/src/core/meter.ts +22 -9
package/lib/core/meter.d.ts
CHANGED
|
@@ -29,7 +29,11 @@ export declare class MetricState extends MapStateStorage<Metric> {
|
|
|
29
29
|
}
|
|
30
30
|
export declare class Counter extends Metric {
|
|
31
31
|
static register(name: string, option?: CounterOptions): Counter;
|
|
32
|
-
|
|
32
|
+
/**
|
|
33
|
+
* internal use only, to create a metric use {@link register} instead
|
|
34
|
+
*/
|
|
35
|
+
static _create(name: string, option?: MetricOptions): Counter;
|
|
36
|
+
private constructor();
|
|
33
37
|
add(ctx: BaseContext, value: Numberish, labels?: Labels): void;
|
|
34
38
|
sub(ctx: BaseContext, value: Numberish, labels?: Labels): void;
|
|
35
39
|
private record;
|
|
@@ -43,7 +47,11 @@ export declare class CounterBinding {
|
|
|
43
47
|
}
|
|
44
48
|
export declare class Gauge extends Metric {
|
|
45
49
|
static register(name: string, option?: MetricOptions): Gauge;
|
|
46
|
-
|
|
50
|
+
/**
|
|
51
|
+
* internal use only, to create a metric use {@link register} instead
|
|
52
|
+
*/
|
|
53
|
+
static _create(name: string, option?: MetricOptions): Gauge;
|
|
54
|
+
private constructor();
|
|
47
55
|
record(ctx: BaseContext, value: Numberish, labels?: Labels): void;
|
|
48
56
|
}
|
|
49
57
|
export declare class GaugeBinding {
|
package/lib/core/meter.js
CHANGED
|
@@ -6,8 +6,7 @@ const metadata_1 = require("./metadata");
|
|
|
6
6
|
const protos_1 = require("@sentio/protos");
|
|
7
7
|
const runtime_1 = require("@sentio/runtime");
|
|
8
8
|
function normalizeName(name) {
|
|
9
|
-
|
|
10
|
-
return name.slice(0, 100).replace(regex, '_');
|
|
9
|
+
return name.slice(0, 100).replace(/[^_\-a-zA-Z0-9]/g, '_');
|
|
11
10
|
}
|
|
12
11
|
exports.normalizeName = normalizeName;
|
|
13
12
|
function normalizeKey(name) {
|
|
@@ -50,7 +49,7 @@ exports.CounterOptions = CounterOptions;
|
|
|
50
49
|
class Metric extends metadata_1.NamedResultDescriptor {
|
|
51
50
|
config;
|
|
52
51
|
constructor(type, name, option) {
|
|
53
|
-
super(name);
|
|
52
|
+
super(normalizeKey(name));
|
|
54
53
|
this.config = protos_1.MetricConfig.fromPartial({ name: this.name, type: type, ...option });
|
|
55
54
|
const aggregationConfig = this.config.aggregationConfig;
|
|
56
55
|
if (aggregationConfig && aggregationConfig.intervalInMinutes.length) {
|
|
@@ -74,10 +73,10 @@ class MetricState extends runtime_1.MapStateStorage {
|
|
|
74
73
|
}
|
|
75
74
|
if (!metric) {
|
|
76
75
|
if (type === protos_1.MetricType.COUNTER) {
|
|
77
|
-
metric =
|
|
76
|
+
metric = Counter._create(name, option);
|
|
78
77
|
}
|
|
79
78
|
else {
|
|
80
|
-
metric =
|
|
79
|
+
metric = Gauge._create(name, option);
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
82
|
metricMap.set(name, metric);
|
|
@@ -89,6 +88,12 @@ class Counter extends Metric {
|
|
|
89
88
|
static register(name, option) {
|
|
90
89
|
return MetricState.INSTANCE.getOrRegisterMetric(protos_1.MetricType.COUNTER, name, option);
|
|
91
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* internal use only, to create a metric use {@link register} instead
|
|
93
|
+
*/
|
|
94
|
+
static _create(name, option) {
|
|
95
|
+
return new Counter(name, option);
|
|
96
|
+
}
|
|
92
97
|
constructor(name, option) {
|
|
93
98
|
super(protos_1.MetricType.COUNTER, name, option);
|
|
94
99
|
}
|
|
@@ -112,7 +117,7 @@ class CounterBinding {
|
|
|
112
117
|
ctx;
|
|
113
118
|
counter;
|
|
114
119
|
constructor(name, ctx) {
|
|
115
|
-
this.counter =
|
|
120
|
+
this.counter = Counter._create(name);
|
|
116
121
|
this.ctx = ctx;
|
|
117
122
|
}
|
|
118
123
|
add(value, labels = {}) {
|
|
@@ -127,6 +132,12 @@ class Gauge extends Metric {
|
|
|
127
132
|
static register(name, option) {
|
|
128
133
|
return MetricState.INSTANCE.getOrRegisterMetric(protos_1.MetricType.GAUGE, name, option);
|
|
129
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* internal use only, to create a metric use {@link register} instead
|
|
137
|
+
*/
|
|
138
|
+
static _create(name, option) {
|
|
139
|
+
return new Gauge(name, option);
|
|
140
|
+
}
|
|
130
141
|
constructor(name, option) {
|
|
131
142
|
super(protos_1.MetricType.GAUGE, name, option);
|
|
132
143
|
}
|
|
@@ -143,7 +154,7 @@ class GaugeBinding {
|
|
|
143
154
|
gauge;
|
|
144
155
|
ctx;
|
|
145
156
|
constructor(name, ctx) {
|
|
146
|
-
this.gauge =
|
|
157
|
+
this.gauge = Gauge._create(name);
|
|
147
158
|
this.ctx = ctx;
|
|
148
159
|
}
|
|
149
160
|
record(value, labels = {}) {
|
package/lib/core/meter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meter.js","sourceRoot":"","sources":["../../src/core/meter.ts"],"names":[],"mappings":";;;AACA,2CAAsD;AACtD,yCAA0D;AAC1D,2CAA6F;AAC7F,6CAAiD;AAEjD,SAAgB,aAAa,CAAC,IAAY;IACxC,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,eAAe,CAAC,CAAA;IACzC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;AAC/C,CAAC;AAHD,sCAGC;AAED,SAAgB,YAAY,CAAC,IAAY;IACvC,IAAI,IAAI,KAAK,QAAQ,EAAE;QACrB,OAAO,SAAS,CAAA;KACjB;IACD,OAAO,aAAa,CAAC,IAAI,CAAC,CAAA;AAC5B,CAAC;AAL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AY;QAClB,OAAO,IAAI,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IAC3C,CAAC;IAED,KAAK,CAAC,IAAY;QAChB,OAAO,IAAI,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IACzC,CAAC;CACF;AAdD,sBAcC","sourcesContent":["import { BaseContext } from './base-context'\nimport { Numberish, toMetricValue } from './numberish'\nimport { Labels, NamedResultDescriptor } from './metadata'\nimport { AggregationConfig, AggregationType, MetricConfig, MetricType } from '@sentio/protos'\nimport { MapStateStorage } from '@sentio/runtime'\n\nexport function normalizeName(name: string): string {\n const regex = new RegExp('![_a-zA-Z0-9]')\n return name.slice(0, 100).replace(regex, '_')\n}\n\nexport function normalizeKey(name: string): string {\n if (name === 'labels') {\n return 'labels_'\n }\n return normalizeName(name)\n}\n\nexport function normalizeValue(name: string): string {\n return name.slice(0, 100)\n}\n\nexport function normalizeLabels(labels: Labels): Labels {\n const normLabels: Labels = {}\n for (const key in labels) {\n normLabels[normalizeKey(key)] = normalizeValue(labels[key])\n }\n return normLabels\n}\n\nexport class MetricOptions {\n unit?: string\n description?: string\n sparse?: boolean\n persistentBetweenVersion?: boolean\n aggregationConfig?: Partial<AggregationConfig>\n}\n\nexport class CounterOptions {\n unit?: string\n description?: string\n sparse?: boolean\n}\n\n// enum MetricType {\n// Counter = 0,\n// Gauge = 1,\n// }\n\nexport class Metric extends NamedResultDescriptor {\n config: MetricConfig\n constructor(type: MetricType, name: string, option?: MetricOptions) {\n super(name)\n this.config = MetricConfig.fromPartial({ name: this.name, type: type, ...option })\n const aggregationConfig = this.config.aggregationConfig\n if (aggregationConfig && aggregationConfig.intervalInMinutes.length) {\n if (aggregationConfig.intervalInMinutes.length > 1) {\n console.error('current only support one intervalInMinutes, only first interval will be used for', name)\n }\n if (aggregationConfig.intervalInMinutes[0] > 0 && aggregationConfig.types.length === 0) {\n aggregationConfig.types = [AggregationType.SUM, AggregationType.COUNT]\n }\n }\n }\n}\n\nexport class MetricState extends MapStateStorage<Metric> {\n static INSTANCE = new MetricState()\n\n getOrRegisterMetric(type: MetricType, name: string, option?: CounterOptions | MetricOptions): Metric {\n const metricMap = this.getOrRegister()\n let metric = metricMap.get(name)\n if (metric && metric.config.type !== type) {\n throw Error(`redefine ${name} of metric type ${type} that is previously ${metric.config.type}`)\n }\n\n if (!metric) {\n if (type === MetricType.COUNTER) {\n metric = new Counter(name, option)\n } else {\n metric = new Gauge(name, option)\n }\n }\n metricMap.set(name, metric)\n return metric\n }\n}\n\nexport class Counter extends Metric {\n static register(name: string, option?: CounterOptions): Counter {\n return MetricState.INSTANCE.getOrRegisterMetric(MetricType.COUNTER, name, option) as Counter\n }\n\n constructor(name: string, option?: MetricOptions) {\n super(MetricType.COUNTER, name, option)\n }\n\n add(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n this.record(ctx, value, labels, true)\n }\n\n sub(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n this.record(ctx, value, labels, false)\n }\n\n private record(ctx: BaseContext, value: Numberish, labels: Labels, add: boolean) {\n ctx._res.counters.push({\n metadata: ctx.getMetaData(this.name, labels),\n metricValue: toMetricValue(value),\n add: add,\n runtimeInfo: undefined,\n })\n }\n}\n\nexport class CounterBinding {\n private readonly ctx: BaseContext\n private readonly counter: Counter\n\n constructor(name: string, ctx: BaseContext) {\n this.counter = new Counter(name)\n this.ctx = ctx\n }\n\n add(value: Numberish, labels: Labels = {}) {\n this.counter.add(this.ctx, value, labels)\n }\n\n sub(value: Numberish, labels: Labels = {}) {\n this.counter.sub(this.ctx, value, labels)\n }\n}\n\nexport class Gauge extends Metric {\n static register(name: string, option?: MetricOptions): Gauge {\n return MetricState.INSTANCE.getOrRegisterMetric(MetricType.GAUGE, name, option) as Gauge\n }\n\n constructor(name: string, option?: MetricOptions) {\n super(MetricType.GAUGE, name, option)\n }\n\n record(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n ctx._res.gauges.push({\n metadata: ctx.getMetaData(this.config.name, labels),\n metricValue: toMetricValue(value),\n runtimeInfo: undefined,\n })\n }\n}\n\nexport class GaugeBinding {\n private readonly gauge: Gauge\n private readonly ctx: BaseContext\n\n constructor(name: string, ctx: BaseContext) {\n this.gauge = new Gauge(name)\n this.ctx = ctx\n }\n\n record(value: Numberish, labels: Labels = {}) {\n this.gauge.record(this.ctx, value, labels)\n }\n}\n\nexport class Meter {\n private readonly ctx: BaseContext\n\n constructor(ctx: BaseContext) {\n this.ctx = ctx\n }\n\n Counter(name: string): CounterBinding {\n return new CounterBinding(name, this.ctx)\n }\n\n Gauge(name: string): GaugeBinding {\n return new GaugeBinding(name, this.ctx)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"meter.js","sourceRoot":"","sources":["../../src/core/meter.ts"],"names":[],"mappings":";;;AACA,2CAAsD;AACtD,yCAA0D;AAC1D,2CAA6F;AAC7F,6CAAiD;AAEjD,SAAgB,aAAa,CAAC,IAAY;IACxC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAA;AAC5D,CAAC;AAFD,sCAEC;AAED,SAAgB,YAAY,CAAC,IAAY;IACvC,IAAI,IAAI,KAAK,QAAQ,EAAE;QACrB,OAAO,SAAS,CAAA;KACjB;IACD,OAAO,aAAa,CAAC,IAAI,CAAC,CAAA;AAC5B,CAAC;AALD,oCAKC;AAED,SAAgB,cAAc,CAAC,IAAY;IACzC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AAC3B,CAAC;AAFD,wCAEC;AAED,SAAgB,eAAe,CAAC,MAAc;IAC5C,MAAM,UAAU,GAAW,EAAE,CAAA;IAC7B,KAAK,MAAM,GAAG,IAAI,MAAM,EAAE;QACxB,UAAU,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,C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IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IAC3C,CAAC;IAED,KAAK,CAAC,IAAY;QAChB,OAAO,IAAI,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IACzC,CAAC;CACF;AAdD,sBAcC","sourcesContent":["import { BaseContext } from './base-context'\nimport { Numberish, toMetricValue } from './numberish'\nimport { Labels, NamedResultDescriptor } from './metadata'\nimport { AggregationConfig, AggregationType, MetricConfig, MetricType } from '@sentio/protos'\nimport { MapStateStorage } from '@sentio/runtime'\n\nexport function normalizeName(name: string): string {\n return name.slice(0, 100).replace(/[^_\\-a-zA-Z0-9]/g, '_')\n}\n\nexport function normalizeKey(name: string): string {\n if (name === 'labels') {\n return 'labels_'\n }\n return normalizeName(name)\n}\n\nexport function normalizeValue(name: string): string {\n return name.slice(0, 100)\n}\n\nexport function normalizeLabels(labels: Labels): Labels {\n const normLabels: Labels = {}\n for (const key in labels) {\n normLabels[normalizeKey(key)] = normalizeValue(labels[key])\n }\n return normLabels\n}\n\nexport class MetricOptions {\n unit?: string\n description?: string\n sparse?: boolean\n persistentBetweenVersion?: boolean\n aggregationConfig?: Partial<AggregationConfig>\n}\n\nexport class CounterOptions {\n unit?: string\n description?: string\n sparse?: boolean\n}\n\n// enum MetricType {\n// Counter = 0,\n// Gauge = 1,\n// }\n\nexport class Metric extends NamedResultDescriptor {\n config: MetricConfig\n constructor(type: MetricType, name: string, option?: MetricOptions) {\n super(normalizeKey(name))\n this.config = MetricConfig.fromPartial({ name: this.name, type: type, ...option })\n const aggregationConfig = this.config.aggregationConfig\n if (aggregationConfig && aggregationConfig.intervalInMinutes.length) {\n if (aggregationConfig.intervalInMinutes.length > 1) {\n console.error('current only support one intervalInMinutes, only first interval will be used for', name)\n }\n if (aggregationConfig.intervalInMinutes[0] > 0 && aggregationConfig.types.length === 0) {\n aggregationConfig.types = [AggregationType.SUM, AggregationType.COUNT]\n }\n }\n }\n}\n\nexport class MetricState extends MapStateStorage<Metric> {\n static INSTANCE = new MetricState()\n\n getOrRegisterMetric(type: MetricType, name: string, option?: CounterOptions | MetricOptions): Metric {\n const metricMap = this.getOrRegister()\n let metric = metricMap.get(name)\n if (metric && metric.config.type !== type) {\n throw Error(`redefine ${name} of metric type ${type} that is previously ${metric.config.type}`)\n }\n\n if (!metric) {\n if (type === MetricType.COUNTER) {\n metric = Counter._create(name, option)\n } else {\n metric = Gauge._create(name, option)\n }\n }\n metricMap.set(name, metric)\n return metric\n }\n}\n\nexport class Counter extends Metric {\n static register(name: string, option?: CounterOptions): Counter {\n return MetricState.INSTANCE.getOrRegisterMetric(MetricType.COUNTER, name, option) as Counter\n }\n\n /**\n * internal use only, to create a metric use {@link register} instead\n */\n static _create(name: string, option?: MetricOptions): Counter {\n return new Counter(name, option)\n }\n\n private constructor(name: string, option?: MetricOptions) {\n super(MetricType.COUNTER, name, option)\n }\n\n add(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n this.record(ctx, value, labels, true)\n }\n\n sub(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n this.record(ctx, value, labels, false)\n }\n\n private record(ctx: BaseContext, value: Numberish, labels: Labels, add: boolean) {\n ctx._res.counters.push({\n metadata: ctx.getMetaData(this.name, labels),\n metricValue: toMetricValue(value),\n add: add,\n runtimeInfo: undefined,\n })\n }\n}\n\nexport class CounterBinding {\n private readonly ctx: BaseContext\n private readonly counter: Counter\n\n constructor(name: string, ctx: BaseContext) {\n this.counter = Counter._create(name)\n this.ctx = ctx\n }\n\n add(value: Numberish, labels: Labels = {}) {\n this.counter.add(this.ctx, value, labels)\n }\n\n sub(value: Numberish, labels: Labels = {}) {\n this.counter.sub(this.ctx, value, labels)\n }\n}\n\nexport class Gauge extends Metric {\n static register(name: string, option?: MetricOptions): Gauge {\n return MetricState.INSTANCE.getOrRegisterMetric(MetricType.GAUGE, name, option) as Gauge\n }\n\n /**\n * internal use only, to create a metric use {@link register} instead\n */\n static _create(name: string, option?: MetricOptions): Gauge {\n return new Gauge(name, option)\n }\n\n private constructor(name: string, option?: MetricOptions) {\n super(MetricType.GAUGE, name, option)\n }\n\n record(ctx: BaseContext, value: Numberish, labels: Labels = {}) {\n ctx._res.gauges.push({\n metadata: ctx.getMetaData(this.config.name, labels),\n metricValue: toMetricValue(value),\n runtimeInfo: undefined,\n })\n }\n}\n\nexport class GaugeBinding {\n private readonly gauge: Gauge\n private readonly ctx: BaseContext\n\n constructor(name: string, ctx: BaseContext) {\n this.gauge = Gauge._create(name)\n this.ctx = ctx\n }\n\n record(value: Numberish, labels: Labels = {}) {\n this.gauge.record(this.ctx, value, labels)\n }\n}\n\nexport class Meter {\n private readonly ctx: BaseContext\n\n constructor(ctx: BaseContext) {\n this.ctx = ctx\n }\n\n Counter(name: string): CounterBinding {\n return new CounterBinding(name, this.ctx)\n }\n\n Gauge(name: string): GaugeBinding {\n return new GaugeBinding(name, this.ctx)\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meter.test.js","sourceRoot":"","sources":["../../src/core/meter.test.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,mCAAwD;AAExD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,IAAI,CAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;QACrC,IAAA,aAAM,EAAC,IAAA,qBAAa,EAAC,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"meter.test.js","sourceRoot":"","sources":["../../src/core/meter.test.ts"],"names":[],"mappings":";;AAAA,+BAA6B;AAC7B,mCAAwD;AAExD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,IAAI,CAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;QACrC,IAAA,aAAM,EAAC,IAAA,qBAAa,EAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;QACtC,IAAA,aAAM,EAAC,IAAA,qBAAa,EAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAA;QAC1C,IAAA,aAAM,EAAC,IAAA,qBAAa,EAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAA;QAE9C,IAAA,aAAM,EAAC,IAAA,qBAAa,EAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAA;QAC9C,IAAA,aAAM,EAAC,IAAA,qBAAa,EAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAA;QAC9C,IAAA,aAAM,EAAC,IAAA,qBAAa,EAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAA;QAEtC,IAAA,aAAM,EAAC,IAAA,qBAAa,EAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAA;QAEhD,IAAA,aAAM,EAAC,IAAA,qBAAa,EAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAA;IACvD,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,cAAc,EAAE,KAAK,IAAI,EAAE;QAC9B,MAAM,MAAM,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAA;QAC9B,MAAM,OAAO,GAAG,IAAA,uBAAe,EAAC,MAAM,CAAC,CAAA;QAEvC,IAAA,aAAM,EAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { expect } from 'chai'\nimport { normalizeLabels, normalizeName } from './meter'\n\ndescribe('meter tests', () => {\n test('test normalization ', async () => {\n expect(normalizeName('abc')).eq('abc')\n expect(normalizeName('a-b-c')).eq('a-b-c')\n expect(normalizeName('_a-B-1.')).eq('_a-B-1_')\n\n expect(normalizeName('a/b\\\\c\\n')).eq('a_b_c_')\n expect(normalizeName('abc abc')).eq('abc_abc')\n expect(normalizeName('*&~')).eq('___')\n\n expect(normalizeName('vo total')).eq('vo_total')\n\n expect(normalizeName('x'.repeat(200)).length).eq(100)\n })\n\n test('test labels', async () => {\n const labels = { labels: '0' }\n const updated = normalizeLabels(labels)\n\n expect(updated['labels_']).eq('0')\n })\n})\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentio/sdk",
|
|
3
3
|
"license": "Apache-2.0",
|
|
4
|
-
"version": "1.40.5-rc.
|
|
4
|
+
"version": "1.40.5-rc.5",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"compile_target": "yarn tsc -b src/target-ethers-sentio/tsconfig.json",
|
|
7
7
|
"compile": "tsc -p . && cp src/utils/*.csv lib/utils && cp src/webpack.config.js lib",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@ethersproject/providers": "~5.7.0",
|
|
21
|
-
"@sentio/bigdecimal": "9.1.1-patch.
|
|
22
|
-
"@sentio/protos": "^1.40.5-rc.
|
|
23
|
-
"@sentio/runtime": "^1.40.5-rc.
|
|
21
|
+
"@sentio/bigdecimal": "^9.1.1-patch.2",
|
|
22
|
+
"@sentio/protos": "^1.40.5-rc.5",
|
|
23
|
+
"@sentio/runtime": "^1.40.5-rc.5",
|
|
24
24
|
"@typechain/ethers-v5": "^10.0.0",
|
|
25
25
|
"command-line-args": "^5.2.1",
|
|
26
26
|
"command-line-usage": "^6.1.3",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"typedoc": {
|
|
52
52
|
"entryPoint": "./src/index.ts"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "b89781d025a0f5487962943deb6f5c5b2de6f49a"
|
|
55
55
|
}
|
package/src/core/meter.ts
CHANGED
|
@@ -5,8 +5,7 @@ import { AggregationConfig, AggregationType, MetricConfig, MetricType } from '@s
|
|
|
5
5
|
import { MapStateStorage } from '@sentio/runtime'
|
|
6
6
|
|
|
7
7
|
export function normalizeName(name: string): string {
|
|
8
|
-
|
|
9
|
-
return name.slice(0, 100).replace(regex, '_')
|
|
8
|
+
return name.slice(0, 100).replace(/[^_\-a-zA-Z0-9]/g, '_')
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
export function normalizeKey(name: string): string {
|
|
@@ -50,7 +49,7 @@ export class CounterOptions {
|
|
|
50
49
|
export class Metric extends NamedResultDescriptor {
|
|
51
50
|
config: MetricConfig
|
|
52
51
|
constructor(type: MetricType, name: string, option?: MetricOptions) {
|
|
53
|
-
super(name)
|
|
52
|
+
super(normalizeKey(name))
|
|
54
53
|
this.config = MetricConfig.fromPartial({ name: this.name, type: type, ...option })
|
|
55
54
|
const aggregationConfig = this.config.aggregationConfig
|
|
56
55
|
if (aggregationConfig && aggregationConfig.intervalInMinutes.length) {
|
|
@@ -76,9 +75,9 @@ export class MetricState extends MapStateStorage<Metric> {
|
|
|
76
75
|
|
|
77
76
|
if (!metric) {
|
|
78
77
|
if (type === MetricType.COUNTER) {
|
|
79
|
-
metric =
|
|
78
|
+
metric = Counter._create(name, option)
|
|
80
79
|
} else {
|
|
81
|
-
metric =
|
|
80
|
+
metric = Gauge._create(name, option)
|
|
82
81
|
}
|
|
83
82
|
}
|
|
84
83
|
metricMap.set(name, metric)
|
|
@@ -91,7 +90,14 @@ export class Counter extends Metric {
|
|
|
91
90
|
return MetricState.INSTANCE.getOrRegisterMetric(MetricType.COUNTER, name, option) as Counter
|
|
92
91
|
}
|
|
93
92
|
|
|
94
|
-
|
|
93
|
+
/**
|
|
94
|
+
* internal use only, to create a metric use {@link register} instead
|
|
95
|
+
*/
|
|
96
|
+
static _create(name: string, option?: MetricOptions): Counter {
|
|
97
|
+
return new Counter(name, option)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private constructor(name: string, option?: MetricOptions) {
|
|
95
101
|
super(MetricType.COUNTER, name, option)
|
|
96
102
|
}
|
|
97
103
|
|
|
@@ -118,7 +124,7 @@ export class CounterBinding {
|
|
|
118
124
|
private readonly counter: Counter
|
|
119
125
|
|
|
120
126
|
constructor(name: string, ctx: BaseContext) {
|
|
121
|
-
this.counter =
|
|
127
|
+
this.counter = Counter._create(name)
|
|
122
128
|
this.ctx = ctx
|
|
123
129
|
}
|
|
124
130
|
|
|
@@ -136,7 +142,14 @@ export class Gauge extends Metric {
|
|
|
136
142
|
return MetricState.INSTANCE.getOrRegisterMetric(MetricType.GAUGE, name, option) as Gauge
|
|
137
143
|
}
|
|
138
144
|
|
|
139
|
-
|
|
145
|
+
/**
|
|
146
|
+
* internal use only, to create a metric use {@link register} instead
|
|
147
|
+
*/
|
|
148
|
+
static _create(name: string, option?: MetricOptions): Gauge {
|
|
149
|
+
return new Gauge(name, option)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private constructor(name: string, option?: MetricOptions) {
|
|
140
153
|
super(MetricType.GAUGE, name, option)
|
|
141
154
|
}
|
|
142
155
|
|
|
@@ -154,7 +167,7 @@ export class GaugeBinding {
|
|
|
154
167
|
private readonly ctx: BaseContext
|
|
155
168
|
|
|
156
169
|
constructor(name: string, ctx: BaseContext) {
|
|
157
|
-
this.gauge =
|
|
170
|
+
this.gauge = Gauge._create(name)
|
|
158
171
|
this.ctx = ctx
|
|
159
172
|
}
|
|
160
173
|
|