@tramvai/module-metrics 1.95.1 → 1.97.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -158,22 +158,7 @@ fetch(url).then(() => {
158
158
 
159
159
  ### Use custom port for metrics endpoint
160
160
 
161
- It can be done with token `METRICS_MODULE_CONFIG_TOKEN` and its property `port`:
162
-
163
- ```ts
164
- import { provide } from '@tramvai/core';
165
- import { METRICS_MODULE_CONFIG_TOKEN } from '@tramvai/tokens-metrics';
166
-
167
- const providers = [
168
- provide({
169
- provide: METRICS_MODULE_CONFIG_TOKEN,
170
- useValue: {
171
- enableConnectionResolveMetrics: true,
172
- port: 3001,
173
- },
174
- }),
175
- ];
176
- ```
161
+ It can be done with token `UTILITY_SERVER_PORT_TOKEN` as it works for any [utility path](./server.md#specify-port-for-utility-paths):
177
162
 
178
163
  ## Debug
179
164
 
package/lib/server.es.js CHANGED
@@ -1,13 +1,12 @@
1
1
  import { __decorate } from 'tslib';
2
- import { Module, commandLineListTokens, Scope, createToken, provide } from '@tramvai/core';
3
- import { SERVER_MODULE_PAPI_PUBLIC_ROUTE, SERVER_TOKEN, SPECIAL_SERVER_PATHS } from '@tramvai/tokens-server';
4
- import { SERVER_FACTORY_TOKEN, WEB_FASTIFY_APP_TOKEN, WEB_FASTIFY_APP_FACTORY_TOKEN, WEB_FASTIFY_APP_BEFORE_INIT_TOKEN, WEB_FASTIFY_APP_INIT_TOKEN } from '@tramvai/tokens-server-private';
2
+ import { Module, commandLineListTokens, Scope, provide } from '@tramvai/core';
3
+ import { SERVER_MODULE_PAPI_PUBLIC_ROUTE, UTILITY_SERVER_PATHS } from '@tramvai/tokens-server';
4
+ import { WEB_FASTIFY_APP_BEFORE_INIT_TOKEN, UTILITY_WEB_FASTIFY_APP_TOKEN, WEB_FASTIFY_APP_INIT_TOKEN } from '@tramvai/tokens-server-private';
5
5
  import { METRICS_MODULE_TOKEN, METRICS_SERVICES_REGISTRY_TOKEN, METRICS_MODULE_CONFIG_TOKEN, REGISTER_INSTANT_METRIC_TOKEN } from '@tramvai/tokens-metrics';
6
6
  export * from '@tramvai/tokens-metrics';
7
7
  import { fastifyMeasureRequests } from '@tinkoff/measure-fastify-requests';
8
8
  import { Registry, collectDefaultMetrics, Counter, Gauge, Histogram, Summary } from 'prom-client';
9
9
  import flatten from '@tinkoff/utils/array/flatten';
10
- import { ENV_MANAGER_TOKEN as ENV_MANAGER_TOKEN$1, LOGGER_TOKEN as LOGGER_TOKEN$1 } from '@tramvai/tokens-common';
11
10
  import { ENV_MANAGER_TOKEN, COMBINE_REDUCERS, LOGGER_TOKEN, CONTEXT_TOKEN } from '@tramvai/module-common';
12
11
  import noop from '@tinkoff/utils/function/noop';
13
12
  import https from 'https';
@@ -454,9 +453,6 @@ const eventLoopMetrics = (metrics) => {
454
453
  startEventLoopLagMeasure(histogram);
455
454
  };
456
455
 
457
- const METRICS_IS_CUSTOM_SERVER_TOKEN = createToken('metrics isCustomServer');
458
- const METRICS_SERVER_TOKEN = createToken('metrics server');
459
- const METRICS_WEB_APP_TOKEN = createToken('metrics webApp');
460
456
  let MetricsModule = class MetricsModule {
461
457
  };
462
458
  MetricsModule = __decorate([
@@ -489,76 +485,6 @@ MetricsModule = __decorate([
489
485
  registry: 'metricsDefaultRegistry',
490
486
  },
491
487
  }),
492
- provide({
493
- provide: METRICS_IS_CUSTOM_SERVER_TOKEN,
494
- useFactory: ({ config, envManager }) => {
495
- return config.port && +envManager.get('PORT') !== config.port;
496
- },
497
- deps: {
498
- envManager: ENV_MANAGER_TOKEN$1,
499
- config: METRICS_MODULE_CONFIG_TOKEN,
500
- },
501
- }),
502
- provide({
503
- provide: METRICS_SERVER_TOKEN,
504
- scope: Scope.SINGLETON,
505
- useFactory: ({ isCustomServer, serverFactory, server }) => {
506
- return isCustomServer ? serverFactory() : server;
507
- },
508
- deps: {
509
- isCustomServer: METRICS_IS_CUSTOM_SERVER_TOKEN,
510
- server: SERVER_TOKEN,
511
- serverFactory: SERVER_FACTORY_TOKEN,
512
- },
513
- }),
514
- provide({
515
- provide: METRICS_WEB_APP_TOKEN,
516
- scope: Scope.SINGLETON,
517
- useFactory: ({ isCustomServer, app, appFactory, server }) => {
518
- return isCustomServer ? appFactory({ server }) : app;
519
- },
520
- deps: {
521
- isCustomServer: METRICS_IS_CUSTOM_SERVER_TOKEN,
522
- app: WEB_FASTIFY_APP_TOKEN,
523
- appFactory: WEB_FASTIFY_APP_FACTORY_TOKEN,
524
- server: METRICS_SERVER_TOKEN,
525
- },
526
- }),
527
- provide({
528
- provide: commandLineListTokens.listen,
529
- multi: true,
530
- scope: Scope.SINGLETON,
531
- useFactory: ({ logger, isCustomServer, config, app, server }) => {
532
- return async function metricsServerListen() {
533
- if (!isCustomServer) {
534
- return;
535
- }
536
- const log = logger('metrics:server');
537
- const { port = 3001 } = config;
538
- await app.ready();
539
- return new Promise((resolve, reject) => {
540
- server.once('error', (error) => {
541
- log.error({ event: 'server-listen-port', error });
542
- reject(error);
543
- });
544
- server.listen({
545
- host: '',
546
- port,
547
- }, () => {
548
- log.warn({ event: 'server-listen-port', message: `Server listen ${port} port` });
549
- resolve();
550
- });
551
- });
552
- };
553
- },
554
- deps: {
555
- logger: LOGGER_TOKEN$1,
556
- isCustomServer: METRICS_IS_CUSTOM_SERVER_TOKEN,
557
- config: METRICS_MODULE_CONFIG_TOKEN,
558
- app: METRICS_WEB_APP_TOKEN,
559
- server: METRICS_SERVER_TOKEN,
560
- },
561
- }),
562
488
  provide({
563
489
  provide: WEB_FASTIFY_APP_BEFORE_INIT_TOKEN,
564
490
  useFactory: ({ app, registry }) => {
@@ -570,7 +496,7 @@ MetricsModule = __decorate([
570
496
  };
571
497
  },
572
498
  deps: {
573
- app: METRICS_WEB_APP_TOKEN,
499
+ app: UTILITY_WEB_FASTIFY_APP_TOKEN,
574
500
  registry: 'metricsDefaultRegistry',
575
501
  },
576
502
  multi: true,
@@ -598,7 +524,7 @@ MetricsModule = __decorate([
598
524
  },
599
525
  deps: {
600
526
  metrics: METRICS_MODULE_TOKEN,
601
- app: WEB_FASTIFY_APP_TOKEN,
527
+ app: UTILITY_WEB_FASTIFY_APP_TOKEN,
602
528
  additionalLabelNamesList: {
603
529
  token: 'additionalLabelNames',
604
530
  multi: true,
@@ -613,7 +539,7 @@ MetricsModule = __decorate([
613
539
  token: 'httpRequestsDurationBuckets',
614
540
  optional: true,
615
541
  },
616
- metricsExcludePaths: SPECIAL_SERVER_PATHS,
542
+ metricsExcludePaths: UTILITY_SERVER_PATHS,
617
543
  },
618
544
  multi: true,
619
545
  }),
package/lib/server.js CHANGED
@@ -10,7 +10,6 @@ var tokensMetrics = require('@tramvai/tokens-metrics');
10
10
  var measureFastifyRequests = require('@tinkoff/measure-fastify-requests');
11
11
  var promClient = require('prom-client');
12
12
  var flatten = require('@tinkoff/utils/array/flatten');
13
- var tokensCommon = require('@tramvai/tokens-common');
14
13
  var moduleCommon = require('@tramvai/module-common');
15
14
  var noop = require('@tinkoff/utils/function/noop');
16
15
  var https = require('https');
@@ -467,9 +466,6 @@ const eventLoopMetrics = (metrics) => {
467
466
  startEventLoopLagMeasure(histogram);
468
467
  };
469
468
 
470
- const METRICS_IS_CUSTOM_SERVER_TOKEN = core.createToken('metrics isCustomServer');
471
- const METRICS_SERVER_TOKEN = core.createToken('metrics server');
472
- const METRICS_WEB_APP_TOKEN = core.createToken('metrics webApp');
473
469
  exports.MetricsModule = class MetricsModule {
474
470
  };
475
471
  exports.MetricsModule = tslib.__decorate([
@@ -502,76 +498,6 @@ exports.MetricsModule = tslib.__decorate([
502
498
  registry: 'metricsDefaultRegistry',
503
499
  },
504
500
  }),
505
- core.provide({
506
- provide: METRICS_IS_CUSTOM_SERVER_TOKEN,
507
- useFactory: ({ config, envManager }) => {
508
- return config.port && +envManager.get('PORT') !== config.port;
509
- },
510
- deps: {
511
- envManager: tokensCommon.ENV_MANAGER_TOKEN,
512
- config: tokensMetrics.METRICS_MODULE_CONFIG_TOKEN,
513
- },
514
- }),
515
- core.provide({
516
- provide: METRICS_SERVER_TOKEN,
517
- scope: core.Scope.SINGLETON,
518
- useFactory: ({ isCustomServer, serverFactory, server }) => {
519
- return isCustomServer ? serverFactory() : server;
520
- },
521
- deps: {
522
- isCustomServer: METRICS_IS_CUSTOM_SERVER_TOKEN,
523
- server: tokensServer.SERVER_TOKEN,
524
- serverFactory: tokensServerPrivate.SERVER_FACTORY_TOKEN,
525
- },
526
- }),
527
- core.provide({
528
- provide: METRICS_WEB_APP_TOKEN,
529
- scope: core.Scope.SINGLETON,
530
- useFactory: ({ isCustomServer, app, appFactory, server }) => {
531
- return isCustomServer ? appFactory({ server }) : app;
532
- },
533
- deps: {
534
- isCustomServer: METRICS_IS_CUSTOM_SERVER_TOKEN,
535
- app: tokensServerPrivate.WEB_FASTIFY_APP_TOKEN,
536
- appFactory: tokensServerPrivate.WEB_FASTIFY_APP_FACTORY_TOKEN,
537
- server: METRICS_SERVER_TOKEN,
538
- },
539
- }),
540
- core.provide({
541
- provide: core.commandLineListTokens.listen,
542
- multi: true,
543
- scope: core.Scope.SINGLETON,
544
- useFactory: ({ logger, isCustomServer, config, app, server }) => {
545
- return async function metricsServerListen() {
546
- if (!isCustomServer) {
547
- return;
548
- }
549
- const log = logger('metrics:server');
550
- const { port = 3001 } = config;
551
- await app.ready();
552
- return new Promise((resolve, reject) => {
553
- server.once('error', (error) => {
554
- log.error({ event: 'server-listen-port', error });
555
- reject(error);
556
- });
557
- server.listen({
558
- host: '',
559
- port,
560
- }, () => {
561
- log.warn({ event: 'server-listen-port', message: `Server listen ${port} port` });
562
- resolve();
563
- });
564
- });
565
- };
566
- },
567
- deps: {
568
- logger: tokensCommon.LOGGER_TOKEN,
569
- isCustomServer: METRICS_IS_CUSTOM_SERVER_TOKEN,
570
- config: tokensMetrics.METRICS_MODULE_CONFIG_TOKEN,
571
- app: METRICS_WEB_APP_TOKEN,
572
- server: METRICS_SERVER_TOKEN,
573
- },
574
- }),
575
501
  core.provide({
576
502
  provide: tokensServerPrivate.WEB_FASTIFY_APP_BEFORE_INIT_TOKEN,
577
503
  useFactory: ({ app, registry }) => {
@@ -583,7 +509,7 @@ exports.MetricsModule = tslib.__decorate([
583
509
  };
584
510
  },
585
511
  deps: {
586
- app: METRICS_WEB_APP_TOKEN,
512
+ app: tokensServerPrivate.UTILITY_WEB_FASTIFY_APP_TOKEN,
587
513
  registry: 'metricsDefaultRegistry',
588
514
  },
589
515
  multi: true,
@@ -611,7 +537,7 @@ exports.MetricsModule = tslib.__decorate([
611
537
  },
612
538
  deps: {
613
539
  metrics: tokensMetrics.METRICS_MODULE_TOKEN,
614
- app: tokensServerPrivate.WEB_FASTIFY_APP_TOKEN,
540
+ app: tokensServerPrivate.UTILITY_WEB_FASTIFY_APP_TOKEN,
615
541
  additionalLabelNamesList: {
616
542
  token: 'additionalLabelNames',
617
543
  multi: true,
@@ -626,7 +552,7 @@ exports.MetricsModule = tslib.__decorate([
626
552
  token: 'httpRequestsDurationBuckets',
627
553
  optional: true,
628
554
  },
629
- metricsExcludePaths: tokensServer.SPECIAL_SERVER_PATHS,
555
+ metricsExcludePaths: tokensServer.UTILITY_SERVER_PATHS,
630
556
  },
631
557
  multi: true,
632
558
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-metrics",
3
- "version": "1.95.1",
3
+ "version": "1.97.0",
4
4
  "description": "",
5
5
  "browser": "lib/browser.js",
6
6
  "main": "lib/server.js",
@@ -19,15 +19,14 @@
19
19
  "build-for-publish": "true"
20
20
  },
21
21
  "dependencies": {
22
- "@tramvai/core": "1.95.1",
23
- "@tramvai/tokens-common": "1.95.1",
24
- "@tramvai/tokens-server": "1.95.1",
25
- "@tramvai/tokens-server-private": "1.95.1",
26
- "@tramvai/tokens-metrics": "1.95.1",
27
- "@tramvai/module-common": "1.95.1",
28
- "@tramvai/tokens-http-client": "1.95.1",
29
- "@tramvai/state": "1.95.1",
30
- "@tramvai/papi": "1.95.1",
22
+ "@tramvai/core": "1.97.0",
23
+ "@tramvai/tokens-server": "1.97.0",
24
+ "@tramvai/tokens-server-private": "1.97.0",
25
+ "@tramvai/tokens-metrics": "1.97.0",
26
+ "@tramvai/module-common": "1.97.0",
27
+ "@tramvai/tokens-http-client": "1.97.0",
28
+ "@tramvai/state": "1.97.0",
29
+ "@tramvai/papi": "1.97.0",
31
30
  "@tinkoff/measure-fastify-requests": "0.0.2",
32
31
  "@tinkoff/monkeypatch": "1.3.3",
33
32
  "@tinkoff/url": "0.7.37",