@whitewater-guide/gorge 3.0.0-beta.1 → 3.0.0-beta.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.
Files changed (3) hide show
  1. package/README.md +54 -10
  2. package/index.d.ts +2 -2
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -13,6 +13,7 @@ Harvested data is stored in database and can be queried later.
13
13
  - [Launching](#launching)
14
14
  - [Working with API](#working-with-api)
15
15
  - [Available scripts](#available-scripts)
16
+ - [Health notifications](#health-notifications)
16
17
  - [Other](#other)
17
18
  - [Development](#development)
18
19
  - [Inside container](#inside-container)
@@ -45,7 +46,7 @@ You can find the list of our data sources and their statuses [here](scripts/READ
45
46
 
46
47
  ## Usage
47
48
 
48
- Gorge is distributed as a ~50Mb [docker image](https://github.com/whitewater-guide/gorge/pkgs/container/gorge) with two binary files:
49
+ Gorge is distributed as a ~130Mb [docker image](https://github.com/whitewater-guide/gorge/pkgs/container/gorge) with two binary files:
49
50
 
50
51
  - `gorge-server` (_entrypoint_) - web server with REST API
51
52
  - `gorge-cli` - command-line client for this server. Since image is distroless, use `docker exec gorge gorge-cli` to call it
@@ -89,7 +90,9 @@ Here is the list of available flags:
89
90
  --db-chunk-size int measurements will be saved to db in chunks of this size. When set to 0, they will be saved in one chunk, which can cause errors
90
91
  --debug enables debug mode, sets log level to debug
91
92
  --endpoint string endpoint path (default "/")
93
+ --hooks-health-cron string cron expression for running health notifier (default "0 0 * * *")
92
94
  --hooks-health-headers strings headers to set on request, in 'Header: Value' format, similar to curl (default [])
95
+ --hooks-health-threshold int hours required to pass since last successful execution to consider job unhealthy (default 48)
93
96
  --hooks-health-url string external endpoint to call with list of unhealthy jobs
94
97
  --http-proxy string HTTP client proxy (for example, you can use mitm for local development)
95
98
  --http-timeout int Request timeout in seconds (default 60)
@@ -224,11 +227,11 @@ Below is the list of endpoints exposed by gorge server. You can use `request.htt
224
227
  },
225
228
  "status": {
226
229
  // information about running job
227
- "success": true, // whether latest execution was successful
228
- "timestamp": "2020-02-25T17:44:00Z", // latest execution timestamp
230
+ "lastRun": "2020-02-25T17:44:00Z", // latest execution timestamp
231
+ "lastSuccess": "2020-02-25T17:44:00Z", // latest successful (>0 measurements harvested) execution timestamp (optional)
229
232
  "count": 10, // number of measurements harvested during latest execution
230
- "next": "2020-02-25T17:46:00Z", // next execution timestamp
231
- "error": "somethin went wrong" // latest execution error, omitted when success = true
233
+ "nextRun": "2020-02-25T17:46:00Z", // next execution timestamp
234
+ "error": "somethin went wrong" // latest execution error (optional)
232
235
  }
233
236
  }
234
237
  ]
@@ -269,10 +272,10 @@ Below is the list of endpoints exposed by gorge server. You can use `request.htt
269
272
  [
270
273
  {
271
274
  "010802": {
272
- "success": false,
273
- "timestamp": "2020-02-24T18:00:00Z",
274
- "count": 0,
275
- "next": "2020-02-25T18:00:00Z"
275
+ "lastRun": "2020-02-24T18:00:00Z",
276
+ "lastSuccess": "2020-02-24T18:00:00Z",
277
+ "count": 10,
278
+ "nextRun": "2020-02-25T18:00:00Z"
276
279
  }
277
280
  ]
278
281
  ```
@@ -352,6 +355,48 @@ Below is the list of endpoints exposed by gorge server. You can use `request.htt
352
355
 
353
356
  List of available scripts is [here](scripts/README.md)
354
357
 
358
+ ### Health notifications
359
+
360
+ Gorge can call your webhooks when some of the running scripts haven't harvested any data for a period of time.
361
+
362
+ To configure healthcheck, use `--health--xxx` cli arguments. For example:
363
+
364
+ ```yml
365
+ command:
366
+ [
367
+
368
+ '--hooks-health-cron',
369
+ '0 0 * * *', # check health every midnight
370
+
371
+ '--hooks-health-threshold',
372
+ '48', # scripts that haven't harvested anything within last 48 hours are considered unhealthy
373
+
374
+ '--hooks-health-url',
375
+ 'http://host.docker.internal:3333/gorge/health', # so POST request will be made to this endpoint
376
+
377
+ '--hooks-health-headers',
378
+ 'x-api-key: __test_gorge_health_key__', # multiple headers can be set on this request
379
+ ]
380
+ ```
381
+
382
+ Example of this POST request payload:
383
+
384
+ ```json
385
+ [
386
+ {
387
+ "id": "2f915d20-ffe6-11e8-8919-9f370230d1ae",
388
+ "script": "chile",
389
+ "lastRun": "2021-12-13T07:57:59Z"
390
+ },
391
+ {
392
+ "id": "e3c0c89a-7c72-11e9-8abd-cfc3ab2b843d",
393
+ "script": "quebec",
394
+ "lastRun": "2021-12-13T07:57:00Z",
395
+ "lastSuccess": "2021-12-10T09:22:00Z"
396
+ }
397
+ ]
398
+ ```
399
+
355
400
  ### Other
356
401
 
357
402
  There're Typescript type definitions for the API available on [NPM](https://www.npmjs.com/package/@whitewater-guide/gorge)
@@ -418,7 +463,6 @@ Here are some recommendations for writing scripts for new sources
418
463
 
419
464
  ## TODO
420
465
 
421
- - Notify when some script seem to be broken
422
466
  - Virtual gauges
423
467
  - Statuses
424
468
  - What happens when one component is broken?
package/index.d.ts CHANGED
@@ -41,8 +41,8 @@ export interface JobDescription {
41
41
  export interface UnhealthyJob {
42
42
  id: string;
43
43
  script: string;
44
- last_run: string;
45
- last_success?: string;
44
+ lastRun: string;
45
+ lastSuccess?: string;
46
46
  }
47
47
  export interface ScriptDescriptor {
48
48
  name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitewater-guide/gorge",
3
- "version": "3.0.0-beta.1",
3
+ "version": "3.0.0-beta.5",
4
4
  "description": "Hydrological data harvester",
5
5
  "main": "",
6
6
  "types": "index",