@twin.org/telemetry-service 0.9.1-next.1 → 0.9.1-next.3
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/dist/es/telemetryRoutes.js +76 -8
- package/dist/es/telemetryRoutes.js.map +1 -1
- package/dist/es/telemetryService.js +11 -0
- package/dist/es/telemetryService.js.map +1 -1
- package/dist/types/telemetryRoutes.d.ts +14 -4
- package/dist/types/telemetryService.d.ts +7 -0
- package/docs/changelog.md +28 -0
- package/docs/open-api/spec.json +116 -0
- package/docs/reference/classes/TelemetryService.md +32 -0
- package/docs/reference/functions/telemetryAddMetricValue.md +7 -1
- package/docs/reference/functions/telemetryCreateMetric.md +7 -1
- package/docs/reference/functions/telemetryGetMetricValue.md +31 -0
- package/docs/reference/index.md +1 -0
- package/package.json +2 -2
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { HttpContextIdKeys, HttpHeaderHelper, HttpUrlHelper } from "@twin.org/api-models";
|
|
4
|
+
import { ContextIdStore } from "@twin.org/context";
|
|
1
5
|
import { Coerce, ComponentFactory, Guards } from "@twin.org/core";
|
|
2
6
|
import { MetricType } from "@twin.org/telemetry-models";
|
|
3
7
|
import { HeaderTypes, HttpStatusCode } from "@twin.org/web";
|
|
@@ -27,7 +31,7 @@ export function generateRestRoutesTelemetry(baseRouteName, componentName) {
|
|
|
27
31
|
tag: tagsTelemetry[0].name,
|
|
28
32
|
method: "POST",
|
|
29
33
|
path: `${baseRouteName}/metric`,
|
|
30
|
-
handler: async (httpRequestContext, request) => telemetryCreateMetric(httpRequestContext, componentName, request),
|
|
34
|
+
handler: async (httpRequestContext, request) => telemetryCreateMetric(httpRequestContext, componentName, request, baseRouteName),
|
|
31
35
|
requestType: {
|
|
32
36
|
type: "ITelemetryCreateMetricRequest",
|
|
33
37
|
examples: [
|
|
@@ -144,7 +148,7 @@ export function generateRestRoutesTelemetry(baseRouteName, componentName) {
|
|
|
144
148
|
tag: tagsTelemetry[0].name,
|
|
145
149
|
method: "POST",
|
|
146
150
|
path: `${baseRouteName}/metric/:id/value`,
|
|
147
|
-
handler: async (httpRequestContext, request) => telemetryAddMetricValue(httpRequestContext, componentName, request),
|
|
151
|
+
handler: async (httpRequestContext, request) => telemetryAddMetricValue(httpRequestContext, componentName, request, baseRouteName),
|
|
148
152
|
requestType: {
|
|
149
153
|
type: "ITelemetryAddMetricValueRequest",
|
|
150
154
|
examples: [
|
|
@@ -265,6 +269,45 @@ export function generateRestRoutesTelemetry(baseRouteName, componentName) {
|
|
|
265
269
|
}
|
|
266
270
|
]
|
|
267
271
|
};
|
|
272
|
+
const getMetricValueRoute = {
|
|
273
|
+
operationId: "telemetryGetMetricValue",
|
|
274
|
+
summary: "Get a specific telemetry metric value",
|
|
275
|
+
tag: tagsTelemetry[0].name,
|
|
276
|
+
method: "GET",
|
|
277
|
+
path: `${baseRouteName}/metric/:id/value/:valueId`,
|
|
278
|
+
handler: async (httpRequestContext, request) => telemetryGetMetricValue(httpRequestContext, componentName, request),
|
|
279
|
+
requestType: {
|
|
280
|
+
type: "ITelemetryGetMetricValueRequest",
|
|
281
|
+
examples: [
|
|
282
|
+
{
|
|
283
|
+
id: "telemetryGetMetricValueRequestExample",
|
|
284
|
+
request: {
|
|
285
|
+
pathParams: {
|
|
286
|
+
id: "my-counter",
|
|
287
|
+
valueId: "aabbccdd11223445566"
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
]
|
|
292
|
+
},
|
|
293
|
+
responseType: [
|
|
294
|
+
{
|
|
295
|
+
type: "ITelemetryGetMetricValueResponse",
|
|
296
|
+
examples: [
|
|
297
|
+
{
|
|
298
|
+
id: "telemetryGetMetricValueResponseExample",
|
|
299
|
+
response: {
|
|
300
|
+
body: {
|
|
301
|
+
id: "aabbccdd11223445566",
|
|
302
|
+
ts: 1715252922273,
|
|
303
|
+
value: 10
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
}
|
|
309
|
+
]
|
|
310
|
+
};
|
|
268
311
|
const listMetricsValuesRoute = {
|
|
269
312
|
operationId: "telemetryValuesListEntries",
|
|
270
313
|
summary: "Get a list of the values for a telemetry metric",
|
|
@@ -326,6 +369,7 @@ export function generateRestRoutesTelemetry(baseRouteName, componentName) {
|
|
|
326
369
|
addMetricValueRoute,
|
|
327
370
|
removeMetricRoute,
|
|
328
371
|
listMetricsRoute,
|
|
372
|
+
getMetricValueRoute,
|
|
329
373
|
listMetricsValuesRoute
|
|
330
374
|
];
|
|
331
375
|
}
|
|
@@ -334,9 +378,10 @@ export function generateRestRoutesTelemetry(baseRouteName, componentName) {
|
|
|
334
378
|
* @param httpRequestContext The request context for the API.
|
|
335
379
|
* @param componentName The name of the component to use in the routes.
|
|
336
380
|
* @param request The request.
|
|
381
|
+
* @param baseRouteName The base route name for the API.
|
|
337
382
|
* @returns The response object with additional http response properties.
|
|
338
383
|
*/
|
|
339
|
-
export async function telemetryCreateMetric(httpRequestContext, componentName, request) {
|
|
384
|
+
export async function telemetryCreateMetric(httpRequestContext, componentName, request, baseRouteName) {
|
|
340
385
|
Guards.object(ROUTES_SOURCE, "request", request);
|
|
341
386
|
Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
342
387
|
const component = ComponentFactory.get(componentName);
|
|
@@ -347,11 +392,13 @@ export async function telemetryCreateMetric(httpRequestContext, componentName, r
|
|
|
347
392
|
type: request.body.type,
|
|
348
393
|
unit: request.body.unit
|
|
349
394
|
});
|
|
395
|
+
const contextIds = await ContextIdStore.getContextIds();
|
|
396
|
+
const publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];
|
|
397
|
+
const headers = {};
|
|
398
|
+
HttpHeaderHelper.buildId(headers, request.body.id, HttpUrlHelper.combineOriginPath(publicOrigin, `${baseRouteName}/:id`));
|
|
350
399
|
return {
|
|
351
400
|
statusCode: HttpStatusCode.created,
|
|
352
|
-
headers
|
|
353
|
-
[HeaderTypes.Location]: request.body.id
|
|
354
|
-
}
|
|
401
|
+
headers
|
|
355
402
|
};
|
|
356
403
|
}
|
|
357
404
|
/**
|
|
@@ -395,16 +442,21 @@ export async function telemetryUpdateMetric(httpRequestContext, componentName, r
|
|
|
395
442
|
* @param httpRequestContext The request context for the API.
|
|
396
443
|
* @param componentName The name of the component to use in the routes.
|
|
397
444
|
* @param request The request.
|
|
445
|
+
* @param baseRouteName The base route name for the API.
|
|
398
446
|
* @returns The response object with additional http response properties.
|
|
399
447
|
*/
|
|
400
|
-
export async function telemetryAddMetricValue(httpRequestContext, componentName, request) {
|
|
448
|
+
export async function telemetryAddMetricValue(httpRequestContext, componentName, request, baseRouteName) {
|
|
401
449
|
Guards.object(ROUTES_SOURCE, "request", request);
|
|
402
450
|
Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
403
451
|
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
404
452
|
Guards.object(ROUTES_SOURCE, "request.body", request.body);
|
|
405
453
|
const component = ComponentFactory.get(componentName);
|
|
406
454
|
const id = await component.addMetricValue(request.pathParams.id, request.body.value, request.body.customData);
|
|
407
|
-
|
|
455
|
+
const contextIds = await ContextIdStore.getContextIds();
|
|
456
|
+
const publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];
|
|
457
|
+
const headers = {};
|
|
458
|
+
HttpHeaderHelper.buildId(headers, id, HttpUrlHelper.combineOriginPath(publicOrigin, `${baseRouteName}/:id`));
|
|
459
|
+
return { statusCode: HttpStatusCode.created, headers };
|
|
408
460
|
}
|
|
409
461
|
/**
|
|
410
462
|
* Removes a telemetry metric.
|
|
@@ -439,6 +491,22 @@ export async function telemetryMetricList(httpRequestContext, componentName, req
|
|
|
439
491
|
body: itemsAndCursor
|
|
440
492
|
};
|
|
441
493
|
}
|
|
494
|
+
/**
|
|
495
|
+
* Gets a specific telemetry metric value.
|
|
496
|
+
* @param httpRequestContext The request context for the API.
|
|
497
|
+
* @param componentName The name of the component to use in the routes.
|
|
498
|
+
* @param request The request.
|
|
499
|
+
* @returns The response object with additional http response properties.
|
|
500
|
+
*/
|
|
501
|
+
export async function telemetryGetMetricValue(httpRequestContext, componentName, request) {
|
|
502
|
+
Guards.object(ROUTES_SOURCE, "request", request);
|
|
503
|
+
Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
504
|
+
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
505
|
+
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.valueId", request.pathParams.valueId);
|
|
506
|
+
const component = ComponentFactory.get(componentName);
|
|
507
|
+
const result = await component.getMetricValue(request.pathParams.id, request.pathParams.valueId);
|
|
508
|
+
return { body: result };
|
|
509
|
+
}
|
|
442
510
|
/**
|
|
443
511
|
* Get a list of the telemetry metric values.
|
|
444
512
|
* @param httpRequestContext The request context for the API.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetryRoutes.js","sourceRoot":"","sources":["../../src/telemetryRoutes.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAElE,OAAO,EACN,UAAU,EAYV,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAE5D;;GAEG;AACH,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAExC;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAW;IACpC;QACC,IAAI,EAAE,WAAW;QACjB,WAAW,EAAE,8DAA8D;KAC3E;CACD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CAC1C,aAAqB,EACrB,aAAqB;IAErB,MAAM,iBAAiB,GAAgE;QACtF,WAAW,EAAE,uBAAuB;QACpC,OAAO,EA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,KAAK,CAC3C,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAe,EACjD,OAAO,EAAE,KAAK,EAAE,MAAM,EACtB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CACpC,CAAC;IAEF,OAAO;QACN,IAAI,EAAE,cAAc;KACpB,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC7C,kBAAuC,EACvC,aAAqB,EACrB,OAAoC;IAEpC,MAAM,CAAC,MAAM,CAA8B,aAAa,aAAmB,OAAO,CAAC,CAAC;IACpF,MAAM,CAAC,MAAM,CACZ,aAAa,mBAEb,OAAO,CAAC,KAAK,CACb,CAAC;IACF,MAAM,CAAC,WAAW,CAAC,aAAa,2BAAiC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAExF,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAsB,aAAa,CAAC,CAAC;IAE3E,MAAM,cAAc,GAAG,MAAM,SAAS,CAAC,WAAW,CACjD,OAAO,EAAE,UAAU,CAAC,EAAE,EACtB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,EACxC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,EACtC,OAAO,EAAE,KAAK,EAAE,MAAM,EACtB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CACpC,CAAC;IAEF,OAAO;QACN,IAAI,EAAE,cAAc;KACpB,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tICreatedResponse,\n\tIHttpRequestContext,\n\tINoContentResponse,\n\tIRestRoute,\n\tITag\n} from \"@twin.org/api-models\";\nimport { Coerce, ComponentFactory, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tMetricType,\n\ttype ITelemetryAddMetricValueRequest,\n\ttype ITelemetryComponent,\n\ttype ITelemetryCreateMetricRequest,\n\ttype ITelemetryGetMetricRequest,\n\ttype ITelemetryGetMetricResponse,\n\ttype ITelemetryListRequest,\n\ttype ITelemetryListResponse,\n\ttype ITelemetryRemoveMetricRequest,\n\ttype ITelemetryUpdateMetricRequest,\n\ttype ITelemetryValuesListRequest,\n\ttype ITelemetryValuesListResponse\n} from \"@twin.org/telemetry-models\";\nimport { HeaderTypes, HttpStatusCode } from \"@twin.org/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"telemetryRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsTelemetry: ITag[] = [\n\t{\n\t\tname: \"Telemetry\",\n\t\tdescription: \"Endpoints which are modelled to access a telemetry contract.\"\n\t}\n];\n\n/**\n * The REST routes for telemetry.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @returns The generated routes.\n */\nexport function generateRestRoutesTelemetry(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst createMetricRoute: IRestRoute<ITelemetryCreateMetricRequest, ICreatedResponse> = {\n\t\toperationId: \"telemetryCreateMetric\",\n\t\tsummary: \"Create a telemetry metric\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/metric`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryCreateMetric(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryCreateMetricRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryCreateMetricRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tid: \"my-counter\",\n\t\t\t\t\t\t\tlabel: \"My Counter\",\n\t\t\t\t\t\t\tdescription: \"This is my counter\",\n\t\t\t\t\t\t\ttype: MetricType.Counter,\n\t\t\t\t\t\t\tunit: \"KG\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ICreatedResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"telemetryCreateMetricResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tstatusCode: HttpStatusCode.created,\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t[HeaderTypes.Location]: \"my-counter\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst getMetricRoute: IRestRoute<ITelemetryGetMetricRequest, ITelemetryGetMetricResponse> = {\n\t\toperationId: \"telemetryGetMetric\",\n\t\tsummary: \"Get a telemetry metric and it's most recent value\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/metric/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryGetMetric(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryGetMetricRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryGetMetricRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ITelemetryGetMetricResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"telemetryGetMetricResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tmetric: {\n\t\t\t\t\t\t\t\t\tid: \"my-counter\",\n\t\t\t\t\t\t\t\t\tlabel: \"My Counter\",\n\t\t\t\t\t\t\t\t\tdescription: \"This is my counter\",\n\t\t\t\t\t\t\t\t\ttype: MetricType.Counter,\n\t\t\t\t\t\t\t\t\tunit: \"KG\"\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t\t\tid: \"aabbccdd11223445566\",\n\t\t\t\t\t\t\t\t\tts: 1715252922273,\n\t\t\t\t\t\t\t\t\tvalue: 10\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst updateMetricRoute: IRestRoute<ITelemetryUpdateMetricRequest, INoContentResponse> = {\n\t\toperationId: \"telemetryUpdateMetric\",\n\t\tsummary: \"Update a telemetry metric\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"PUT\",\n\t\tpath: `${baseRouteName}/metric/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryUpdateMetric(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryUpdateMetricRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryUpdateMetricRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tlabel: \"My New Label\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst addMetricValueRoute: IRestRoute<ITelemetryAddMetricValueRequest, ICreatedResponse> = {\n\t\toperationId: \"telemetryAddMetricValue\",\n\t\tsummary: \"Add a telemetry metric value\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/metric/:id/value`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryAddMetricValue(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryAddMetricValueRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryAddMetricValueRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tvalue: 10\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryAddMetricValueIncRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tvalue: \"inc\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ICreatedResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"telemetryAddMetricValueResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tstatusCode: HttpStatusCode.created,\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t[HeaderTypes.Location]: \"aabbccdd11223445566\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst removeMetricRoute: IRestRoute<ITelemetryRemoveMetricRequest, INoContentResponse> = {\n\t\toperationId: \"telemetryRemoveMetric\",\n\t\tsummary: \"Remove a telemetry metric and it's values.\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/metric/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryRemoveMetric(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryRemoveMetricRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryRemoveMetricRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst listMetricsRoute: IRestRoute<ITelemetryListRequest, ITelemetryListResponse> = {\n\t\toperationId: \"telemetryListEntries\",\n\t\tsummary: \"Get a list of the telemetry metrics\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/metric`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryMetricList(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryListRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryListRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tquery: {\n\t\t\t\t\t\t\ttype: MetricType.Counter.toString()\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ITelemetryListResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"telemetryListResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tentities: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"my-counter\",\n\t\t\t\t\t\t\t\t\t\tlabel: \"My Counter\",\n\t\t\t\t\t\t\t\t\t\ttype: MetricType.Counter,\n\t\t\t\t\t\t\t\t\t\tunit: \"KG\"\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"my-counter-2\",\n\t\t\t\t\t\t\t\t\t\tlabel: \"My Counter 2\",\n\t\t\t\t\t\t\t\t\t\ttype: MetricType.IncDecCounter,\n\t\t\t\t\t\t\t\t\t\tunit: \"M\"\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tcursor: \"1\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst listMetricsValuesRoute: IRestRoute<\n\t\tITelemetryValuesListRequest,\n\t\tITelemetryValuesListResponse\n\t> = {\n\t\toperationId: \"telemetryValuesListEntries\",\n\t\tsummary: \"Get a list of the values for a telemetry metric\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/metric/:id/value`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryMetricValueList(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryValuesListRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryValuesListRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ITelemetryValuesListResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"telemetryValuesListResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tmetric: {\n\t\t\t\t\t\t\t\t\tid: \"my-counter\",\n\t\t\t\t\t\t\t\t\tlabel: \"My Counter\",\n\t\t\t\t\t\t\t\t\ttype: MetricType.Counter,\n\t\t\t\t\t\t\t\t\tunit: \"KG\"\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tentities: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"aabbccdd11223445566\",\n\t\t\t\t\t\t\t\t\t\tts: 1715252922273,\n\t\t\t\t\t\t\t\t\t\tvalue: 10\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"aabbccdd11223445566\",\n\t\t\t\t\t\t\t\t\t\tts: 1715252922274,\n\t\t\t\t\t\t\t\t\t\tvalue: 11\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tcursor: \"1\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [\n\t\tcreateMetricRoute,\n\t\tgetMetricRoute,\n\t\tupdateMetricRoute,\n\t\taddMetricValueRoute,\n\t\tremoveMetricRoute,\n\t\tlistMetricsRoute,\n\t\tlistMetricsValuesRoute\n\t];\n}\n\n/**\n * Create a new telemetry metric.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryCreateMetric(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryCreateMetricRequest\n): Promise<ICreatedResponse> {\n\tGuards.object<ITelemetryCreateMetricRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryCreateMetricRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.body),\n\t\trequest.body\n\t);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\tawait component.createMetric({\n\t\tid: request.body.id,\n\t\tlabel: request.body.label,\n\t\tdescription: request.body.description,\n\t\ttype: request.body.type,\n\t\tunit: request.body.unit\n\t});\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders: {\n\t\t\t[HeaderTypes.Location]: request.body.id\n\t\t}\n\t};\n}\n\n/**\n * Gets a telemetry metric.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryGetMetric(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryGetMetricRequest\n): Promise<ITelemetryGetMetricResponse> {\n\tGuards.object<ITelemetryGetMetricRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryGetMetricRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\tconst result = await component.getMetric(request.pathParams.id);\n\treturn { body: result };\n}\n\n/**\n * Updates a telemetry metric.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryUpdateMetric(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryUpdateMetricRequest\n): Promise<INoContentResponse> {\n\tGuards.object<ITelemetryUpdateMetricRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryUpdateMetricRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\tGuards.object<ITelemetryUpdateMetricRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.body),\n\t\trequest.body\n\t);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\tawait component.updateMetric({\n\t\tid: request.pathParams.id,\n\t\tlabel: request.body.label,\n\t\tdescription: request.body.description,\n\t\tunit: request.body.unit\n\t});\n\n\treturn { statusCode: HttpStatusCode.noContent };\n}\n\n/**\n * Add a telemetry metric value.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryAddMetricValue(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryAddMetricValueRequest\n): Promise<ICreatedResponse> {\n\tGuards.object<ITelemetryAddMetricValueRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryAddMetricValueRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\tGuards.object<ITelemetryAddMetricValueRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.body),\n\t\trequest.body\n\t);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\tconst id = await component.addMetricValue(\n\t\trequest.pathParams.id,\n\t\trequest.body.value,\n\t\trequest.body.customData\n\t);\n\n\treturn { statusCode: HttpStatusCode.created, headers: { [HeaderTypes.Location]: id } };\n}\n\n/**\n * Removes a telemetry metric.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryRemoveMetric(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryRemoveMetricRequest\n): Promise<INoContentResponse> {\n\tGuards.object<ITelemetryRemoveMetricRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryRemoveMetricRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\tawait component.removeMetric(request.pathParams.id);\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Get a list of the telemetry metrics.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryMetricList(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryListRequest\n): Promise<ITelemetryListResponse> {\n\tGuards.object<ITelemetryListRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryListRequest[\"query\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.query),\n\t\trequest.query\n\t);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\n\tconst itemsAndCursor = await component.query(\n\t\tCoerce.number(request?.query?.type) as MetricType,\n\t\trequest?.query?.cursor,\n\t\tCoerce.number(request?.query?.limit)\n\t);\n\n\treturn {\n\t\tbody: itemsAndCursor\n\t};\n}\n\n/**\n * Get a list of the telemetry metric values.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryMetricValueList(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryValuesListRequest\n): Promise<ITelemetryValuesListResponse> {\n\tGuards.object<ITelemetryValuesListRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryValuesListRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.query),\n\t\trequest.query\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\n\tconst itemsAndCursor = await component.queryValues(\n\t\trequest?.pathParams.id,\n\t\tCoerce.number(request?.query?.timeStart),\n\t\tCoerce.number(request?.query?.timeEnd),\n\t\trequest?.query?.cursor,\n\t\tCoerce.number(request?.query?.limit)\n\t);\n\n\treturn {\n\t\tbody: itemsAndCursor\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"telemetryRoutes.js","sourceRoot":"","sources":["../../src/telemetryRoutes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,iBAAiB,EACjB,gBAAgB,EAChB,aAAa,EAMb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAElE,OAAO,EACN,UAAU,EAcV,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,cAAc,EAAqB,MAAM,eAAe,CAAC;AAE/E;;GAEG;AACH,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAExC;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAW;IACpC;QACC,IAAI,EAAE,WAAW;QACjB,WAAW,EAAE,8DAA8D;KAC3E;CACD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,2BAA2B,CAC1C,aAAqB,EACrB,aAAqB;IAErB,MAAM,iBAAiB,GAAgE;QACtF,WAAW,EAAE,uBAAuB;QACpC,OAAO,EAAE,2BAA2B;QACpC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI;QAC1B,MAAM,EAAE,MA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E,CAAC,CAAC;IAExF,MAAM,SAAS,GAAG,gBAAgB,CAAC,GAAG,CAAsB,aAAa,CAAC,CAAC;IAE3E,MAAM,cAAc,GAAG,MAAM,SAAS,CAAC,WAAW,CACjD,OAAO,EAAE,UAAU,CAAC,EAAE,EACtB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,EACxC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,EACtC,OAAO,EAAE,KAAK,EAAE,MAAM,EACtB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CACpC,CAAC;IAEF,OAAO;QACN,IAAI,EAAE,cAAc;KACpB,CAAC;AACH,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tHttpContextIdKeys,\n\tHttpHeaderHelper,\n\tHttpUrlHelper,\n\ttype ICreatedResponse,\n\ttype IHttpRequestContext,\n\ttype INoContentResponse,\n\ttype IRestRoute,\n\ttype ITag\n} from \"@twin.org/api-models\";\nimport { ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, ComponentFactory, Guards } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tMetricType,\n\ttype ITelemetryAddMetricValueRequest,\n\ttype ITelemetryComponent,\n\ttype ITelemetryCreateMetricRequest,\n\ttype ITelemetryGetMetricRequest,\n\ttype ITelemetryGetMetricResponse,\n\ttype ITelemetryGetMetricValueRequest,\n\ttype ITelemetryGetMetricValueResponse,\n\ttype ITelemetryListRequest,\n\ttype ITelemetryListResponse,\n\ttype ITelemetryRemoveMetricRequest,\n\ttype ITelemetryUpdateMetricRequest,\n\ttype ITelemetryValuesListRequest,\n\ttype ITelemetryValuesListResponse\n} from \"@twin.org/telemetry-models\";\nimport { HeaderTypes, HttpStatusCode, type IHttpHeaders } from \"@twin.org/web\";\n\n/**\n * The source used when communicating about these routes.\n */\nconst ROUTES_SOURCE = \"telemetryRoutes\";\n\n/**\n * The tag to associate with the routes.\n */\nexport const tagsTelemetry: ITag[] = [\n\t{\n\t\tname: \"Telemetry\",\n\t\tdescription: \"Endpoints which are modelled to access a telemetry contract.\"\n\t}\n];\n\n/**\n * The REST routes for telemetry.\n * @param baseRouteName Prefix to prepend to the paths.\n * @param componentName The name of the component to use in the routes stored in the ComponentFactory.\n * @returns The generated routes.\n */\nexport function generateRestRoutesTelemetry(\n\tbaseRouteName: string,\n\tcomponentName: string\n): IRestRoute[] {\n\tconst createMetricRoute: IRestRoute<ITelemetryCreateMetricRequest, ICreatedResponse> = {\n\t\toperationId: \"telemetryCreateMetric\",\n\t\tsummary: \"Create a telemetry metric\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/metric`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryCreateMetric(httpRequestContext, componentName, request, baseRouteName),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryCreateMetricRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryCreateMetricRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tid: \"my-counter\",\n\t\t\t\t\t\t\tlabel: \"My Counter\",\n\t\t\t\t\t\t\tdescription: \"This is my counter\",\n\t\t\t\t\t\t\ttype: MetricType.Counter,\n\t\t\t\t\t\t\tunit: \"KG\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ICreatedResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"telemetryCreateMetricResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tstatusCode: HttpStatusCode.created,\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t[HeaderTypes.Location]: \"my-counter\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst getMetricRoute: IRestRoute<ITelemetryGetMetricRequest, ITelemetryGetMetricResponse> = {\n\t\toperationId: \"telemetryGetMetric\",\n\t\tsummary: \"Get a telemetry metric and it's most recent value\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/metric/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryGetMetric(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryGetMetricRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryGetMetricRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ITelemetryGetMetricResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"telemetryGetMetricResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tmetric: {\n\t\t\t\t\t\t\t\t\tid: \"my-counter\",\n\t\t\t\t\t\t\t\t\tlabel: \"My Counter\",\n\t\t\t\t\t\t\t\t\tdescription: \"This is my counter\",\n\t\t\t\t\t\t\t\t\ttype: MetricType.Counter,\n\t\t\t\t\t\t\t\t\tunit: \"KG\"\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tvalue: {\n\t\t\t\t\t\t\t\t\tid: \"aabbccdd11223445566\",\n\t\t\t\t\t\t\t\t\tts: 1715252922273,\n\t\t\t\t\t\t\t\t\tvalue: 10\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst updateMetricRoute: IRestRoute<ITelemetryUpdateMetricRequest, INoContentResponse> = {\n\t\toperationId: \"telemetryUpdateMetric\",\n\t\tsummary: \"Update a telemetry metric\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"PUT\",\n\t\tpath: `${baseRouteName}/metric/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryUpdateMetric(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryUpdateMetricRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryUpdateMetricRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tlabel: \"My New Label\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst addMetricValueRoute: IRestRoute<ITelemetryAddMetricValueRequest, ICreatedResponse> = {\n\t\toperationId: \"telemetryAddMetricValue\",\n\t\tsummary: \"Add a telemetry metric value\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"POST\",\n\t\tpath: `${baseRouteName}/metric/:id/value`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryAddMetricValue(httpRequestContext, componentName, request, baseRouteName),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryAddMetricValueRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryAddMetricValueRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tvalue: 10\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryAddMetricValueIncRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tvalue: \"inc\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ICreatedResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"telemetryAddMetricValueResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tstatusCode: HttpStatusCode.created,\n\t\t\t\t\t\t\theaders: {\n\t\t\t\t\t\t\t\t[HeaderTypes.Location]: \"aabbccdd11223445566\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst removeMetricRoute: IRestRoute<ITelemetryRemoveMetricRequest, INoContentResponse> = {\n\t\toperationId: \"telemetryRemoveMetric\",\n\t\tsummary: \"Remove a telemetry metric and it's values.\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"DELETE\",\n\t\tpath: `${baseRouteName}/metric/:id`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryRemoveMetric(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryRemoveMetricRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryRemoveMetricRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<INoContentResponse>()\n\t\t\t}\n\t\t]\n\t};\n\n\tconst listMetricsRoute: IRestRoute<ITelemetryListRequest, ITelemetryListResponse> = {\n\t\toperationId: \"telemetryListEntries\",\n\t\tsummary: \"Get a list of the telemetry metrics\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/metric`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryMetricList(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryListRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryListRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tquery: {\n\t\t\t\t\t\t\ttype: MetricType.Counter.toString()\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ITelemetryListResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"telemetryListResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tentities: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"my-counter\",\n\t\t\t\t\t\t\t\t\t\tlabel: \"My Counter\",\n\t\t\t\t\t\t\t\t\t\ttype: MetricType.Counter,\n\t\t\t\t\t\t\t\t\t\tunit: \"KG\"\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"my-counter-2\",\n\t\t\t\t\t\t\t\t\t\tlabel: \"My Counter 2\",\n\t\t\t\t\t\t\t\t\t\ttype: MetricType.IncDecCounter,\n\t\t\t\t\t\t\t\t\t\tunit: \"M\"\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tcursor: \"1\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst getMetricValueRoute: IRestRoute<\n\t\tITelemetryGetMetricValueRequest,\n\t\tITelemetryGetMetricValueResponse\n\t> = {\n\t\toperationId: \"telemetryGetMetricValue\",\n\t\tsummary: \"Get a specific telemetry metric value\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/metric/:id/value/:valueId`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryGetMetricValue(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryGetMetricValueRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryGetMetricValueRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\",\n\t\t\t\t\t\t\tvalueId: \"aabbccdd11223445566\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ITelemetryGetMetricValueResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"telemetryGetMetricValueResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tid: \"aabbccdd11223445566\",\n\t\t\t\t\t\t\t\tts: 1715252922273,\n\t\t\t\t\t\t\t\tvalue: 10\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\tconst listMetricsValuesRoute: IRestRoute<\n\t\tITelemetryValuesListRequest,\n\t\tITelemetryValuesListResponse\n\t> = {\n\t\toperationId: \"telemetryValuesListEntries\",\n\t\tsummary: \"Get a list of the values for a telemetry metric\",\n\t\ttag: tagsTelemetry[0].name,\n\t\tmethod: \"GET\",\n\t\tpath: `${baseRouteName}/metric/:id/value`,\n\t\thandler: async (httpRequestContext, request) =>\n\t\t\ttelemetryMetricValueList(httpRequestContext, componentName, request),\n\t\trequestType: {\n\t\t\ttype: nameof<ITelemetryValuesListRequest>(),\n\t\t\texamples: [\n\t\t\t\t{\n\t\t\t\t\tid: \"telemetryValuesListRequestExample\",\n\t\t\t\t\trequest: {\n\t\t\t\t\t\tpathParams: {\n\t\t\t\t\t\t\tid: \"my-counter\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t]\n\t\t},\n\t\tresponseType: [\n\t\t\t{\n\t\t\t\ttype: nameof<ITelemetryValuesListResponse>(),\n\t\t\t\texamples: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: \"telemetryValuesListResponseExample\",\n\t\t\t\t\t\tresponse: {\n\t\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\t\tmetric: {\n\t\t\t\t\t\t\t\t\tid: \"my-counter\",\n\t\t\t\t\t\t\t\t\tlabel: \"My Counter\",\n\t\t\t\t\t\t\t\t\ttype: MetricType.Counter,\n\t\t\t\t\t\t\t\t\tunit: \"KG\"\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tentities: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"aabbccdd11223445566\",\n\t\t\t\t\t\t\t\t\t\tts: 1715252922273,\n\t\t\t\t\t\t\t\t\t\tvalue: 10\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tid: \"aabbccdd11223445566\",\n\t\t\t\t\t\t\t\t\t\tts: 1715252922274,\n\t\t\t\t\t\t\t\t\t\tvalue: 11\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tcursor: \"1\"\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t]\n\t\t\t}\n\t\t]\n\t};\n\n\treturn [\n\t\tcreateMetricRoute,\n\t\tgetMetricRoute,\n\t\tupdateMetricRoute,\n\t\taddMetricValueRoute,\n\t\tremoveMetricRoute,\n\t\tlistMetricsRoute,\n\t\tgetMetricValueRoute,\n\t\tlistMetricsValuesRoute\n\t];\n}\n\n/**\n * Create a new telemetry metric.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @param baseRouteName The base route name for the API.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryCreateMetric(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryCreateMetricRequest,\n\tbaseRouteName: string\n): Promise<ICreatedResponse> {\n\tGuards.object<ITelemetryCreateMetricRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryCreateMetricRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.body),\n\t\trequest.body\n\t);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\tawait component.createMetric({\n\t\tid: request.body.id,\n\t\tlabel: request.body.label,\n\t\tdescription: request.body.description,\n\t\ttype: request.body.type,\n\t\tunit: request.body.unit\n\t});\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tconst publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];\n\n\tconst headers: IHttpHeaders = {};\n\tHttpHeaderHelper.buildId(\n\t\theaders,\n\t\trequest.body.id,\n\t\tHttpUrlHelper.combineOriginPath(publicOrigin, `${baseRouteName}/:id`)\n\t);\n\n\treturn {\n\t\tstatusCode: HttpStatusCode.created,\n\t\theaders\n\t};\n}\n\n/**\n * Gets a telemetry metric.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryGetMetric(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryGetMetricRequest\n): Promise<ITelemetryGetMetricResponse> {\n\tGuards.object<ITelemetryGetMetricRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryGetMetricRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\tconst result = await component.getMetric(request.pathParams.id);\n\treturn { body: result };\n}\n\n/**\n * Updates a telemetry metric.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryUpdateMetric(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryUpdateMetricRequest\n): Promise<INoContentResponse> {\n\tGuards.object<ITelemetryUpdateMetricRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryUpdateMetricRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\tGuards.object<ITelemetryUpdateMetricRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.body),\n\t\trequest.body\n\t);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\tawait component.updateMetric({\n\t\tid: request.pathParams.id,\n\t\tlabel: request.body.label,\n\t\tdescription: request.body.description,\n\t\tunit: request.body.unit\n\t});\n\n\treturn { statusCode: HttpStatusCode.noContent };\n}\n\n/**\n * Add a telemetry metric value.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @param baseRouteName The base route name for the API.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryAddMetricValue(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryAddMetricValueRequest,\n\tbaseRouteName: string\n): Promise<ICreatedResponse> {\n\tGuards.object<ITelemetryAddMetricValueRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryAddMetricValueRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\tGuards.object<ITelemetryAddMetricValueRequest[\"body\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.body),\n\t\trequest.body\n\t);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\tconst id = await component.addMetricValue(\n\t\trequest.pathParams.id,\n\t\trequest.body.value,\n\t\trequest.body.customData\n\t);\n\n\tconst contextIds = await ContextIdStore.getContextIds();\n\tconst publicOrigin = contextIds?.[HttpContextIdKeys.PublicOrigin];\n\n\tconst headers: IHttpHeaders = {};\n\tHttpHeaderHelper.buildId(\n\t\theaders,\n\t\tid,\n\t\tHttpUrlHelper.combineOriginPath(publicOrigin, `${baseRouteName}/:id`)\n\t);\n\n\treturn { statusCode: HttpStatusCode.created, headers };\n}\n\n/**\n * Removes a telemetry metric.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryRemoveMetric(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryRemoveMetricRequest\n): Promise<INoContentResponse> {\n\tGuards.object<ITelemetryRemoveMetricRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryRemoveMetricRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\tawait component.removeMetric(request.pathParams.id);\n\treturn {\n\t\tstatusCode: HttpStatusCode.noContent\n\t};\n}\n\n/**\n * Get a list of the telemetry metrics.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryMetricList(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryListRequest\n): Promise<ITelemetryListResponse> {\n\tGuards.object<ITelemetryListRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryListRequest[\"query\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.query),\n\t\trequest.query\n\t);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\n\tconst itemsAndCursor = await component.query(\n\t\tCoerce.number(request?.query?.type) as MetricType,\n\t\trequest?.query?.cursor,\n\t\tCoerce.number(request?.query?.limit)\n\t);\n\n\treturn {\n\t\tbody: itemsAndCursor\n\t};\n}\n\n/**\n * Gets a specific telemetry metric value.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryGetMetricValue(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryGetMetricValueRequest\n): Promise<ITelemetryGetMetricValueResponse> {\n\tGuards.object<ITelemetryGetMetricValueRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryGetMetricValueRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.pathParams),\n\t\trequest.pathParams\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.valueId), request.pathParams.valueId);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\tconst result = await component.getMetricValue(request.pathParams.id, request.pathParams.valueId);\n\treturn { body: result };\n}\n\n/**\n * Get a list of the telemetry metric values.\n * @param httpRequestContext The request context for the API.\n * @param componentName The name of the component to use in the routes.\n * @param request The request.\n * @returns The response object with additional http response properties.\n */\nexport async function telemetryMetricValueList(\n\thttpRequestContext: IHttpRequestContext,\n\tcomponentName: string,\n\trequest: ITelemetryValuesListRequest\n): Promise<ITelemetryValuesListResponse> {\n\tGuards.object<ITelemetryValuesListRequest>(ROUTES_SOURCE, nameof(request), request);\n\tGuards.object<ITelemetryValuesListRequest[\"pathParams\"]>(\n\t\tROUTES_SOURCE,\n\t\tnameof(request.query),\n\t\trequest.query\n\t);\n\tGuards.stringValue(ROUTES_SOURCE, nameof(request.pathParams.id), request.pathParams.id);\n\n\tconst component = ComponentFactory.get<ITelemetryComponent>(componentName);\n\n\tconst itemsAndCursor = await component.queryValues(\n\t\trequest?.pathParams.id,\n\t\tCoerce.number(request?.query?.timeStart),\n\t\tCoerce.number(request?.query?.timeEnd),\n\t\trequest?.query?.cursor,\n\t\tCoerce.number(request?.query?.limit)\n\t);\n\n\treturn {\n\t\tbody: itemsAndCursor\n\t};\n}\n"]}
|
|
@@ -62,6 +62,17 @@ export class TelemetryService {
|
|
|
62
62
|
Guards.stringValue(TelemetryService.CLASS_NAME, "id", id);
|
|
63
63
|
return this._telemetryConnector.getMetric(id);
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Get a specific metric value by its id.
|
|
67
|
+
* @param id The id of the metric.
|
|
68
|
+
* @param valueId The id of the metric value.
|
|
69
|
+
* @returns The metric value.
|
|
70
|
+
*/
|
|
71
|
+
async getMetricValue(id, valueId) {
|
|
72
|
+
Guards.stringValue(TelemetryService.CLASS_NAME, "id", id);
|
|
73
|
+
Guards.stringValue(TelemetryService.CLASS_NAME, "valueId", valueId);
|
|
74
|
+
return this._telemetryConnector.getMetricValue(id, valueId);
|
|
75
|
+
}
|
|
65
76
|
/**
|
|
66
77
|
* Update metric.
|
|
67
78
|
* @param metric The metric details.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetryService.js","sourceRoot":"","sources":["../../src/telemetryService.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,EACN,yBAAyB,EAOzB,MAAM,4BAA4B,CAAC;AAGpC;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAC5B;;OAEG;IACI,MAAM,CAAU,UAAU,sBAAsC;IAEvE;;;OAGG;IACc,mBAAmB,CAAsB;IAE1D;;;OAGG;IACc,kBAAkB,CAAqB;IAExD;;;OAGG;IACH,YAAY,OAA6C;QACxD,IAAI,CAAC,mBAAmB,GAAG,yBAAyB,CAAC,GAAG,CACvD,OAAO,EAAE,sBAAsB,IAAI,WAAW,CAC9C,CAAC;QACF,IAAI,CAAC,kBAAkB,GAAG,gBAAgB,CAAC,GAAG,CAC7C,OAAO,EAAE,qBAAqB,IAAI,UAAU,CAC5C,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,gBAAgB,CAAC,UAAU,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,YAAY,CAAC,MAAwB;QACjD,MAAM,CAAC,MAAM,CAAmB,gBAAgB,CAAC,UAAU,YAAkB,MAAM,CAAC,CAAC;QAErF,iFAAiF;QACjF,qFAAqF;QACrF,yCAAyC;QACzC,MAAM,UAAU,GAAG,CAAC,MAAM,cAAc,CAAC,aAAa,EAAE,CAAC,IAAI,EAAE,CAAC;QAChE,MAAM,SAAS,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AAC;IACvE,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,YAAY,CAAC,EAAU;QACnC,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,UAAU,QAAc,EAAE,CAAC,CAAC;QAChE,OAAO,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,KAAK,CACjB,IAAiB,EACjB,MAAe,EACf,KAAc;QAYd,OAAO,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC5D,CAAC;IAED;;;;;;;;;;OAUG;IACI,KAAK,CAAC,WAAW,CACvB,EAAU,EACV,SAAkB,EAClB,OAAgB,EAChB,MAAe,EACf,KAAc;QAed,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,UAAU,QAAc,EAAE,CAAC,CAAC;QAChE,OAAO,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACpF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IPlatformComponent } from \"@twin.org/api-models\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { ComponentFactory, Guards, Is } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tTelemetryConnectorFactory,\n\ttype ITelemetryComponent,\n\ttype ITelemetryConnector,\n\ttype ITelemetryMetric,\n\ttype ITelemetryMetricValue,\n\ttype MetricCounterOperation,\n\ttype MetricType\n} from \"@twin.org/telemetry-models\";\nimport type { ITelemetryServiceConstructorOptions } from \"./models/ITelemetryServiceConstructorOptions.js\";\n\n/**\n * Service for performing telemetry operations to a connector.\n */\nexport class TelemetryService implements ITelemetryComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<TelemetryService>();\n\n\t/**\n\t * Telemetry connector used by the service.\n\t * @internal\n\t */\n\tprivate readonly _telemetryConnector: ITelemetryConnector;\n\n\t/**\n\t * Platform component.\n\t * @internal\n\t */\n\tprivate readonly _platformComponent: IPlatformComponent;\n\n\t/**\n\t * Create a new instance of TelemetryService.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options?: ITelemetryServiceConstructorOptions) {\n\t\tthis._telemetryConnector = TelemetryConnectorFactory.get(\n\t\t\toptions?.telemetryConnectorType ?? \"telemetry\"\n\t\t);\n\t\tthis._platformComponent = ComponentFactory.get<IPlatformComponent>(\n\t\t\toptions?.platformComponentType ?? \"platform\"\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn TelemetryService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create a new metric.\n\t * @param metric The metric details.\n\t * @returns A promise that resolves when the metric has been created.\n\t */\n\tpublic async createMetric(metric: ITelemetryMetric): Promise<void> {\n\t\tGuards.object<ITelemetryMetric>(TelemetryService.CLASS_NAME, nameof(metric), metric);\n\n\t\t// If we don't have a tenant context ID and the tenant component is multi-tenant,\n\t\t// we consider the entry as per-tenant and run it in all the tenant context to ensure\n\t\t// the metric is created for each tenant.\n\t\tconst contextIds = (await ContextIdStore.getContextIds()) ?? {};\n\t\tconst perTenant =\n\t\t\t!Is.stringValue(contextIds[ContextIdKeys.Tenant]) && this._platformComponent.isMultiTenant();\n\n\t\tif (perTenant) {\n\t\t\tawait this._platformComponent.execute(async () =>\n\t\t\t\tthis._telemetryConnector.createMetric(metric)\n\t\t\t);\n\t\t} else {\n\t\t\tawait this._telemetryConnector.createMetric(metric);\n\t\t}\n\t}\n\n\t/**\n\t * Get the metric details and it's most recent value.\n\t * @param id The metric id.\n\t * @returns The metric details and it's most recent value.\n\t */\n\tpublic async getMetric(id: string): Promise<{\n\t\tmetric: ITelemetryMetric;\n\t\tvalue: ITelemetryMetricValue;\n\t}> {\n\t\tGuards.stringValue(TelemetryService.CLASS_NAME, nameof(id), id);\n\t\treturn this._telemetryConnector.getMetric(id);\n\t}\n\n\t/**\n\t * Update metric.\n\t * @param metric The metric details.\n\t * @returns A promise that resolves when the metric has been updated.\n\t */\n\tpublic async updateMetric(metric: Omit<ITelemetryMetric, \"type\">): Promise<void> {\n\t\tGuards.object<ITelemetryMetric>(TelemetryService.CLASS_NAME, nameof(metric), metric);\n\t\tGuards.stringValue(TelemetryService.CLASS_NAME, nameof(metric.id), metric.id);\n\t\treturn this._telemetryConnector.updateMetric(metric);\n\t}\n\n\t/**\n\t * Add a metric value.\n\t * @param id The id of the metric.\n\t * @param value The value for the add operation.\n\t * @param customData The custom data for the add operation.\n\t * @returns The created metric value id.\n\t */\n\tpublic async addMetricValue(\n\t\tid: string,\n\t\tvalue: MetricCounterOperation | number,\n\t\tcustomData?: { [key: string]: unknown }\n\t): Promise<string> {\n\t\tGuards.stringValue(TelemetryService.CLASS_NAME, nameof(id), id);\n\t\tGuards.defined(TelemetryService.CLASS_NAME, nameof(value), value);\n\t\treturn this._telemetryConnector.addMetricValue(id, value, customData);\n\t}\n\n\t/**\n\t * Remove metric.\n\t * @param id The id of the metric.\n\t * @returns A promise that resolves when the metric and all its values have been removed.\n\t */\n\tpublic async removeMetric(id: string): Promise<void> {\n\t\tGuards.stringValue(TelemetryService.CLASS_NAME, nameof(id), id);\n\t\treturn this._telemetryConnector.removeMetric(id);\n\t}\n\n\t/**\n\t * Query the metrics.\n\t * @param type The type of the metric.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t * @throws NotImplementedError if the implementation does not support retrieval.\n\t */\n\tpublic async query(\n\t\ttype?: MetricType,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The metrics.\n\t\t */\n\t\tentities: ITelemetryMetric[];\n\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more values.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\treturn this._telemetryConnector.query(type, cursor, limit);\n\t}\n\n\t/**\n\t * Query the metric values.\n\t * @param id The id of the metric.\n\t * @param timeStart The inclusive time as the start of the metric entries.\n\t * @param timeEnd The inclusive time as the end of the metric entries.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t * @throws NotImplementedError if the implementation does not support retrieval.\n\t */\n\tpublic async queryValues(\n\t\tid: string,\n\t\ttimeStart?: number,\n\t\ttimeEnd?: number,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The metric details.\n\t\t */\n\t\tmetric: ITelemetryMetric;\n\t\t/**\n\t\t * The values for the metric.\n\t\t */\n\t\tentities: ITelemetryMetricValue[];\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more values.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\tGuards.stringValue(TelemetryService.CLASS_NAME, nameof(id), id);\n\t\treturn this._telemetryConnector.queryValues(id, timeStart, timeEnd, cursor, limit);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"telemetryService.js","sourceRoot":"","sources":["../../src/telemetryService.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE9D,OAAO,EACN,yBAAyB,EAOzB,MAAM,4BAA4B,CAAC;AAGpC;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAC5B;;OAEG;IACI,MAAM,CAAU,UAAU,sBAAsC;IAEvE;;;OAGG;IACc,mBAAmB,CAAsB;IAE1D;;;OAGG;IACc,kBAAkB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,CAAC,mBAAmB,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC5D,CAAC;IAED;;;;;;;;;;OAUG;IACI,KAAK,CAAC,WAAW,CACvB,EAAU,EACV,SAAkB,EAClB,OAAgB,EAChB,MAAe,EACf,KAAc;QAed,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,UAAU,QAAc,EAAE,CAAC,CAAC;QAChE,OAAO,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACpF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IPlatformComponent } from \"@twin.org/api-models\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { ComponentFactory, Guards, Is } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport {\n\tTelemetryConnectorFactory,\n\ttype ITelemetryComponent,\n\ttype ITelemetryConnector,\n\ttype ITelemetryMetric,\n\ttype ITelemetryMetricValue,\n\ttype MetricCounterOperation,\n\ttype MetricType\n} from \"@twin.org/telemetry-models\";\nimport type { ITelemetryServiceConstructorOptions } from \"./models/ITelemetryServiceConstructorOptions.js\";\n\n/**\n * Service for performing telemetry operations to a connector.\n */\nexport class TelemetryService implements ITelemetryComponent {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<TelemetryService>();\n\n\t/**\n\t * Telemetry connector used by the service.\n\t * @internal\n\t */\n\tprivate readonly _telemetryConnector: ITelemetryConnector;\n\n\t/**\n\t * Platform component.\n\t * @internal\n\t */\n\tprivate readonly _platformComponent: IPlatformComponent;\n\n\t/**\n\t * Create a new instance of TelemetryService.\n\t * @param options The options for the connector.\n\t */\n\tconstructor(options?: ITelemetryServiceConstructorOptions) {\n\t\tthis._telemetryConnector = TelemetryConnectorFactory.get(\n\t\t\toptions?.telemetryConnectorType ?? \"telemetry\"\n\t\t);\n\t\tthis._platformComponent = ComponentFactory.get<IPlatformComponent>(\n\t\t\toptions?.platformComponentType ?? \"platform\"\n\t\t);\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn TelemetryService.CLASS_NAME;\n\t}\n\n\t/**\n\t * Create a new metric.\n\t * @param metric The metric details.\n\t * @returns A promise that resolves when the metric has been created.\n\t */\n\tpublic async createMetric(metric: ITelemetryMetric): Promise<void> {\n\t\tGuards.object<ITelemetryMetric>(TelemetryService.CLASS_NAME, nameof(metric), metric);\n\n\t\t// If we don't have a tenant context ID and the tenant component is multi-tenant,\n\t\t// we consider the entry as per-tenant and run it in all the tenant context to ensure\n\t\t// the metric is created for each tenant.\n\t\tconst contextIds = (await ContextIdStore.getContextIds()) ?? {};\n\t\tconst perTenant =\n\t\t\t!Is.stringValue(contextIds[ContextIdKeys.Tenant]) && this._platformComponent.isMultiTenant();\n\n\t\tif (perTenant) {\n\t\t\tawait this._platformComponent.execute(async () =>\n\t\t\t\tthis._telemetryConnector.createMetric(metric)\n\t\t\t);\n\t\t} else {\n\t\t\tawait this._telemetryConnector.createMetric(metric);\n\t\t}\n\t}\n\n\t/**\n\t * Get the metric details and it's most recent value.\n\t * @param id The metric id.\n\t * @returns The metric details and it's most recent value.\n\t */\n\tpublic async getMetric(id: string): Promise<{\n\t\tmetric: ITelemetryMetric;\n\t\tvalue: ITelemetryMetricValue;\n\t}> {\n\t\tGuards.stringValue(TelemetryService.CLASS_NAME, nameof(id), id);\n\t\treturn this._telemetryConnector.getMetric(id);\n\t}\n\n\t/**\n\t * Get a specific metric value by its id.\n\t * @param id The id of the metric.\n\t * @param valueId The id of the metric value.\n\t * @returns The metric value.\n\t */\n\tpublic async getMetricValue(id: string, valueId: string): Promise<ITelemetryMetricValue> {\n\t\tGuards.stringValue(TelemetryService.CLASS_NAME, nameof(id), id);\n\t\tGuards.stringValue(TelemetryService.CLASS_NAME, nameof(valueId), valueId);\n\t\treturn this._telemetryConnector.getMetricValue(id, valueId);\n\t}\n\n\t/**\n\t * Update metric.\n\t * @param metric The metric details.\n\t * @returns A promise that resolves when the metric has been updated.\n\t */\n\tpublic async updateMetric(metric: Omit<ITelemetryMetric, \"type\">): Promise<void> {\n\t\tGuards.object<ITelemetryMetric>(TelemetryService.CLASS_NAME, nameof(metric), metric);\n\t\tGuards.stringValue(TelemetryService.CLASS_NAME, nameof(metric.id), metric.id);\n\t\treturn this._telemetryConnector.updateMetric(metric);\n\t}\n\n\t/**\n\t * Add a metric value.\n\t * @param id The id of the metric.\n\t * @param value The value for the add operation.\n\t * @param customData The custom data for the add operation.\n\t * @returns The created metric value id.\n\t */\n\tpublic async addMetricValue(\n\t\tid: string,\n\t\tvalue: MetricCounterOperation | number,\n\t\tcustomData?: { [key: string]: unknown }\n\t): Promise<string> {\n\t\tGuards.stringValue(TelemetryService.CLASS_NAME, nameof(id), id);\n\t\tGuards.defined(TelemetryService.CLASS_NAME, nameof(value), value);\n\t\treturn this._telemetryConnector.addMetricValue(id, value, customData);\n\t}\n\n\t/**\n\t * Remove metric.\n\t * @param id The id of the metric.\n\t * @returns A promise that resolves when the metric and all its values have been removed.\n\t */\n\tpublic async removeMetric(id: string): Promise<void> {\n\t\tGuards.stringValue(TelemetryService.CLASS_NAME, nameof(id), id);\n\t\treturn this._telemetryConnector.removeMetric(id);\n\t}\n\n\t/**\n\t * Query the metrics.\n\t * @param type The type of the metric.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t * @throws NotImplementedError if the implementation does not support retrieval.\n\t */\n\tpublic async query(\n\t\ttype?: MetricType,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The metrics.\n\t\t */\n\t\tentities: ITelemetryMetric[];\n\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more values.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\treturn this._telemetryConnector.query(type, cursor, limit);\n\t}\n\n\t/**\n\t * Query the metric values.\n\t * @param id The id of the metric.\n\t * @param timeStart The inclusive time as the start of the metric entries.\n\t * @param timeEnd The inclusive time as the end of the metric entries.\n\t * @param cursor The cursor to request the next chunk of entities.\n\t * @param limit Limit the number of entities to return.\n\t * @returns All the entities for the storage matching the conditions,\n\t * and a cursor which can be used to request more entities.\n\t * @throws NotImplementedError if the implementation does not support retrieval.\n\t */\n\tpublic async queryValues(\n\t\tid: string,\n\t\ttimeStart?: number,\n\t\ttimeEnd?: number,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\t/**\n\t\t * The metric details.\n\t\t */\n\t\tmetric: ITelemetryMetric;\n\t\t/**\n\t\t * The values for the metric.\n\t\t */\n\t\tentities: ITelemetryMetricValue[];\n\t\t/**\n\t\t * An optional cursor, when defined can be used to call find to get more values.\n\t\t */\n\t\tcursor?: string;\n\t}> {\n\t\tGuards.stringValue(TelemetryService.CLASS_NAME, nameof(id), id);\n\t\treturn this._telemetryConnector.queryValues(id, timeStart, timeEnd, cursor, limit);\n\t}\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type ITelemetryAddMetricValueRequest, type ITelemetryCreateMetricRequest, type ITelemetryGetMetricRequest, type ITelemetryGetMetricResponse, type ITelemetryListRequest, type ITelemetryListResponse, type ITelemetryRemoveMetricRequest, type ITelemetryUpdateMetricRequest, type ITelemetryValuesListRequest, type ITelemetryValuesListResponse } from "@twin.org/telemetry-models";
|
|
1
|
+
import { type ICreatedResponse, type IHttpRequestContext, type INoContentResponse, type IRestRoute, type ITag } from "@twin.org/api-models";
|
|
2
|
+
import { type ITelemetryAddMetricValueRequest, type ITelemetryCreateMetricRequest, type ITelemetryGetMetricRequest, type ITelemetryGetMetricResponse, type ITelemetryGetMetricValueRequest, type ITelemetryGetMetricValueResponse, type ITelemetryListRequest, type ITelemetryListResponse, type ITelemetryRemoveMetricRequest, type ITelemetryUpdateMetricRequest, type ITelemetryValuesListRequest, type ITelemetryValuesListResponse } from "@twin.org/telemetry-models";
|
|
3
3
|
/**
|
|
4
4
|
* The tag to associate with the routes.
|
|
5
5
|
*/
|
|
@@ -16,9 +16,10 @@ export declare function generateRestRoutesTelemetry(baseRouteName: string, compo
|
|
|
16
16
|
* @param httpRequestContext The request context for the API.
|
|
17
17
|
* @param componentName The name of the component to use in the routes.
|
|
18
18
|
* @param request The request.
|
|
19
|
+
* @param baseRouteName The base route name for the API.
|
|
19
20
|
* @returns The response object with additional http response properties.
|
|
20
21
|
*/
|
|
21
|
-
export declare function telemetryCreateMetric(httpRequestContext: IHttpRequestContext, componentName: string, request: ITelemetryCreateMetricRequest): Promise<ICreatedResponse>;
|
|
22
|
+
export declare function telemetryCreateMetric(httpRequestContext: IHttpRequestContext, componentName: string, request: ITelemetryCreateMetricRequest, baseRouteName: string): Promise<ICreatedResponse>;
|
|
22
23
|
/**
|
|
23
24
|
* Gets a telemetry metric.
|
|
24
25
|
* @param httpRequestContext The request context for the API.
|
|
@@ -40,9 +41,10 @@ export declare function telemetryUpdateMetric(httpRequestContext: IHttpRequestCo
|
|
|
40
41
|
* @param httpRequestContext The request context for the API.
|
|
41
42
|
* @param componentName The name of the component to use in the routes.
|
|
42
43
|
* @param request The request.
|
|
44
|
+
* @param baseRouteName The base route name for the API.
|
|
43
45
|
* @returns The response object with additional http response properties.
|
|
44
46
|
*/
|
|
45
|
-
export declare function telemetryAddMetricValue(httpRequestContext: IHttpRequestContext, componentName: string, request: ITelemetryAddMetricValueRequest): Promise<ICreatedResponse>;
|
|
47
|
+
export declare function telemetryAddMetricValue(httpRequestContext: IHttpRequestContext, componentName: string, request: ITelemetryAddMetricValueRequest, baseRouteName: string): Promise<ICreatedResponse>;
|
|
46
48
|
/**
|
|
47
49
|
* Removes a telemetry metric.
|
|
48
50
|
* @param httpRequestContext The request context for the API.
|
|
@@ -59,6 +61,14 @@ export declare function telemetryRemoveMetric(httpRequestContext: IHttpRequestCo
|
|
|
59
61
|
* @returns The response object with additional http response properties.
|
|
60
62
|
*/
|
|
61
63
|
export declare function telemetryMetricList(httpRequestContext: IHttpRequestContext, componentName: string, request: ITelemetryListRequest): Promise<ITelemetryListResponse>;
|
|
64
|
+
/**
|
|
65
|
+
* Gets a specific telemetry metric value.
|
|
66
|
+
* @param httpRequestContext The request context for the API.
|
|
67
|
+
* @param componentName The name of the component to use in the routes.
|
|
68
|
+
* @param request The request.
|
|
69
|
+
* @returns The response object with additional http response properties.
|
|
70
|
+
*/
|
|
71
|
+
export declare function telemetryGetMetricValue(httpRequestContext: IHttpRequestContext, componentName: string, request: ITelemetryGetMetricValueRequest): Promise<ITelemetryGetMetricValueResponse>;
|
|
62
72
|
/**
|
|
63
73
|
* Get a list of the telemetry metric values.
|
|
64
74
|
* @param httpRequestContext The request context for the API.
|
|
@@ -33,6 +33,13 @@ export declare class TelemetryService implements ITelemetryComponent {
|
|
|
33
33
|
metric: ITelemetryMetric;
|
|
34
34
|
value: ITelemetryMetricValue;
|
|
35
35
|
}>;
|
|
36
|
+
/**
|
|
37
|
+
* Get a specific metric value by its id.
|
|
38
|
+
* @param id The id of the metric.
|
|
39
|
+
* @param valueId The id of the metric value.
|
|
40
|
+
* @returns The metric value.
|
|
41
|
+
*/
|
|
42
|
+
getMetricValue(id: string, valueId: string): Promise<ITelemetryMetricValue>;
|
|
36
43
|
/**
|
|
37
44
|
* Update metric.
|
|
38
45
|
* @param metric The metric details.
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.9.1-next.3](https://github.com/iotaledger/twin-telemetry/compare/telemetry-service-v0.9.1-next.2...telemetry-service-v0.9.1-next.3) (2026-06-30)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* rest enhancement ([#56](https://github.com/iotaledger/twin-telemetry/issues/56)) ([28b79fc](https://github.com/iotaledger/twin-telemetry/commit/28b79fc2fb66f1e5c28cde325d018e5878d899b5))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/telemetry-models bumped from 0.9.1-next.2 to 0.9.1-next.3
|
|
16
|
+
|
|
17
|
+
## [0.9.1-next.2](https://github.com/iotaledger/twin-telemetry/compare/telemetry-service-v0.9.1-next.1...telemetry-service-v0.9.1-next.2) (2026-06-29)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* enhanced rest testing ([#54](https://github.com/iotaledger/twin-telemetry/issues/54)) ([13b4c02](https://github.com/iotaledger/twin-telemetry/commit/13b4c02dc77d82f2fd88e2b79bd3dda077f639f6))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Dependencies
|
|
26
|
+
|
|
27
|
+
* The following workspace dependencies were updated
|
|
28
|
+
* dependencies
|
|
29
|
+
* @twin.org/telemetry-models bumped from 0.9.1-next.1 to 0.9.1-next.2
|
|
30
|
+
|
|
3
31
|
## [0.9.1-next.1](https://github.com/iotaledger/twin-telemetry/compare/telemetry-service-v0.9.1-next.0...telemetry-service-v0.9.1-next.1) (2026-06-26)
|
|
4
32
|
|
|
5
33
|
|
package/docs/open-api/spec.json
CHANGED
|
@@ -839,6 +839,122 @@
|
|
|
839
839
|
}
|
|
840
840
|
}
|
|
841
841
|
}
|
|
842
|
+
},
|
|
843
|
+
"/telemetry/metric/{id}/value/{valueId}": {
|
|
844
|
+
"get": {
|
|
845
|
+
"operationId": "telemetryGetMetricValue",
|
|
846
|
+
"summary": "Get a specific telemetry metric value",
|
|
847
|
+
"tags": [
|
|
848
|
+
"Telemetry"
|
|
849
|
+
],
|
|
850
|
+
"parameters": [
|
|
851
|
+
{
|
|
852
|
+
"name": "id",
|
|
853
|
+
"description": "The id of the metric.",
|
|
854
|
+
"in": "path",
|
|
855
|
+
"required": true,
|
|
856
|
+
"schema": {
|
|
857
|
+
"type": "string"
|
|
858
|
+
},
|
|
859
|
+
"style": "simple",
|
|
860
|
+
"example": "my-counter"
|
|
861
|
+
},
|
|
862
|
+
{
|
|
863
|
+
"name": "valueId",
|
|
864
|
+
"description": "The id of the metric value.",
|
|
865
|
+
"in": "path",
|
|
866
|
+
"required": true,
|
|
867
|
+
"schema": {
|
|
868
|
+
"type": "string"
|
|
869
|
+
},
|
|
870
|
+
"style": "simple",
|
|
871
|
+
"example": "aabbccdd11223445566"
|
|
872
|
+
}
|
|
873
|
+
],
|
|
874
|
+
"security": [
|
|
875
|
+
{
|
|
876
|
+
"jwtBearerAuthScheme": []
|
|
877
|
+
}
|
|
878
|
+
],
|
|
879
|
+
"responses": {
|
|
880
|
+
"200": {
|
|
881
|
+
"description": "Get a telemetry metric value response.",
|
|
882
|
+
"content": {
|
|
883
|
+
"application/json": {
|
|
884
|
+
"schema": {
|
|
885
|
+
"$ref": "#/components/schemas/TelemetryMetricValue"
|
|
886
|
+
},
|
|
887
|
+
"examples": {
|
|
888
|
+
"telemetryGetMetricValueResponseExample": {
|
|
889
|
+
"value": {
|
|
890
|
+
"id": "aabbccdd11223445566",
|
|
891
|
+
"ts": 1715252922273,
|
|
892
|
+
"value": 10
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
},
|
|
899
|
+
"400": {
|
|
900
|
+
"description": "The server cannot process the request, see the content for more details.",
|
|
901
|
+
"content": {
|
|
902
|
+
"application/json": {
|
|
903
|
+
"schema": {
|
|
904
|
+
"$ref": "#/components/schemas/Error"
|
|
905
|
+
},
|
|
906
|
+
"examples": {
|
|
907
|
+
"exampleResponse": {
|
|
908
|
+
"value": {
|
|
909
|
+
"name": "GeneralError",
|
|
910
|
+
"message": "errorMessage",
|
|
911
|
+
"properties": {
|
|
912
|
+
"foo": "bar"
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
},
|
|
920
|
+
"401": {
|
|
921
|
+
"description": "You are not authorized to use the API or no credentials were supplied, see the content for more details.",
|
|
922
|
+
"content": {
|
|
923
|
+
"application/json": {
|
|
924
|
+
"schema": {
|
|
925
|
+
"$ref": "#/components/schemas/Error"
|
|
926
|
+
},
|
|
927
|
+
"examples": {
|
|
928
|
+
"exampleResponse": {
|
|
929
|
+
"value": {
|
|
930
|
+
"name": "UnauthorizedError",
|
|
931
|
+
"message": "errorMessage"
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
},
|
|
938
|
+
"500": {
|
|
939
|
+
"description": "The server has encountered a situation it does not know how to handle, see the content for more details.",
|
|
940
|
+
"content": {
|
|
941
|
+
"application/json": {
|
|
942
|
+
"schema": {
|
|
943
|
+
"$ref": "#/components/schemas/Error"
|
|
944
|
+
},
|
|
945
|
+
"examples": {
|
|
946
|
+
"exampleResponse": {
|
|
947
|
+
"value": {
|
|
948
|
+
"name": "InternalServerError",
|
|
949
|
+
"message": "errorMessage"
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
}
|
|
842
958
|
}
|
|
843
959
|
},
|
|
844
960
|
"components": {
|
|
@@ -106,6 +106,38 @@ The metric details and it's most recent value.
|
|
|
106
106
|
|
|
107
107
|
***
|
|
108
108
|
|
|
109
|
+
### getMetricValue() {#getmetricvalue}
|
|
110
|
+
|
|
111
|
+
> **getMetricValue**(`id`, `valueId`): `Promise`\<`ITelemetryMetricValue`\>
|
|
112
|
+
|
|
113
|
+
Get a specific metric value by its id.
|
|
114
|
+
|
|
115
|
+
#### Parameters
|
|
116
|
+
|
|
117
|
+
##### id
|
|
118
|
+
|
|
119
|
+
`string`
|
|
120
|
+
|
|
121
|
+
The id of the metric.
|
|
122
|
+
|
|
123
|
+
##### valueId
|
|
124
|
+
|
|
125
|
+
`string`
|
|
126
|
+
|
|
127
|
+
The id of the metric value.
|
|
128
|
+
|
|
129
|
+
#### Returns
|
|
130
|
+
|
|
131
|
+
`Promise`\<`ITelemetryMetricValue`\>
|
|
132
|
+
|
|
133
|
+
The metric value.
|
|
134
|
+
|
|
135
|
+
#### Implementation of
|
|
136
|
+
|
|
137
|
+
`ITelemetryComponent.getMetricValue`
|
|
138
|
+
|
|
139
|
+
***
|
|
140
|
+
|
|
109
141
|
### updateMetric() {#updatemetric}
|
|
110
142
|
|
|
111
143
|
> **updateMetric**(`metric`): `Promise`\<`void`\>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Function: telemetryAddMetricValue()
|
|
2
2
|
|
|
3
|
-
> **telemetryAddMetricValue**(`httpRequestContext`, `componentName`, `request`): `Promise`\<`ICreatedResponse`\>
|
|
3
|
+
> **telemetryAddMetricValue**(`httpRequestContext`, `componentName`, `request`, `baseRouteName`): `Promise`\<`ICreatedResponse`\>
|
|
4
4
|
|
|
5
5
|
Add a telemetry metric value.
|
|
6
6
|
|
|
@@ -24,6 +24,12 @@ The name of the component to use in the routes.
|
|
|
24
24
|
|
|
25
25
|
The request.
|
|
26
26
|
|
|
27
|
+
### baseRouteName
|
|
28
|
+
|
|
29
|
+
`string`
|
|
30
|
+
|
|
31
|
+
The base route name for the API.
|
|
32
|
+
|
|
27
33
|
## Returns
|
|
28
34
|
|
|
29
35
|
`Promise`\<`ICreatedResponse`\>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Function: telemetryCreateMetric()
|
|
2
2
|
|
|
3
|
-
> **telemetryCreateMetric**(`httpRequestContext`, `componentName`, `request`): `Promise`\<`ICreatedResponse`\>
|
|
3
|
+
> **telemetryCreateMetric**(`httpRequestContext`, `componentName`, `request`, `baseRouteName`): `Promise`\<`ICreatedResponse`\>
|
|
4
4
|
|
|
5
5
|
Create a new telemetry metric.
|
|
6
6
|
|
|
@@ -24,6 +24,12 @@ The name of the component to use in the routes.
|
|
|
24
24
|
|
|
25
25
|
The request.
|
|
26
26
|
|
|
27
|
+
### baseRouteName
|
|
28
|
+
|
|
29
|
+
`string`
|
|
30
|
+
|
|
31
|
+
The base route name for the API.
|
|
32
|
+
|
|
27
33
|
## Returns
|
|
28
34
|
|
|
29
35
|
`Promise`\<`ICreatedResponse`\>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Function: telemetryGetMetricValue()
|
|
2
|
+
|
|
3
|
+
> **telemetryGetMetricValue**(`httpRequestContext`, `componentName`, `request`): `Promise`\<`ITelemetryGetMetricValueResponse`\>
|
|
4
|
+
|
|
5
|
+
Gets a specific telemetry metric value.
|
|
6
|
+
|
|
7
|
+
## Parameters
|
|
8
|
+
|
|
9
|
+
### httpRequestContext
|
|
10
|
+
|
|
11
|
+
`IHttpRequestContext`
|
|
12
|
+
|
|
13
|
+
The request context for the API.
|
|
14
|
+
|
|
15
|
+
### componentName
|
|
16
|
+
|
|
17
|
+
`string`
|
|
18
|
+
|
|
19
|
+
The name of the component to use in the routes.
|
|
20
|
+
|
|
21
|
+
### request
|
|
22
|
+
|
|
23
|
+
`ITelemetryGetMetricValueRequest`
|
|
24
|
+
|
|
25
|
+
The request.
|
|
26
|
+
|
|
27
|
+
## Returns
|
|
28
|
+
|
|
29
|
+
`Promise`\<`ITelemetryGetMetricValueResponse`\>
|
|
30
|
+
|
|
31
|
+
The response object with additional http response properties.
|
package/docs/reference/index.md
CHANGED
|
@@ -25,4 +25,5 @@
|
|
|
25
25
|
- [telemetryAddMetricValue](functions/telemetryAddMetricValue.md)
|
|
26
26
|
- [telemetryRemoveMetric](functions/telemetryRemoveMetric.md)
|
|
27
27
|
- [telemetryMetricList](functions/telemetryMetricList.md)
|
|
28
|
+
- [telemetryGetMetricValue](functions/telemetryGetMetricValue.md)
|
|
28
29
|
- [telemetryMetricValueList](functions/telemetryMetricValueList.md)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/telemetry-service",
|
|
3
|
-
"version": "0.9.1-next.
|
|
3
|
+
"version": "0.9.1-next.3",
|
|
4
4
|
"description": "Telemetry service implementation with REST entry points.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@twin.org/entity": "next",
|
|
21
21
|
"@twin.org/logging-models": "next",
|
|
22
22
|
"@twin.org/nameof": "next",
|
|
23
|
-
"@twin.org/telemetry-models": "0.9.1-next.
|
|
23
|
+
"@twin.org/telemetry-models": "0.9.1-next.3",
|
|
24
24
|
"@twin.org/web": "next"
|
|
25
25
|
},
|
|
26
26
|
"main": "./dist/es/index.js",
|