@flowrensic/temporal-flowrensic-node-sdk 0.0.0-stage → 0.6.63
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 +149 -2
- package/dist/cjs/ci.d.ts +47 -0
- package/dist/cjs/ci.d.ts.map +1 -0
- package/dist/cjs/ci.js +70 -0
- package/dist/cjs/ci.js.map +1 -0
- package/dist/cjs/client-interceptor.d.ts +46 -0
- package/dist/cjs/client-interceptor.d.ts.map +1 -0
- package/dist/cjs/client-interceptor.js +129 -0
- package/dist/cjs/client-interceptor.js.map +1 -0
- package/dist/cjs/client.d.ts +44 -0
- package/dist/cjs/client.d.ts.map +1 -0
- package/dist/cjs/client.js +77 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/activity_metrics_pb.d.ts +702 -0
- package/dist/cjs/gen/flowrensic/v1/activity_metrics_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/activity_metrics_pb.js +123 -0
- package/dist/cjs/gen/flowrensic/v1/activity_metrics_pb.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/catalog_pb.d.ts +314 -0
- package/dist/cjs/gen/flowrensic/v1/catalog_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/catalog_pb.js +92 -0
- package/dist/cjs/gen/flowrensic/v1/catalog_pb.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/catch_up_pb.d.ts +180 -0
- package/dist/cjs/gen/flowrensic/v1/catch_up_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/catch_up_pb.js +29 -0
- package/dist/cjs/gen/flowrensic/v1/catch_up_pb.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/client_calls_pb.d.ts +216 -0
- package/dist/cjs/gen/flowrensic/v1/client_calls_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/client_calls_pb.js +69 -0
- package/dist/cjs/gen/flowrensic/v1/client_calls_pb.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/cost_pb.d.ts +257 -0
- package/dist/cjs/gen/flowrensic/v1/cost_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/cost_pb.js +54 -0
- package/dist/cjs/gen/flowrensic/v1/cost_pb.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/deploy_pb.d.ts +222 -0
- package/dist/cjs/gen/flowrensic/v1/deploy_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/deploy_pb.js +53 -0
- package/dist/cjs/gen/flowrensic/v1/deploy_pb.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/ephemeral_run_pb.d.ts +850 -0
- package/dist/cjs/gen/flowrensic/v1/ephemeral_run_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/ephemeral_run_pb.js +170 -0
- package/dist/cjs/gen/flowrensic/v1/ephemeral_run_pb.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/finding_pb.d.ts +896 -0
- package/dist/cjs/gen/flowrensic/v1/finding_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/finding_pb.js +451 -0
- package/dist/cjs/gen/flowrensic/v1/finding_pb.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/job_pb.d.ts +104 -0
- package/dist/cjs/gen/flowrensic/v1/job_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/job_pb.js +28 -0
- package/dist/cjs/gen/flowrensic/v1/job_pb.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/load_pb.d.ts +333 -0
- package/dist/cjs/gen/flowrensic/v1/load_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/load_pb.js +53 -0
- package/dist/cjs/gen/flowrensic/v1/load_pb.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/page_pb.d.ts +67 -0
- package/dist/cjs/gen/flowrensic/v1/page_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/page_pb.js +22 -0
- package/dist/cjs/gen/flowrensic/v1/page_pb.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/remediation_pb.d.ts +395 -0
- package/dist/cjs/gen/flowrensic/v1/remediation_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/remediation_pb.js +103 -0
- package/dist/cjs/gen/flowrensic/v1/remediation_pb.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/replay_pb.d.ts +805 -0
- package/dist/cjs/gen/flowrensic/v1/replay_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/replay_pb.js +179 -0
- package/dist/cjs/gen/flowrensic/v1/replay_pb.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/server_config_pb.d.ts +220 -0
- package/dist/cjs/gen/flowrensic/v1/server_config_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/server_config_pb.js +44 -0
- package/dist/cjs/gen/flowrensic/v1/server_config_pb.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/services_pb.d.ts +561 -0
- package/dist/cjs/gen/flowrensic/v1/services_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/services_pb.js +59 -0
- package/dist/cjs/gen/flowrensic/v1/services_pb.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/stored_data_pb.d.ts +120 -0
- package/dist/cjs/gen/flowrensic/v1/stored_data_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/stored_data_pb.js +33 -0
- package/dist/cjs/gen/flowrensic/v1/stored_data_pb.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/workflow_history_pb.d.ts +204 -0
- package/dist/cjs/gen/flowrensic/v1/workflow_history_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/workflow_history_pb.js +135 -0
- package/dist/cjs/gen/flowrensic/v1/workflow_history_pb.js.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/workflow_types_pb.d.ts +505 -0
- package/dist/cjs/gen/flowrensic/v1/workflow_types_pb.d.ts.map +1 -0
- package/dist/cjs/gen/flowrensic/v1/workflow_types_pb.js +56 -0
- package/dist/cjs/gen/flowrensic/v1/workflow_types_pb.js.map +1 -0
- package/dist/cjs/index.d.ts +29 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +49 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/interceptor-names.d.ts +11 -0
- package/dist/cjs/interceptor-names.d.ts.map +1 -0
- package/dist/cjs/interceptor-names.js +27 -0
- package/dist/cjs/interceptor-names.js.map +1 -0
- package/dist/cjs/interceptor.d.ts +39 -0
- package/dist/cjs/interceptor.d.ts.map +1 -0
- package/dist/cjs/interceptor.js +113 -0
- package/dist/cjs/interceptor.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/query-sink.d.ts +31 -0
- package/dist/cjs/query-sink.d.ts.map +1 -0
- package/dist/cjs/query-sink.js +64 -0
- package/dist/cjs/query-sink.js.map +1 -0
- package/dist/cjs/replay.d.ts +119 -0
- package/dist/cjs/replay.d.ts.map +1 -0
- package/dist/cjs/replay.js +204 -0
- package/dist/cjs/replay.js.map +1 -0
- package/dist/cjs/sink.d.ts +79 -0
- package/dist/cjs/sink.d.ts.map +1 -0
- package/dist/cjs/sink.js +320 -0
- package/dist/cjs/sink.js.map +1 -0
- package/dist/cjs/telemetry.d.ts +128 -0
- package/dist/cjs/telemetry.d.ts.map +1 -0
- package/dist/cjs/telemetry.js +420 -0
- package/dist/cjs/telemetry.js.map +1 -0
- package/dist/cjs/workflow.d.ts +15 -0
- package/dist/cjs/workflow.d.ts.map +1 -0
- package/dist/cjs/workflow.js +39 -0
- package/dist/cjs/workflow.js.map +1 -0
- package/dist/esm/ci.d.ts +47 -0
- package/dist/esm/ci.d.ts.map +1 -0
- package/dist/esm/ci.js +64 -0
- package/dist/esm/ci.js.map +1 -0
- package/dist/esm/client-interceptor.d.ts +46 -0
- package/dist/esm/client-interceptor.d.ts.map +1 -0
- package/dist/esm/client-interceptor.js +124 -0
- package/dist/esm/client-interceptor.js.map +1 -0
- package/dist/esm/client.d.ts +44 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +69 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/activity_metrics_pb.d.ts +702 -0
- package/dist/esm/gen/flowrensic/v1/activity_metrics_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/activity_metrics_pb.js +120 -0
- package/dist/esm/gen/flowrensic/v1/activity_metrics_pb.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/catalog_pb.d.ts +314 -0
- package/dist/esm/gen/flowrensic/v1/catalog_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/catalog_pb.js +89 -0
- package/dist/esm/gen/flowrensic/v1/catalog_pb.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/catch_up_pb.d.ts +180 -0
- package/dist/esm/gen/flowrensic/v1/catch_up_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/catch_up_pb.js +26 -0
- package/dist/esm/gen/flowrensic/v1/catch_up_pb.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/client_calls_pb.d.ts +216 -0
- package/dist/esm/gen/flowrensic/v1/client_calls_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/client_calls_pb.js +66 -0
- package/dist/esm/gen/flowrensic/v1/client_calls_pb.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/cost_pb.d.ts +257 -0
- package/dist/esm/gen/flowrensic/v1/cost_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/cost_pb.js +51 -0
- package/dist/esm/gen/flowrensic/v1/cost_pb.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/deploy_pb.d.ts +222 -0
- package/dist/esm/gen/flowrensic/v1/deploy_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/deploy_pb.js +50 -0
- package/dist/esm/gen/flowrensic/v1/deploy_pb.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/ephemeral_run_pb.d.ts +850 -0
- package/dist/esm/gen/flowrensic/v1/ephemeral_run_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/ephemeral_run_pb.js +167 -0
- package/dist/esm/gen/flowrensic/v1/ephemeral_run_pb.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/finding_pb.d.ts +896 -0
- package/dist/esm/gen/flowrensic/v1/finding_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/finding_pb.js +448 -0
- package/dist/esm/gen/flowrensic/v1/finding_pb.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/job_pb.d.ts +104 -0
- package/dist/esm/gen/flowrensic/v1/job_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/job_pb.js +25 -0
- package/dist/esm/gen/flowrensic/v1/job_pb.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/load_pb.d.ts +333 -0
- package/dist/esm/gen/flowrensic/v1/load_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/load_pb.js +50 -0
- package/dist/esm/gen/flowrensic/v1/load_pb.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/page_pb.d.ts +67 -0
- package/dist/esm/gen/flowrensic/v1/page_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/page_pb.js +19 -0
- package/dist/esm/gen/flowrensic/v1/page_pb.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/remediation_pb.d.ts +395 -0
- package/dist/esm/gen/flowrensic/v1/remediation_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/remediation_pb.js +100 -0
- package/dist/esm/gen/flowrensic/v1/remediation_pb.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/replay_pb.d.ts +805 -0
- package/dist/esm/gen/flowrensic/v1/replay_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/replay_pb.js +176 -0
- package/dist/esm/gen/flowrensic/v1/replay_pb.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/server_config_pb.d.ts +220 -0
- package/dist/esm/gen/flowrensic/v1/server_config_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/server_config_pb.js +41 -0
- package/dist/esm/gen/flowrensic/v1/server_config_pb.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/services_pb.d.ts +561 -0
- package/dist/esm/gen/flowrensic/v1/services_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/services_pb.js +56 -0
- package/dist/esm/gen/flowrensic/v1/services_pb.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/stored_data_pb.d.ts +120 -0
- package/dist/esm/gen/flowrensic/v1/stored_data_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/stored_data_pb.js +30 -0
- package/dist/esm/gen/flowrensic/v1/stored_data_pb.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/workflow_history_pb.d.ts +204 -0
- package/dist/esm/gen/flowrensic/v1/workflow_history_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/workflow_history_pb.js +132 -0
- package/dist/esm/gen/flowrensic/v1/workflow_history_pb.js.map +1 -0
- package/dist/esm/gen/flowrensic/v1/workflow_types_pb.d.ts +505 -0
- package/dist/esm/gen/flowrensic/v1/workflow_types_pb.d.ts.map +1 -0
- package/dist/esm/gen/flowrensic/v1/workflow_types_pb.js +53 -0
- package/dist/esm/gen/flowrensic/v1/workflow_types_pb.js.map +1 -0
- package/dist/esm/index.d.ts +29 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/interceptor-names.d.ts +11 -0
- package/dist/esm/interceptor-names.d.ts.map +1 -0
- package/dist/esm/interceptor-names.js +23 -0
- package/dist/esm/interceptor-names.js.map +1 -0
- package/dist/esm/interceptor.d.ts +39 -0
- package/dist/esm/interceptor.d.ts.map +1 -0
- package/dist/esm/interceptor.js +108 -0
- package/dist/esm/interceptor.js.map +1 -0
- package/dist/esm/query-sink.d.ts +31 -0
- package/dist/esm/query-sink.d.ts.map +1 -0
- package/dist/esm/query-sink.js +61 -0
- package/dist/esm/query-sink.js.map +1 -0
- package/dist/esm/replay.d.ts +119 -0
- package/dist/esm/replay.d.ts.map +1 -0
- package/dist/esm/replay.js +197 -0
- package/dist/esm/replay.js.map +1 -0
- package/dist/esm/sink.d.ts +79 -0
- package/dist/esm/sink.d.ts.map +1 -0
- package/dist/esm/sink.js +315 -0
- package/dist/esm/sink.js.map +1 -0
- package/dist/esm/telemetry.d.ts +128 -0
- package/dist/esm/telemetry.d.ts.map +1 -0
- package/dist/esm/telemetry.js +414 -0
- package/dist/esm/telemetry.js.map +1 -0
- package/dist/esm/workflow.d.ts +15 -0
- package/dist/esm/workflow.d.ts.map +1 -0
- package/dist/esm/workflow.js +35 -0
- package/dist/esm/workflow.js.map +1 -0
- package/package.json +75 -4
package/README.md
CHANGED
|
@@ -1,3 +1,150 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @flowrensic/temporal-flowrensic-node-sdk
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
Pre-release. This package is an early preview and not ready for production. Its API can change in any version.
|
|
4
|
+
|
|
5
|
+
Replay the histories your workflows already produced, against the code you are
|
|
6
|
+
about to ship.
|
|
7
|
+
|
|
8
|
+
Flowrensic keeps what a Temporal Engine recorded. This package fetches a set to
|
|
9
|
+
disk and reports back what your replay found. The replay itself stays yours:
|
|
10
|
+
call Temporal's replayer directly, in your suite, with your own bundler options.
|
|
11
|
+
Histories in a repo go stale on the next deploy and nobody can say which are
|
|
12
|
+
still safe to delete.
|
|
13
|
+
|
|
14
|
+
Server: `flowrensic/temporal-flowrensic` on Docker Hub. Temporal is the supported engine.
|
|
15
|
+
|
|
16
|
+
## Who the caller is
|
|
17
|
+
|
|
18
|
+
Every call to Flowrensic says who sends it, in three headers:
|
|
19
|
+
`Flowrensic-Current-Env`, `Flowrensic-Env-Access-Key` and
|
|
20
|
+
`Flowrensic-Current-Ephemeral-Run`. Each helper here takes them as the options
|
|
21
|
+
`currentEnv`, `envAccessKey` and `currentEphemeralRun`, beside `serverBaseUrl`.
|
|
22
|
+
The package reads no environment variable: pass the values from your own
|
|
23
|
+
config. An env of kind ephemeral takes `currentEphemeralRun`, such as the
|
|
24
|
+
CI build number, and without one the run is default.
|
|
25
|
+
|
|
26
|
+
## Replay
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { fetchReplaySet, publishVerdicts, readReplaySet } from '@flowrensic/temporal-flowrensic-node-sdk';
|
|
30
|
+
import { historyFromJSON } from '@temporalio/common/lib/proto-utils.js';
|
|
31
|
+
import { Worker } from '@temporalio/worker';
|
|
32
|
+
|
|
33
|
+
await fetchReplaySet({
|
|
34
|
+
serverBaseUrl: 'http://flowrensic:8080',
|
|
35
|
+
replayHistoryWorkflow: 'OrderWorkflow',
|
|
36
|
+
replayHistoryOutDir: 'replay-set',
|
|
37
|
+
replayHistoryFromEnvs: ['prod', 'staging'],
|
|
38
|
+
currentEnv: 'ci',
|
|
39
|
+
envAccessKey: config.envAccessKey,
|
|
40
|
+
currentEphemeralRun: config.buildNumber,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const set = await readReplaySet('replay-set');
|
|
44
|
+
const histories = await Promise.all(
|
|
45
|
+
set.histories.map(async (entry) => ({
|
|
46
|
+
workflowId: entry.run_id,
|
|
47
|
+
history: historyFromJSON(JSON.parse(await readFile(join('replay-set', entry.file), 'utf8'))),
|
|
48
|
+
})),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const verdicts = [];
|
|
52
|
+
for await (const result of Worker.runReplayHistories({ workflowsPath }, histories)) {
|
|
53
|
+
verdicts.push({
|
|
54
|
+
runId: result.workflowId,
|
|
55
|
+
workflowType: set.workflow_type,
|
|
56
|
+
passed: result.error === undefined,
|
|
57
|
+
error: result.error?.message,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
await publishVerdicts({
|
|
62
|
+
serverBaseUrl: 'http://flowrensic:8080',
|
|
63
|
+
codeVersion: config.gitSha,
|
|
64
|
+
verdicts,
|
|
65
|
+
currentEnv: 'ci',
|
|
66
|
+
envAccessKey: config.envAccessKey,
|
|
67
|
+
currentEphemeralRun: config.buildNumber,
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The set holds the histories of each env named, one env after the other, and
|
|
72
|
+
`replay-set.json` lists the envs and gives each history its env. Each env named
|
|
73
|
+
must be the current env or one its entry in FLOWRENSIC_KNOWN_ENVS may read.
|
|
74
|
+
The current env must be of kind ephemeral: every fetch belongs to an ephemeral
|
|
75
|
+
run, and a persistent env is refused.
|
|
76
|
+
|
|
77
|
+
Verdicts go back against the run and the version, so a break points at the
|
|
78
|
+
change that caused it.
|
|
79
|
+
|
|
80
|
+
`temporal-flowrensic replay fetch` in the CLI writes the same directory and the same
|
|
81
|
+
manifest, for a pipeline that would rather fetch in a step than in a test.
|
|
82
|
+
|
|
83
|
+
The server picks the set: recent histories, versions still running somewhere,
|
|
84
|
+
outcomes that differ. Newest-ten on a healthy workflow type is ten completions
|
|
85
|
+
and not one failure.
|
|
86
|
+
|
|
87
|
+
## Activity telemetry
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { createAttemptSink, flowrensicInterceptor } from '@flowrensic/temporal-flowrensic-node-sdk';
|
|
91
|
+
|
|
92
|
+
const sink = createAttemptSink({ serverBaseUrl: 'http://flowrensic:8080', currentEnv: 'prod', envAccessKey, workerName: 'orders-worker' });
|
|
93
|
+
|
|
94
|
+
const worker = await Worker.create({
|
|
95
|
+
// ...
|
|
96
|
+
interceptors: { activity: [flowrensicInterceptor(sink)] },
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
workerName names the worker, the same name for every copy of it. The Workflow
|
|
101
|
+
types page shows it beside each type the worker runs, with the task queue, and
|
|
102
|
+
can filter by it. Left out, the worker has no name.
|
|
103
|
+
|
|
104
|
+
One event per attempt, not per activity: the gap between the two is the retry
|
|
105
|
+
count. Each attempt carries the namespace Temporal gives the activity, and the
|
|
106
|
+
server keeps the namespaces of each environment apart. There is no namespace
|
|
107
|
+
setting.
|
|
108
|
+
|
|
109
|
+
Activity inbound only, and publishing failures are swallowed. Telemetry must
|
|
110
|
+
never fail the activity it measures.
|
|
111
|
+
|
|
112
|
+
## Query and signal counts
|
|
113
|
+
|
|
114
|
+
The Workflow types page counts the queries each workflow type answers. The
|
|
115
|
+
worker needs the workflow module and the sinks:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import { createRequire } from 'node:module';
|
|
119
|
+
import { flowrensicQuerySinks } from '@flowrensic/temporal-flowrensic-node-sdk';
|
|
120
|
+
|
|
121
|
+
const queries = flowrensicQuerySinks({ serverBaseUrl: 'http://flowrensic:8080', currentEnv: 'prod', envAccessKey });
|
|
122
|
+
|
|
123
|
+
const worker = await Worker.create({
|
|
124
|
+
// ...
|
|
125
|
+
interceptors: {
|
|
126
|
+
activity: [flowrensicInterceptor(sink)],
|
|
127
|
+
workflowModules: [createRequire(import.meta.url).resolve('@flowrensic/temporal-flowrensic-node-sdk/workflow')],
|
|
128
|
+
},
|
|
129
|
+
sinks: queries.sinks,
|
|
130
|
+
});
|
|
131
|
+
// Before the process ends:
|
|
132
|
+
await queries.buffer.close();
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The client interceptor sends the queries and signals that fail or get no
|
|
136
|
+
answer. Put it in the plugins of the client, so it reads the namespace of the
|
|
137
|
+
client:
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
const interceptor = flowrensicClientInterceptor({ serverBaseUrl: 'http://flowrensic:8080', currentEnv: 'prod', envAccessKey });
|
|
141
|
+
const client = new Client({ connection, namespace: 'orders', plugins: [interceptor] });
|
|
142
|
+
// Before the process ends:
|
|
143
|
+
await interceptor.close();
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Peers
|
|
147
|
+
|
|
148
|
+
`@temporalio/worker`, `@temporalio/common`, `@temporalio/activity`,
|
|
149
|
+
`@temporalio/workflow`, 1.24 or newer, for the interceptors. The replay runs on your SDK, not on one this
|
|
150
|
+
package pins.
|
package/dist/cjs/ci.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Whether a call failed because nothing answered in time or no connection could be made. */
|
|
2
|
+
export declare function notReached(error: unknown): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* The message a CI call stops with: that Flowrensic could not be reached in
|
|
5
|
+
* time, or what it answered, the code in brackets as Connect writes it and the
|
|
6
|
+
* message. what names the call, such as deploy report.
|
|
7
|
+
*/
|
|
8
|
+
export declare function ciFailure(what: string, serverBaseUrl: string, timeoutMs: number, error: unknown): string;
|
|
9
|
+
/**
|
|
10
|
+
* The error a CI call that has to fail throws. An answer of Flowrensic is
|
|
11
|
+
* passed on as the ConnectError it is, whose text is the code in brackets and
|
|
12
|
+
* the message, so a caller can still read its code. Anything else gets the
|
|
13
|
+
* message that says Flowrensic could not be reached.
|
|
14
|
+
*/
|
|
15
|
+
export declare function ciError(what: string, serverBaseUrl: string, timeoutMs: number, error: unknown): Error;
|
|
16
|
+
export interface DeployStageOptions {
|
|
17
|
+
/** The Flowrensic server to send to. */
|
|
18
|
+
serverBaseUrl: string;
|
|
19
|
+
/** The env of the deploy, sent in the header Flowrensic-Current-Env. */
|
|
20
|
+
currentEnv: string;
|
|
21
|
+
/** The access key of the env. */
|
|
22
|
+
envAccessKey: string;
|
|
23
|
+
/** The ephemeral run of the env, such as the CI build number. For an env of kind ephemeral, without one the run is default. */
|
|
24
|
+
currentEphemeralRun?: string;
|
|
25
|
+
deployId: string;
|
|
26
|
+
/** initiated, started, replay, testsStarted, testsDone or finished. */
|
|
27
|
+
stage: string;
|
|
28
|
+
declaredStages?: readonly string[];
|
|
29
|
+
rollingOutVersion?: string;
|
|
30
|
+
outcome?: string;
|
|
31
|
+
/** How long the report may take, in milliseconds. Left out, 10 seconds. */
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Whether a report that failed rejects, so the CI job fails. Left out,
|
|
35
|
+
* false: the report resolves with sent false and the message.
|
|
36
|
+
*/
|
|
37
|
+
failOnError?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface DeployStageResult {
|
|
40
|
+
/** Whether Flowrensic took the write. */
|
|
41
|
+
readonly sent: boolean;
|
|
42
|
+
/** What happened, in one line, for the CI log. */
|
|
43
|
+
readonly message: string;
|
|
44
|
+
}
|
|
45
|
+
/** Sends one stage of a deploy to Flowrensic, with a time limit, and never hangs. */
|
|
46
|
+
export declare function reportDeployStage(options: DeployStageOptions): Promise<DeployStageResult>;
|
|
47
|
+
//# sourceMappingURL=ci.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ci.d.ts","sourceRoot":"","sources":["../../src/ci.ts"],"names":[],"mappings":"AASA,6FAA6F;AAC7F,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAKlD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAOxG;AAED;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,CAGrG;AAED,MAAM,WAAW,kBAAkB;IACjC,wCAAwC;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,wEAAwE;IACxE,UAAU,EAAE,MAAM,CAAC;IACnB,iCAAiC;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,+HAA+H;IAC/H,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,yCAAyC;IACzC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,kDAAkD;IAClD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAID,qFAAqF;AACrF,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAqB/F"}
|
package/dist/cjs/ci.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.notReached = notReached;
|
|
4
|
+
exports.ciFailure = ciFailure;
|
|
5
|
+
exports.ciError = ciError;
|
|
6
|
+
exports.reportDeployStage = reportDeployStage;
|
|
7
|
+
const connect_1 = require("@connectrpc/connect");
|
|
8
|
+
const client_js_1 = require("./client.js");
|
|
9
|
+
/** The name Connect gives a code on the wire, such as failed_precondition. */
|
|
10
|
+
function codeName(code) {
|
|
11
|
+
return connect_1.Code[code].replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
|
|
12
|
+
}
|
|
13
|
+
/** Whether a call failed because nothing answered in time or no connection could be made. */
|
|
14
|
+
function notReached(error) {
|
|
15
|
+
if (!(error instanceof connect_1.ConnectError))
|
|
16
|
+
return true;
|
|
17
|
+
if (error.code === connect_1.Code.DeadlineExceeded || error.code === connect_1.Code.Canceled)
|
|
18
|
+
return true;
|
|
19
|
+
const cause = error.cause;
|
|
20
|
+
return typeof cause === 'object' && cause !== null && 'code' in cause && typeof cause.code === 'string' && /^E[A-Z]+$/.test(cause.code);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The message a CI call stops with: that Flowrensic could not be reached in
|
|
24
|
+
* time, or what it answered, the code in brackets as Connect writes it and the
|
|
25
|
+
* message. what names the call, such as deploy report.
|
|
26
|
+
*/
|
|
27
|
+
function ciFailure(what, serverBaseUrl, timeoutMs, error) {
|
|
28
|
+
if (notReached(error)) {
|
|
29
|
+
const cause = error instanceof connect_1.ConnectError ? error.rawMessage : error instanceof Error ? error.message : String(error);
|
|
30
|
+
return `${what}: Flowrensic at ${serverBaseUrl} could not be reached within ${String(timeoutMs / 1000)} seconds: ${cause}`;
|
|
31
|
+
}
|
|
32
|
+
if (!(error instanceof connect_1.ConnectError))
|
|
33
|
+
return `${what}: Flowrensic at ${serverBaseUrl} failed: ${String(error)}`;
|
|
34
|
+
return `${what}: Flowrensic at ${serverBaseUrl} answered [${codeName(error.code)}] ${error.rawMessage}`;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The error a CI call that has to fail throws. An answer of Flowrensic is
|
|
38
|
+
* passed on as the ConnectError it is, whose text is the code in brackets and
|
|
39
|
+
* the message, so a caller can still read its code. Anything else gets the
|
|
40
|
+
* message that says Flowrensic could not be reached.
|
|
41
|
+
*/
|
|
42
|
+
function ciError(what, serverBaseUrl, timeoutMs, error) {
|
|
43
|
+
if (error instanceof connect_1.ConnectError && !notReached(error))
|
|
44
|
+
return error;
|
|
45
|
+
return new Error(ciFailure(what, serverBaseUrl, timeoutMs, error), { cause: error });
|
|
46
|
+
}
|
|
47
|
+
const deployReportTimeoutMs = 10_000;
|
|
48
|
+
/** Sends one stage of a deploy to Flowrensic, with a time limit, and never hangs. */
|
|
49
|
+
async function reportDeployStage(options) {
|
|
50
|
+
const { serverBaseUrl, deployId, stage } = options;
|
|
51
|
+
const timeoutMs = options.timeoutMs ?? deployReportTimeoutMs;
|
|
52
|
+
const client = (0, client_js_1.createFlowrensicClient)(serverBaseUrl, (0, client_js_1.contextOf)(options));
|
|
53
|
+
try {
|
|
54
|
+
await client.ingest.ingestDeployStage({
|
|
55
|
+
deployId,
|
|
56
|
+
stage,
|
|
57
|
+
declaredStages: [...(options.declaredStages ?? [])],
|
|
58
|
+
rollingOutVersion: options.rollingOutVersion ?? '',
|
|
59
|
+
outcome: options.outcome ?? '',
|
|
60
|
+
}, { timeoutMs });
|
|
61
|
+
return { sent: true, message: `deploy report: Flowrensic at ${serverBaseUrl} took the stage ${stage} of ${deployId}` };
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
const message = ciFailure('deploy report', serverBaseUrl, timeoutMs, error);
|
|
65
|
+
if (options.failOnError === true)
|
|
66
|
+
throw ciError('deploy report', serverBaseUrl, timeoutMs, error);
|
|
67
|
+
return { sent: false, message };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=ci.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ci.js","sourceRoot":"","sources":["../../src/ci.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAyD;AAEzD,2CAAgE;AAEhE,8EAA8E;AAC9E,SAAS,QAAQ,CAAC,IAAU;IAC1B,OAAO,cAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;AACtE,CAAC;AAED,6FAA6F;AAC7F,oBAA2B,KAAc;IACvC,IAAI,CAAC,CAAC,KAAK,YAAY,sBAAY,CAAC;QAAE,OAAO,IAAI,CAAC;IAClD,IAAI,KAAK,CAAC,IAAI,KAAK,cAAI,CAAC,gBAAgB,IAAI,KAAK,CAAC,IAAI,KAAK,cAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IACtF,MAAM,KAAK,GAAY,KAAK,CAAC,KAAK,CAAC;IACnC,OAAO,OAAO,KAAK,KAAK,QAA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qFAAqF;AAC9E,KAAK,4BAA4B,OAA2B;IACjE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IACnD,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,qBAAqB,CAAC;IAC7D,MAAM,MAAM,GAAG,IAAA,kCAAsB,EAAC,aAAa,EAAE,IAAA,qBAAS,EAAC,OAAO,CAAC,CAAC,CAAC;IACzE,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,MAAM,CAAC,iBAAiB,CACnC;YACE,QAAQ;YACR,KAAK;YACL,cAAc,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC;YACnD,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,IAAI,EAAE;YAClD,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;SAC/B,EACD,EAAE,SAAS,EAAE,CACd,CAAC;QACF,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,gCAAgC,aAAa,mBAAmB,KAAK,OAAO,QAAQ,EAAE,EAAE,CAAC;IACzH,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,MAAM,OAAO,GAAG,SAAS,CAAC,eAAe,EAAE,aAAa,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QAC5E,IAAI,OAAO,CAAC,WAAW,KAAK,IAAI;YAAE,MAAM,OAAO,CAAC,eAAe,EAAE,aAAa,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;QAClG,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IAClC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ClientOptions, ClientPlugin, WorkflowClientInterceptor, WorkflowQueryInput, WorkflowSignalInput } from '@temporalio/client';
|
|
2
|
+
import type { Next } from '@temporalio/common';
|
|
3
|
+
import { type ClientContext } from './client.js';
|
|
4
|
+
import { type BufferOptions, type SinkCounts } from './sink.js';
|
|
5
|
+
export interface ClientInterceptorOptions extends BufferOptions, ClientContext {
|
|
6
|
+
/** The Flowrensic server to send to. */
|
|
7
|
+
serverBaseUrl: string;
|
|
8
|
+
/** The env of the client, sent with its key and ephemeral run in the headers of every send. */
|
|
9
|
+
currentEnv: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Sends every query and signal that throws to Flowrensic, with its name, the
|
|
13
|
+
* workflow it was for and whether it ended on its deadline. A call that works
|
|
14
|
+
* is not sent. The calls wait in a buffer and are sent in batches, as the
|
|
15
|
+
* worker sink sends attempts, so sending never changes what the caller gets or
|
|
16
|
+
* how long it waits. It is a client plugin too: put in the plugins of the
|
|
17
|
+
* Temporal client, it reads the namespace of the client and puts itself in its
|
|
18
|
+
* workflow interceptors.
|
|
19
|
+
*/
|
|
20
|
+
export declare class FlowrensicClientInterceptor implements WorkflowClientInterceptor, ClientPlugin {
|
|
21
|
+
private readonly buffer;
|
|
22
|
+
private namespace;
|
|
23
|
+
/** The name of the plugin. */
|
|
24
|
+
readonly name: string;
|
|
25
|
+
constructor(options: ClientInterceptorOptions);
|
|
26
|
+
/** Reads the namespace of the client and adds this interceptor to its workflow interceptors. */
|
|
27
|
+
configureClient(options: Omit<ClientOptions, 'plugins'>): Omit<ClientOptions, 'plugins'>;
|
|
28
|
+
query(input: WorkflowQueryInput, next: Next<WorkflowClientInterceptor, 'query'>): Promise<unknown>;
|
|
29
|
+
signal(input: WorkflowSignalInput, next: Next<WorkflowClientInterceptor, 'signal'>): Promise<void>;
|
|
30
|
+
/** Send what is buffered and wait for it to land. */
|
|
31
|
+
flush(): Promise<void>;
|
|
32
|
+
/** Send what is buffered and stop. */
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
/** What the buffer lost and holds. */
|
|
35
|
+
counts(): SinkCounts;
|
|
36
|
+
/** Records a call that threw, and never throws itself, so the caller gets the error Temporal gave. */
|
|
37
|
+
private record;
|
|
38
|
+
private callOf;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Pass to `new Client({ namespace, plugins: [flowrensicClientInterceptor({ serverBaseUrl, currentEnv, envAccessKey })] })`.
|
|
42
|
+
* The calls are sent under the namespace of that client. Call close before the
|
|
43
|
+
* process ends, so the calls still waiting are sent.
|
|
44
|
+
*/
|
|
45
|
+
export declare function flowrensicClientInterceptor(options: ClientInterceptorOptions): FlowrensicClientInterceptor;
|
|
46
|
+
//# sourceMappingURL=client-interceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-interceptor.d.ts","sourceRoot":"","sources":["../../src/client-interceptor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC1I,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAqC,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAEpF,OAAO,EAAsB,KAAK,aAAa,EAAmB,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AASrG,MAAM,WAAW,wBAAyB,SAAQ,aAAa,EAAE,aAAa;IAC5E,wCAAwC;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,+FAA+F;IAC/F,UAAU,EAAE,MAAM,CAAC;CACpB;AA2BD;;;;;;;;GAQG;AACH,qBAAa,2BAA4B,YAAW,yBAAyB,EAAE,YAAY;IACzF,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAyB;IAChD,OAAO,CAAC,SAAS,CAAqB;IACtC,8BAA8B;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAuB;IAE5C,YAAY,OAAO,EAAE,wBAAwB,EAW5C;IAGD,gGAAgG;IAChG,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,GAAG,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,CAKvF;IAEK,KAAK,CAAC,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,IAAI,CAAC,yBAAyB,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAOvG;IAEK,MAAM,CAAC,KAAK,EAAE,mBAAmB,EAAE,IAAI,EAAE,IAAI,CAAC,yBAAyB,EAAE,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAOvG;IAED,qDAAqD;IAC/C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;IAED,sCAAsC;IAChC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAE3B;IAED,sCAAsC;IACtC,MAAM,IAAI,UAAU,CAEnB;IAED,sGAAsG;IACtG,OAAO,CAAC,MAAM;IAQd,OAAO,CAAC,MAAM;CAcf;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,wBAAwB,GAAG,2BAA2B,CAE1G"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FlowrensicClientInterceptor = void 0;
|
|
4
|
+
exports.flowrensicClientInterceptor = flowrensicClientInterceptor;
|
|
5
|
+
const wkt_1 = require("@bufbuild/protobuf/wkt");
|
|
6
|
+
const client_js_1 = require("./client.js");
|
|
7
|
+
const client_calls_pb_js_1 = require("./gen/flowrensic/v1/client_calls_pb.js");
|
|
8
|
+
const sink_js_1 = require("./sink.js");
|
|
9
|
+
/** The gRPC status a call that ended on its deadline carries. */
|
|
10
|
+
const DEADLINE_EXCEEDED = 4;
|
|
11
|
+
/** The gRPC status of a cancelled call. */
|
|
12
|
+
const CANCELLED = 1;
|
|
13
|
+
/** The details grpc-js gives a call the client itself cancelled. */
|
|
14
|
+
const CANCELLED_ON_CLIENT = 'Cancelled on client';
|
|
15
|
+
function grpcStatus(err) {
|
|
16
|
+
for (let e = err; e !== undefined && e !== null; e = e.cause) {
|
|
17
|
+
const { code, details } = e;
|
|
18
|
+
if (typeof code === 'number')
|
|
19
|
+
return { code, details: typeof details === 'string' ? details : '' };
|
|
20
|
+
if (typeof e !== 'object')
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
/** True when the call ended on its deadline: DEADLINE_EXCEEDED, or CANCELLED by the server and not by the client. */
|
|
26
|
+
function endedOnDeadline(err) {
|
|
27
|
+
const status = grpcStatus(err);
|
|
28
|
+
if (status === undefined)
|
|
29
|
+
return false;
|
|
30
|
+
if (status.code === DEADLINE_EXCEEDED)
|
|
31
|
+
return true;
|
|
32
|
+
return status.code === CANCELLED && status.details !== CANCELLED_ON_CLIENT;
|
|
33
|
+
}
|
|
34
|
+
/** The namespace a Temporal client talks to when its options name none. */
|
|
35
|
+
const DEFAULT_NAMESPACE = 'default';
|
|
36
|
+
/**
|
|
37
|
+
* Sends every query and signal that throws to Flowrensic, with its name, the
|
|
38
|
+
* workflow it was for and whether it ended on its deadline. A call that works
|
|
39
|
+
* is not sent. The calls wait in a buffer and are sent in batches, as the
|
|
40
|
+
* worker sink sends attempts, so sending never changes what the caller gets or
|
|
41
|
+
* how long it waits. It is a client plugin too: put in the plugins of the
|
|
42
|
+
* Temporal client, it reads the namespace of the client and puts itself in its
|
|
43
|
+
* workflow interceptors.
|
|
44
|
+
*/
|
|
45
|
+
class FlowrensicClientInterceptor {
|
|
46
|
+
buffer;
|
|
47
|
+
namespace = DEFAULT_NAMESPACE;
|
|
48
|
+
/** The name of the plugin. */
|
|
49
|
+
name = 'flowrensic.client';
|
|
50
|
+
constructor(options) {
|
|
51
|
+
const client = (0, client_js_1.createFlowrensicClient)(options.serverBaseUrl, (0, client_js_1.contextOf)(options));
|
|
52
|
+
this.buffer = (0, sink_js_1.createRecordBuffer)({
|
|
53
|
+
async send(calls, timeoutMs, id) {
|
|
54
|
+
await client.ingest.ingestClientCalls({ calls, ...id }, { timeoutMs });
|
|
55
|
+
},
|
|
56
|
+
envOf: () => options.currentEnv,
|
|
57
|
+
}, options);
|
|
58
|
+
}
|
|
59
|
+
/** Reads the namespace of the client and adds this interceptor to its workflow interceptors. */
|
|
60
|
+
configureClient(options) {
|
|
61
|
+
this.namespace = options.namespace ?? DEFAULT_NAMESPACE;
|
|
62
|
+
const workflow = options.interceptors?.workflow;
|
|
63
|
+
const list = Array.isArray(workflow) ? workflow : [];
|
|
64
|
+
return { ...options, interceptors: { ...options.interceptors, workflow: [...list, this] } };
|
|
65
|
+
}
|
|
66
|
+
async query(input, next) {
|
|
67
|
+
try {
|
|
68
|
+
return await next(input);
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
this.record('query', input.queryType, input.workflowExecution, err);
|
|
72
|
+
throw err;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async signal(input, next) {
|
|
76
|
+
try {
|
|
77
|
+
await next(input);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
this.record('signal', input.signalName, input.workflowExecution, err);
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Send what is buffered and wait for it to land. */
|
|
85
|
+
async flush() {
|
|
86
|
+
await this.buffer.flush();
|
|
87
|
+
}
|
|
88
|
+
/** Send what is buffered and stop. */
|
|
89
|
+
async close() {
|
|
90
|
+
await this.buffer.close();
|
|
91
|
+
}
|
|
92
|
+
/** What the buffer lost and holds. */
|
|
93
|
+
counts() {
|
|
94
|
+
return this.buffer.counts();
|
|
95
|
+
}
|
|
96
|
+
/** Records a call that threw, and never throws itself, so the caller gets the error Temporal gave. */
|
|
97
|
+
record(kind, name, execution, err) {
|
|
98
|
+
try {
|
|
99
|
+
this.buffer.record(this.callOf(kind, name, execution, err));
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
callOf(kind, name, execution, err) {
|
|
106
|
+
const timedOut = endedOnDeadline(err);
|
|
107
|
+
return {
|
|
108
|
+
$typeName: 'flowrensic.v1.ClientCall',
|
|
109
|
+
namespace: this.namespace,
|
|
110
|
+
workflowId: execution.workflowId,
|
|
111
|
+
runId: execution.runId ?? '',
|
|
112
|
+
kind,
|
|
113
|
+
name,
|
|
114
|
+
outcome: timedOut ? client_calls_pb_js_1.ClientCallOutcome.TIMED_OUT : client_calls_pb_js_1.ClientCallOutcome.FAILED,
|
|
115
|
+
errorType: err instanceof Error ? err.constructor.name : 'Unknown',
|
|
116
|
+
endedAt: (0, wkt_1.timestampFromDate)(new Date()),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.FlowrensicClientInterceptor = FlowrensicClientInterceptor;
|
|
121
|
+
/**
|
|
122
|
+
* Pass to `new Client({ namespace, plugins: [flowrensicClientInterceptor({ serverBaseUrl, currentEnv, envAccessKey })] })`.
|
|
123
|
+
* The calls are sent under the namespace of that client. Call close before the
|
|
124
|
+
* process ends, so the calls still waiting are sent.
|
|
125
|
+
*/
|
|
126
|
+
function flowrensicClientInterceptor(options) {
|
|
127
|
+
return new FlowrensicClientInterceptor(options);
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=client-interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-interceptor.js","sourceRoot":"","sources":["../../src/client-interceptor.ts"],"names":[],"mappings":";;;;AAAA,gDAA2D;AAI3D,2CAAoF;AACpF,+EAA4F;AAC5F,uCAAqG;AAErG,iEAAiE;AACjE,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,2CAA2C;AAC3C,MAAM,SAAS,GAAG,CAAC,CAAC;AACpB,oEAAoE;AACpE,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAclD,SAAS,UAAU,CAAC,GAAY;IAC9B,KAAK,IAAI,CAAC,GAAY,GAAG,EAAE,CAAC,KAAK,SAAS,IAAI,CAAC,KA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C,OAAO,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Client, type Interceptor } from '@connectrpc/connect';
|
|
2
|
+
import { CatalogService, IngestService, JobService, QueryService, RemediationService } from './gen/flowrensic/v1/services_pb.js';
|
|
3
|
+
export interface FlowrensicClient {
|
|
4
|
+
catalog: Client<typeof CatalogService>;
|
|
5
|
+
ingest: Client<typeof IngestService>;
|
|
6
|
+
query: Client<typeof QueryService>;
|
|
7
|
+
remediation: Client<typeof RemediationService>;
|
|
8
|
+
jobs: Client<typeof JobService>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Who the client is: its env, the access key of that env and the ephemeral run
|
|
12
|
+
* of that env. Every call of IngestService and every ListReplayHistories call
|
|
13
|
+
* carries them in headers.
|
|
14
|
+
*/
|
|
15
|
+
export interface ClientContext {
|
|
16
|
+
/** The env of this client, as FLOWRENSIC_KNOWN_ENVS names it. */
|
|
17
|
+
currentEnv?: string;
|
|
18
|
+
/** The access key of that env. */
|
|
19
|
+
envAccessKey?: string;
|
|
20
|
+
/** The ephemeral run of that env, such as the CI build number. For an env of kind ephemeral, without one the run is default. */
|
|
21
|
+
currentEphemeralRun?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface FlowrensicClientOptions extends ClientContext {
|
|
24
|
+
/** The admin key of the server. Every call of JobService carries it. */
|
|
25
|
+
adminKey?: string;
|
|
26
|
+
}
|
|
27
|
+
/** The header a client call names its env in. */
|
|
28
|
+
export declare const CURRENT_ENV_HEADER = "Flowrensic-Current-Env";
|
|
29
|
+
/** The header a client call carries the access key of its env in. */
|
|
30
|
+
export declare const ENV_ACCESS_KEY_HEADER = "Flowrensic-Env-Access-Key";
|
|
31
|
+
/** The header a client call carries the ephemeral run of its env in. */
|
|
32
|
+
export declare const CURRENT_EPHEMERAL_RUN_HEADER = "Flowrensic-Current-Ephemeral-Run";
|
|
33
|
+
/** The headers of a client context, each one only when it is set. */
|
|
34
|
+
export declare function clientContextHeaders(context: ClientContext): Record<string, string>;
|
|
35
|
+
/** Puts the headers of the context on every call of IngestService, every ListReplayHistories call and every GetEphemeralRunSummary call. */
|
|
36
|
+
export declare function clientContextInterceptor(context: ClientContext): Interceptor;
|
|
37
|
+
/** The header every JobService call carries the server's admin key in. */
|
|
38
|
+
export declare const ADMIN_KEY_HEADER = "Flowrensic-Admin-Key";
|
|
39
|
+
/** Puts adminKey on every call of JobService. */
|
|
40
|
+
export declare function adminKeyInterceptor(adminKey: string): Interceptor;
|
|
41
|
+
/** The client context of options, with only the fields that are set. */
|
|
42
|
+
export declare function contextOf(options: ClientContext): ClientContext;
|
|
43
|
+
export declare function createFlowrensicClient(serverBaseUrl: string, options?: FlowrensicClientOptions): FlowrensicClient;
|
|
44
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,MAAM,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlF,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAEjI,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC;IACvC,MAAM,EAAE,MAAM,CAAC,OAAO,aAAa,CAAC,CAAC;IACrC,KAAK,EAAE,MAAM,CAAC,OAAO,YAAY,CAAC,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC;IAC/C,IAAI,EAAE,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;CACjC;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gIAAgI;IAChI,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,uBAAwB,SAAQ,aAAa;IAC5D,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,iDAAiD;AACjD,eAAO,MAAM,kBAAkB,2BAA2B,CAAC;AAE3D,qEAAqE;AACrE,eAAO,MAAM,qBAAqB,8BAA8B,CAAC;AAEjE,wEAAwE;AACxE,eAAO,MAAM,4BAA4B,qCAAqC,CAAC;AAE/E,qEAAqE;AACrE,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAMnF;AAED,4IAA4I;AAC5I,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,aAAa,GAAG,WAAW,CAU5E;AAED,0EAA0E;AAC1E,eAAO,MAAM,gBAAgB,yBAAyB,CAAC;AAEvD,iDAAiD;AACjD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,CAKjE;AAED,wEAAwE;AACxE,wBAAgB,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CAM/D;AAED,wBAAgB,sBAAsB,CACpC,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,uBAA4B,GACpC,gBAAgB,CAgBlB"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ADMIN_KEY_HEADER = exports.CURRENT_EPHEMERAL_RUN_HEADER = exports.ENV_ACCESS_KEY_HEADER = exports.CURRENT_ENV_HEADER = void 0;
|
|
4
|
+
exports.clientContextHeaders = clientContextHeaders;
|
|
5
|
+
exports.clientContextInterceptor = clientContextInterceptor;
|
|
6
|
+
exports.adminKeyInterceptor = adminKeyInterceptor;
|
|
7
|
+
exports.contextOf = contextOf;
|
|
8
|
+
exports.createFlowrensicClient = createFlowrensicClient;
|
|
9
|
+
const connect_1 = require("@connectrpc/connect");
|
|
10
|
+
const connect_node_1 = require("@connectrpc/connect-node");
|
|
11
|
+
const services_pb_js_1 = require("./gen/flowrensic/v1/services_pb.js");
|
|
12
|
+
/** The header a client call names its env in. */
|
|
13
|
+
exports.CURRENT_ENV_HEADER = 'Flowrensic-Current-Env';
|
|
14
|
+
/** The header a client call carries the access key of its env in. */
|
|
15
|
+
exports.ENV_ACCESS_KEY_HEADER = 'Flowrensic-Env-Access-Key';
|
|
16
|
+
/** The header a client call carries the ephemeral run of its env in. */
|
|
17
|
+
exports.CURRENT_EPHEMERAL_RUN_HEADER = 'Flowrensic-Current-Ephemeral-Run';
|
|
18
|
+
/** The headers of a client context, each one only when it is set. */
|
|
19
|
+
function clientContextHeaders(context) {
|
|
20
|
+
const headers = {};
|
|
21
|
+
if (context.currentEnv !== undefined)
|
|
22
|
+
headers[exports.CURRENT_ENV_HEADER] = context.currentEnv;
|
|
23
|
+
if (context.envAccessKey !== undefined)
|
|
24
|
+
headers[exports.ENV_ACCESS_KEY_HEADER] = context.envAccessKey;
|
|
25
|
+
if (context.currentEphemeralRun !== undefined)
|
|
26
|
+
headers[exports.CURRENT_EPHEMERAL_RUN_HEADER] = context.currentEphemeralRun;
|
|
27
|
+
return headers;
|
|
28
|
+
}
|
|
29
|
+
/** Puts the headers of the context on every call of IngestService, every ListReplayHistories call and every GetEphemeralRunSummary call. */
|
|
30
|
+
function clientContextInterceptor(context) {
|
|
31
|
+
const headers = Object.entries(clientContextHeaders(context));
|
|
32
|
+
return (next) => async (req) => {
|
|
33
|
+
const ingest = req.service.typeName === services_pb_js_1.IngestService.typeName;
|
|
34
|
+
const query = req.service.typeName === services_pb_js_1.QueryService.typeName;
|
|
35
|
+
const replaySet = query && (req.method.name === services_pb_js_1.QueryService.method.listReplayHistories.name || req.method.name === services_pb_js_1.QueryService.method.getEphemeralRunSummary.name);
|
|
36
|
+
if (ingest || replaySet)
|
|
37
|
+
for (const [name, value] of headers)
|
|
38
|
+
req.header.set(name, value);
|
|
39
|
+
return await next(req);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/** The header every JobService call carries the server's admin key in. */
|
|
43
|
+
exports.ADMIN_KEY_HEADER = 'Flowrensic-Admin-Key';
|
|
44
|
+
/** Puts adminKey on every call of JobService. */
|
|
45
|
+
function adminKeyInterceptor(adminKey) {
|
|
46
|
+
return (next) => async (req) => {
|
|
47
|
+
if (req.service.typeName === services_pb_js_1.JobService.typeName)
|
|
48
|
+
req.header.set(exports.ADMIN_KEY_HEADER, adminKey);
|
|
49
|
+
return await next(req);
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** The client context of options, with only the fields that are set. */
|
|
53
|
+
function contextOf(options) {
|
|
54
|
+
return {
|
|
55
|
+
...(options.currentEnv === undefined ? {} : { currentEnv: options.currentEnv }),
|
|
56
|
+
...(options.envAccessKey === undefined ? {} : { envAccessKey: options.envAccessKey }),
|
|
57
|
+
...(options.currentEphemeralRun === undefined ? {} : { currentEphemeralRun: options.currentEphemeralRun }),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function createFlowrensicClient(serverBaseUrl, options = {}) {
|
|
61
|
+
const transport = (0, connect_node_1.createConnectTransport)({
|
|
62
|
+
baseUrl: serverBaseUrl,
|
|
63
|
+
httpVersion: '1.1',
|
|
64
|
+
interceptors: [
|
|
65
|
+
clientContextInterceptor(options),
|
|
66
|
+
...(options.adminKey === undefined ? [] : [adminKeyInterceptor(options.adminKey)]),
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
catalog: (0, connect_1.createClient)(services_pb_js_1.CatalogService, transport),
|
|
71
|
+
ingest: (0, connect_1.createClient)(services_pb_js_1.IngestService, transport),
|
|
72
|
+
query: (0, connect_1.createClient)(services_pb_js_1.QueryService, transport),
|
|
73
|
+
remediation: (0, connect_1.createClient)(services_pb_js_1.RemediationService, transport),
|
|
74
|
+
jobs: (0, connect_1.createClient)(services_pb_js_1.JobService, transport),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;;;;;;AAAA,iDAAkF;AAClF,2DAAkE;AAElE,uEAAiI;AA6BjI,iDAAiD;AACpC,QAAA,kBAAkB,GAAG,wBAAwB,CAAC;AAE3D,qEAAqE;AACxD,QAAA,qBAAqB,GAAG,2BAA2B,CAAC;AAEjE,wEAAwE;AAC3D,QAAA,4BAA4B,GAAG,kCAAkC,CAAC;AAE/E,qEAAqE;AACrE,8BAAqC,OAAsB;IACzD,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS;QAAE,OAAO,CAAC,QAAA,kBAAkB,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;IACvF,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS;QAAE,OAAO,CAAC,QAAA,qBAAqB,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC;IAC9F,IAAI,OAAO,CAAC,mBAAmB,KAAK,SAAS;QAAE,OAAO,CAAC,QAAA,4BAA4B,CAAC,GAAG,OAAO,CAAC,mBAAmB,CAAC;IACnH,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,4IAA4I;AAC5I,kCAAyC,OAAsB;IAC7D,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9D,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QAC7B,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,KAAK,8BAAa,CAAC,QAAQ,CAAC;QAC/D,MAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,KAAK,6BAAY,CAAC,QAAQ,CAAC;QAC7D,M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