@naturalcycles/backend-lib 9.35.0 → 9.37.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.
@@ -39,6 +39,7 @@ export interface CloudRunConfig {
39
39
  * Example: httpGet.path='/',httpGet.port=8080,initialDelaySeconds=3,failureThreshold=50,timeoutSeconds=1,periodSeconds=2
40
40
  */
41
41
  startupProbeConfigString: string;
42
+ livenessProbeConfigString?: string;
42
43
  minInstances: NonNegativeInteger;
43
44
  maxInstances: PositiveInteger;
44
45
  /**
@@ -51,7 +52,7 @@ export interface CloudRunConfig {
51
52
  */
52
53
  memoryPerInstance: string;
53
54
  }
54
- export interface CloudRunStartupProbeConfig {
55
+ export interface CloudRunProbeConfig {
55
56
  /**
56
57
  * Example: '/'
57
58
  */
@@ -106,7 +107,8 @@ declare class CloudRunUtil {
106
107
  * key-value pair is represented as `key1=value1,key2=value2,...`.
107
108
  */
108
109
  stringifyObject(obj: AnyObject): string;
109
- readonly defaultStartupProbeConfig: CloudRunStartupProbeConfig;
110
+ readonly defaultStartupProbeConfig: CloudRunProbeConfig;
111
+ readonly defaultLivenessProbeConfig: CloudRunProbeConfig;
110
112
  }
111
113
  export declare const cloudRunUtil: CloudRunUtil;
112
114
  export {};
@@ -21,5 +21,17 @@ class CloudRunUtil {
21
21
  timeoutSeconds: 1,
22
22
  periodSeconds: 2,
23
23
  };
24
+ defaultLivenessProbeConfig = {
25
+ 'httpGet.path': '/',
26
+ 'httpGet.port': 8080,
27
+ // how long to wait before doing the first check, AFTER the startup probe has succeeded
28
+ initialDelaySeconds: 60,
29
+ // after how many failure it should kill/restart the container
30
+ failureThreshold: 5,
31
+ // how long to wait until liveness probe considers the endpoint unhealthy
32
+ timeoutSeconds: 30,
33
+ // check every periodSeconds
34
+ periodSeconds: 60,
35
+ };
24
36
  }
25
37
  export const cloudRunUtil = new CloudRunUtil();
@@ -1,5 +1,6 @@
1
1
  import { _mb } from '@naturalcycles/js-lib';
2
- import { _sortBy, _sum } from '@naturalcycles/js-lib/array/array.util.js';
2
+ import { _sum } from '@naturalcycles/js-lib/array/array.util.js';
3
+ import { _sortBy } from '@naturalcycles/js-lib/array/sort.js';
3
4
  import { _ms } from '@naturalcycles/js-lib/datetime/time.util.js';
4
5
  import { _percentile } from '@naturalcycles/js-lib/math/math.util.js';
5
6
  import { NumberStack } from '@naturalcycles/js-lib/math/stack.util.js';
@@ -29,7 +29,7 @@ class AjvValidateRequest {
29
29
  const input = req[reqProperty] || {};
30
30
  const ajvSchema = AjvSchema.create(schema);
31
31
  const [error, output] = ajvSchema.getValidationResult(input, {
32
- inputName: `request ${reqProperty}`,
32
+ inputName: `request.${reqProperty}`,
33
33
  });
34
34
  if (error) {
35
35
  handleValidationError(error, input, opt);
@@ -25,7 +25,7 @@ class ValidateRequest {
25
25
  validate(req, reqProperty, schema, opt = {}) {
26
26
  const originalProperty = req[reqProperty] || {};
27
27
  // Joi does not mutate the input
28
- const [error, value] = getValidationResult(originalProperty, schema, `request ${reqProperty}`);
28
+ const [error, value] = getValidationResult(originalProperty, schema, `request.${reqProperty}`);
29
29
  if (error) {
30
30
  if (opt.redactPaths) {
31
31
  error.data.joiValidationErrorItems.length = 0; // clears the array
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/backend-lib",
3
3
  "type": "module",
4
- "version": "9.35.0",
4
+ "version": "9.37.0",
5
5
  "peerDependencies": {
6
6
  "@sentry/node": "^10"
7
7
  },
@@ -29,7 +29,7 @@
29
29
  "@sentry/node": "^10",
30
30
  "@types/ejs": "^3",
31
31
  "fastify": "^5",
32
- "@naturalcycles/dev-lib": "18.4.2"
32
+ "@naturalcycles/dev-lib": "20.6.0"
33
33
  },
34
34
  "exports": {
35
35
  ".": "./dist/index.js",
@@ -66,6 +66,7 @@ export interface CloudRunConfig {
66
66
  * Example: httpGet.path='/',httpGet.port=8080,initialDelaySeconds=3,failureThreshold=50,timeoutSeconds=1,periodSeconds=2
67
67
  */
68
68
  startupProbeConfigString: string
69
+ livenessProbeConfigString?: string
69
70
  minInstances: NonNegativeInteger
70
71
  maxInstances: PositiveInteger
71
72
  /**
@@ -79,7 +80,7 @@ export interface CloudRunConfig {
79
80
  memoryPerInstance: string
80
81
  }
81
82
 
82
- export interface CloudRunStartupProbeConfig {
83
+ export interface CloudRunProbeConfig {
83
84
  /**
84
85
  * Example: '/'
85
86
  */
@@ -144,7 +145,7 @@ class CloudRunUtil {
144
145
  .join(',')
145
146
  }
146
147
 
147
- readonly defaultStartupProbeConfig: CloudRunStartupProbeConfig = {
148
+ readonly defaultStartupProbeConfig: CloudRunProbeConfig = {
148
149
  'httpGet.path': '/',
149
150
  'httpGet.port': 8080,
150
151
  initialDelaySeconds: 3,
@@ -152,6 +153,19 @@ class CloudRunUtil {
152
153
  timeoutSeconds: 1,
153
154
  periodSeconds: 2,
154
155
  }
156
+
157
+ readonly defaultLivenessProbeConfig: CloudRunProbeConfig = {
158
+ 'httpGet.path': '/',
159
+ 'httpGet.port': 8080,
160
+ // how long to wait before doing the first check, AFTER the startup probe has succeeded
161
+ initialDelaySeconds: 60,
162
+ // after how many failure it should kill/restart the container
163
+ failureThreshold: 5,
164
+ // how long to wait until liveness probe considers the endpoint unhealthy
165
+ timeoutSeconds: 30,
166
+ // check every periodSeconds
167
+ periodSeconds: 60,
168
+ }
155
169
  }
156
170
 
157
171
  export const cloudRunUtil = new CloudRunUtil()
@@ -1,5 +1,6 @@
1
1
  import { _mb } from '@naturalcycles/js-lib'
2
- import { _sortBy, _sum } from '@naturalcycles/js-lib/array/array.util.js'
2
+ import { _sum } from '@naturalcycles/js-lib/array/array.util.js'
3
+ import { _sortBy } from '@naturalcycles/js-lib/array/sort.js'
3
4
  import { _ms } from '@naturalcycles/js-lib/datetime/time.util.js'
4
5
  import { _percentile } from '@naturalcycles/js-lib/math/math.util.js'
5
6
  import { NumberStack } from '@naturalcycles/js-lib/math/stack.util.js'
@@ -61,7 +61,7 @@ class AjvValidateRequest {
61
61
  const ajvSchema = AjvSchema.create(schema)
62
62
 
63
63
  const [error, output] = ajvSchema.getValidationResult(input, {
64
- inputName: `request ${reqProperty}`,
64
+ inputName: `request.${reqProperty}`,
65
65
  })
66
66
 
67
67
  if (error) {
@@ -54,7 +54,7 @@ class ValidateRequest {
54
54
  const originalProperty = req[reqProperty] || {}
55
55
 
56
56
  // Joi does not mutate the input
57
- const [error, value] = getValidationResult(originalProperty, schema, `request ${reqProperty}`)
57
+ const [error, value] = getValidationResult(originalProperty, schema, `request.${reqProperty}`)
58
58
 
59
59
  if (error) {
60
60
  if (opt.redactPaths) {