@rsdk/core 5.6.0-next.3 → 5.6.0-next.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,21 +36,28 @@ let HealthChecksService = class HealthChecksService {
36
36
  const indicators = this.filterIndicators(filter);
37
37
  let success = true;
38
38
  const summary = { details: {}, status: 'up' };
39
- await Promise.all(indicators.map(async (indicator) => {
39
+ await Promise.all(indicators.map(async ({ indicator, meta: { isOptional } }) => {
40
40
  const name = this.indicatorNames.get(indicator);
41
41
  if (!name) {
42
42
  throw new Error(`Indicator [${indicator.constructor.name}] - name not found`);
43
43
  }
44
44
  try {
45
45
  const result = await indicator.check();
46
- if (result.isError) {
46
+ if (!isOptional && result.isError) {
47
47
  success = false;
48
48
  }
49
+ result.details.optional = isOptional;
49
50
  summary.details[name] = result;
50
51
  }
51
52
  catch (error) {
52
- success = false;
53
- summary.details[name] = error;
53
+ if (!isOptional) {
54
+ success = false;
55
+ }
56
+ const err = error;
57
+ summary.details[name] = {
58
+ ...err,
59
+ details: { ...err.details, optional: isOptional },
60
+ };
54
61
  }
55
62
  }));
56
63
  if (!success) {
@@ -65,13 +72,14 @@ let HealthChecksService = class HealthChecksService {
65
72
  async onModuleInit() {
66
73
  this.logger.debug('Initializing indicators...');
67
74
  const indicators = this.iterateByIndicators();
68
- for (const [ctor, { key, scope }] of indicators) {
75
+ for (const [ctor, meta] of indicators) {
76
+ const { key, scope } = meta;
69
77
  if (!this.indicators[scope]) {
70
78
  this.indicators[scope] = [];
71
79
  }
72
80
  const [instance] = this.resolve([ctor]);
73
81
  this.indicatorNames.set(instance, key);
74
- this.indicators[scope].push(instance);
82
+ this.indicators[scope].push({ indicator: instance, meta });
75
83
  }
76
84
  this.logger.info(`Indicators initialized!`);
77
85
  }
@@ -1 +1 @@
1
- {"version":3,"file":"health.service.js","sourceRoot":"","sources":["../../src/health/health.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,2CAA4C;AA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AO,CACb,UAAoD;QAEpD,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YAC1B,IAAI,OAAO,CAAC,KAAK,UAAU,EAAE,CAAC;gBAC5B,OAAO,CAAC,CAAC;YACX,CAAC;YAED,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AArIY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,sBAAY,EAAC,mBAAmB,CAAC,CAAA;6CACN,gBAAS;QACE,+BAAoB;GAPlD,mBAAmB,CAqI/B"}
@@ -11,10 +11,10 @@ export declare class CheckResult {
11
11
  */
12
12
  readonly status: CheckStatus;
13
13
  /**
14
- * @optional Custom attributes (key value) Will
14
+ * Custom attributes (key value) Will
15
15
  * be returned to check caller or/and logged
16
16
  */
17
- readonly details?: CheckDetails;
17
+ readonly details: CheckDetails;
18
18
  private constructor();
19
19
  /**
20
20
  * Indicated that check was not successful
@@ -12,7 +12,7 @@ class CheckResult {
12
12
  */
13
13
  status;
14
14
  /**
15
- * @optional Custom attributes (key value) Will
15
+ * Custom attributes (key value) Will
16
16
  * be returned to check caller or/and logged
17
17
  */
18
18
  details;
@@ -1 +1 @@
1
- {"version":3,"file":"check-result.class.js","sourceRoot":"","sources":["../../../src/health/helpers/check-result.class.ts"],"names":[],"mappings":";;;AAGA;;;;GAIG;AACH,MAAa,WAAW;IACtB;;OAEG;IACM,MAAM,CAAc;IAE7B;;;OAGG;IACM,OAAO,CAAgB;IAEhC,YAAoB,MAAmB,EAAE,OAAqB;QAC5D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC;IAChC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,EAAE,CAAC,OAAqB;QAC7B,OAAO,IAAI,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAC,OAAqB;QAC/B,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;CACF;AA3CD,kCA2CC"}
1
+ {"version":3,"file":"check-result.class.js","sourceRoot":"","sources":["../../../src/health/helpers/check-result.class.ts"],"names":[],"mappings":";;;AAGA;;;;GAIG;AACH,MAAa,WAAW;IACtB;;OAEG;IACM,MAAM,CAAc;IAE7B;;;OAGG;IACM,OAAO,CAAe;IAE/B,YAAoB,MAAmB,EAAE,OAAqB;QAC5D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,MAAM,KAAK,MAAM,CAAC;IAChC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,EAAE,CAAC,OAAqB;QAC7B,OAAO,IAAI,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAC,OAAqB;QAC/B,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;CACF;AA3CD,kCA2CC"}
@@ -7,6 +7,11 @@ export interface IndicatorOptions {
7
7
  * FIXME: WTF?
8
8
  */
9
9
  scope?: string;
10
+ /**
11
+ * Flag indicating whether the readiness probe is optional.
12
+ * If set to `true`, an error in the probe will not affect the global system status.
13
+ */
14
+ isOptional?: boolean;
10
15
  }
11
16
  /**
12
17
  * Registers health indicator. Indicators should be added to application
@@ -1 +1 @@
1
- {"version":3,"file":"indicator.decorator.js","sourceRoot":"","sources":["../../../src/health/metadata/indicator.decorator.ts"],"names":[],"mappings":";AAAA,iDAAiD;;;AAIjD,kDAA6D;AAG7D,+DAA2D;AAc3D;;;;;;;;;GASG;AACI,MAAM,SAAS,GAAG,CACvB,GAAW,EACX,UAA4B,EAAE,EACd,EAAE;IAClB,OAAO,UAAU,MAAgB;QAC/B,wCAAkB,CAAC,QAAQ,CAAC,MAAsC,EAAE;YAClE,GAAG;YACH,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,yCAA0B;YAClD,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,SAAS,aAWpB"}
1
+ {"version":3,"file":"indicator.decorator.js","sourceRoot":"","sources":["../../../src/health/metadata/indicator.decorator.ts"],"names":[],"mappings":";AAAA,iDAAiD;;;AAIjD,kDAA6D;AAG7D,+DAA2D;AAoB3D;;;;;;;;;GASG;AACI,MAAM,SAAS,GAAG,CACvB,GAAW,EACX,UAA4B,EAAE,EACd,EAAE;IAClB,OAAO,UAAU,MAAgB;QAC/B,wCAAkB,CAAC,QAAQ,CAAC,MAAsC,EAAE;YAClE,GAAG;YACH,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,yCAA0B;YAClD,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,SAAS,aAWpB"}
@@ -30,10 +30,14 @@ export interface HealthIndicator {
30
30
  */
31
31
  check(): Promise<CheckResult>;
32
32
  }
33
+ export type IndicatorWithMetadata = {
34
+ indicator: HealthIndicator;
35
+ meta: IndicatorMetadata;
36
+ };
33
37
  export type ResolvedIndicators = {
34
- [key: string]: HealthIndicator[];
38
+ [key: string]: IndicatorWithMetadata[];
35
39
  } & {
36
- common: HealthIndicator[];
40
+ common: IndicatorWithMetadata[];
37
41
  };
38
42
  export interface HealthModuleOptions {
39
43
  controllers: Constructor<Controller>[];
@@ -42,4 +46,9 @@ export interface IndicatorMetadata {
42
46
  key: string;
43
47
  scope: string;
44
48
  description?: string;
49
+ /**
50
+ * Flag indicating whether the readiness probe is optional.
51
+ * If set to `true`, an error in the probe will not affect the global system status.
52
+ */
53
+ isOptional?: boolean;
45
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdk/core",
3
- "version": "5.6.0-next.3",
3
+ "version": "5.6.0-next.5",
4
4
  "description": "Nestjs based microservice chassis",
5
5
  "license": "Apache License 2.0",
6
6
  "publishConfig": {
@@ -49,5 +49,5 @@
49
49
  "optional": true
50
50
  }
51
51
  },
52
- "gitHead": "92c0392ea85a5667186f18e123a435f8db293df8"
52
+ "gitHead": "754d114b6ef5c9d30dc844735a00b6155784bf1f"
53
53
  }
@@ -15,6 +15,7 @@ import type {
15
15
  CheckSummary,
16
16
  HealthIndicator,
17
17
  IndicatorMetadata,
18
+ IndicatorWithMetadata,
18
19
  ResolvedIndicators,
19
20
  } from './types';
20
21
 
@@ -38,7 +39,7 @@ export class HealthChecksService implements OnModuleInit {
38
39
  const summary: CheckSummary = { details: {}, status: 'up' };
39
40
 
40
41
  await Promise.all(
41
- indicators.map(async (indicator) => {
42
+ indicators.map(async ({ indicator, meta: { isOptional } }) => {
42
43
  const name = this.indicatorNames.get(indicator);
43
44
  if (!name) {
44
45
  throw new Error(
@@ -48,14 +49,24 @@ export class HealthChecksService implements OnModuleInit {
48
49
 
49
50
  try {
50
51
  const result = await indicator.check();
51
- if (result.isError) {
52
+
53
+ if (!isOptional && result.isError) {
52
54
  success = false;
53
55
  }
54
56
 
57
+ result.details.optional = isOptional;
55
58
  summary.details[name] = result;
56
59
  } catch (error) {
57
- success = false;
58
- summary.details[name] = error as any;
60
+ if (!isOptional) {
61
+ success = false;
62
+ }
63
+
64
+ const err = error as any;
65
+
66
+ summary.details[name] = {
67
+ ...err,
68
+ details: { ...err.details, optional: isOptional },
69
+ };
59
70
  }
60
71
  }),
61
72
  );
@@ -81,7 +92,9 @@ export class HealthChecksService implements OnModuleInit {
81
92
 
82
93
  const indicators = this.iterateByIndicators();
83
94
 
84
- for (const [ctor, { key, scope }] of indicators) {
95
+ for (const [ctor, meta] of indicators) {
96
+ const { key, scope } = meta;
97
+
85
98
  if (!this.indicators[scope]) {
86
99
  this.indicators[scope] = [];
87
100
  }
@@ -89,13 +102,13 @@ export class HealthChecksService implements OnModuleInit {
89
102
  const [instance] = this.resolve([ctor]);
90
103
 
91
104
  this.indicatorNames.set(instance, key);
92
- this.indicators[scope].push(instance);
105
+ this.indicators[scope].push({ indicator: instance, meta });
93
106
  }
94
107
 
95
108
  this.logger.info(`Indicators initialized!`);
96
109
  }
97
110
 
98
- private filterIndicators(filter: '*' | string = ''): HealthIndicator[] {
111
+ private filterIndicators(filter: '*' | string = ''): IndicatorWithMetadata[] {
99
112
  switch (filter) {
100
113
  /**
101
114
  * This means readiness healthcheck which means that server itself is up,
@@ -13,10 +13,10 @@ export class CheckResult {
13
13
  readonly status: CheckStatus;
14
14
 
15
15
  /**
16
- * @optional Custom attributes (key value) Will
16
+ * Custom attributes (key value) Will
17
17
  * be returned to check caller or/and logged
18
18
  */
19
- readonly details?: CheckDetails;
19
+ readonly details: CheckDetails;
20
20
 
21
21
  private constructor(status: CheckStatus, details: CheckDetails) {
22
22
  this.status = status;
@@ -17,6 +17,12 @@ export interface IndicatorOptions {
17
17
  * FIXME: WTF?
18
18
  */
19
19
  scope?: string;
20
+
21
+ /**
22
+ * Flag indicating whether the readiness probe is optional.
23
+ * If set to `true`, an error in the probe will not affect the global system status.
24
+ */
25
+ isOptional?: boolean;
20
26
  }
21
27
 
22
28
  /**
@@ -35,9 +35,14 @@ export interface HealthIndicator {
35
35
  check(): Promise<CheckResult>;
36
36
  }
37
37
 
38
+ export type IndicatorWithMetadata = {
39
+ indicator: HealthIndicator;
40
+ meta: IndicatorMetadata;
41
+ };
42
+
38
43
  export type ResolvedIndicators = {
39
- [key: string]: HealthIndicator[];
40
- } & { common: HealthIndicator[] };
44
+ [key: string]: IndicatorWithMetadata[];
45
+ } & { common: IndicatorWithMetadata[] };
41
46
 
42
47
  export interface HealthModuleOptions {
43
48
  controllers: Constructor<Controller>[];
@@ -47,4 +52,10 @@ export interface IndicatorMetadata {
47
52
  key: string;
48
53
  scope: string;
49
54
  description?: string;
55
+
56
+ /**
57
+ * Flag indicating whether the readiness probe is optional.
58
+ * If set to `true`, an error in the probe will not affect the global system status.
59
+ */
60
+ isOptional?: boolean;
50
61
  }