@whitewater-guide/gorge 2.4.0-beta.8 → 3.0.0-beta.4

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 +74 -28
  2. package/index.d.ts +9 -3
  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
@@ -84,24 +85,28 @@ command:
84
85
  Here is the list of available flags:
85
86
 
86
87
  ```
87
- --cache string Either 'inmemory' or 'redis' (default "redis")
88
- --db string Either 'inmemory' or 'postgres' (default "postgres")
89
- --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
- --debug Enables debug mode, sets log level to debug
91
- --endpoint string Endpoint path (default "/")
92
- --http-proxy string HTTP client proxy (for example, you can use mitm for local development)
93
- --http-timeout int Request timeout in seconds (default 60)
94
- --http-user-agent string User agent for requests sent from scripts. Leave empty to use fake browser agent (default "whitewater.guide robot")
95
- --http-without-tls Disable TLS for some gauges
96
- --log-format string Set this to 'json' to output log in json (default "json")
97
- --log-level string Log level. Leave empty to discard logs (default "info")
98
- --pg-db string Postgres database (default "postgres")
99
- --pg-host string Postgres host (default "db")
100
- --pg-password string Postgres password [env POSTGRES_PASSWORD]
101
- --pg-user string Postgres user (default "postgres")
102
- --port string Port (default "7080")
103
- --redis-host string Redis host (default "redis")
104
- --redis-port string Redis port (default "6379")
88
+ --cache string either 'inmemory' or 'redis' (default "redis")
89
+ --db string either 'inmemory' or 'postgres' (default "postgres")
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
91
+ --debug enables debug mode, sets log level to debug
92
+ --endpoint string endpoint path (default "/")
93
+ --hooks-health-cron string cron expression for running health notifier (default "0 0 * * *")
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)
96
+ --hooks-health-url string external endpoint to call with list of unhealthy jobs
97
+ --http-proxy string HTTP client proxy (for example, you can use mitm for local development)
98
+ --http-timeout int Request timeout in seconds (default 60)
99
+ --http-user-agent string User agent for requests sent from scripts. Leave empty to use fake browser agent (default "whitewater.guide robot")
100
+ --http-without-tls Disable TLS for some gauges
101
+ --log-format string set this to 'json' to output log in json (default "json")
102
+ --log-level string log level. Leave empty to discard logs (default "info")
103
+ --pg-db string postgres database (default "postgres")
104
+ --pg-host string postgres host (default "db")
105
+ --pg-password string postgres password [env POSTGRES_PASSWORD]
106
+ --pg-user string postgres user (default "postgres")
107
+ --port string port (default "7080")
108
+ --redis-host string redis host (default "redis")
109
+ --redis-port string redis port (default "6379")
105
110
  ```
106
111
 
107
112
  Gorge uses database to store harvested measurements and scheduled jobs. It comes with postgres and sqlite drivers. Gorge will initialize all the required tables. Check out sql migration file if you're curious about db schema.
@@ -222,11 +227,11 @@ Below is the list of endpoints exposed by gorge server. You can use `request.htt
222
227
  },
223
228
  "status": {
224
229
  // information about running job
225
- "success": true, // whether latest execution was successful
226
- "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)
227
232
  "count": 10, // number of measurements harvested during latest execution
228
- "next": "2020-02-25T17:46:00Z", // next execution timestamp
229
- "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)
230
235
  }
231
236
  }
232
237
  ]
@@ -267,10 +272,10 @@ Below is the list of endpoints exposed by gorge server. You can use `request.htt
267
272
  [
268
273
  {
269
274
  "010802": {
270
- "success": false,
271
- "timestamp": "2020-02-24T18:00:00Z",
272
- "count": 0,
273
- "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"
274
279
  }
275
280
  ]
276
281
  ```
@@ -350,6 +355,48 @@ Below is the list of endpoints exposed by gorge server. You can use `request.htt
350
355
 
351
356
  List of available scripts is [here](scripts/README.md)
352
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
+
353
400
  ### Other
354
401
 
355
402
  There're Typescript type definitions for the API available on [NPM](https://www.npmjs.com/package/@whitewater-guide/gorge)
@@ -416,7 +463,6 @@ Here are some recommendations for writing scripts for new sources
416
463
 
417
464
  ## TODO
418
465
 
419
- - Notify when some script seem to be broken
420
466
  - Virtual gauges
421
467
  - Statuses
422
468
  - What happens when one component is broken?
package/index.d.ts CHANGED
@@ -24,11 +24,11 @@ export interface Measurement {
24
24
  flow: number | null;
25
25
  }
26
26
  export interface Status {
27
- success: boolean;
28
- timestamp: string;
27
+ lastRun: string;
29
28
  error?: string;
30
29
  count: number;
31
- next?: string;
30
+ lastSuccess?: string;
31
+ nextRun?: string;
32
32
  }
33
33
  export interface JobDescription {
34
34
  id: string;
@@ -38,6 +38,12 @@ export interface JobDescription {
38
38
  options: {[key: string]: any} | null;
39
39
  status?: Status;
40
40
  }
41
+ export interface UnhealthyJob {
42
+ id: string;
43
+ script: string;
44
+ lastRun: string;
45
+ lastSuccess?: string;
46
+ }
41
47
  export interface ScriptDescriptor {
42
48
  name: string;
43
49
  description: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whitewater-guide/gorge",
3
- "version": "2.4.0-beta.8",
3
+ "version": "3.0.0-beta.4",
4
4
  "description": "Hydrological data harvester",
5
5
  "main": "",
6
6
  "types": "index",