@flowrensic/temporal-flowrensic-node-sdk 0.0.0-stage → 0.6.64
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 +151 -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
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { create } from '@bufbuild/protobuf';
|
|
2
|
+
import { WorkflowInterceptorsSchema } from './gen/flowrensic/v1/replay_pb.js';
|
|
3
|
+
const extensions = /\.(?:[cm]?[jt]s|[jt]sx)$/;
|
|
4
|
+
/**
|
|
5
|
+
* The name of a workflow interceptor module: its file name without the folder
|
|
6
|
+
* and the extension, and for a file named index the name of its folder. So a
|
|
7
|
+
* prod worker's /app/dist/interceptors/metrics.js and a CI job's
|
|
8
|
+
* ./src/interceptors/metrics.ts are both metrics.
|
|
9
|
+
*/
|
|
10
|
+
export function interceptorName(module) {
|
|
11
|
+
const parts = module.split(/[/\\]/).filter((part) => part !== '');
|
|
12
|
+
const file = (parts.at(-1) ?? '').replace(extensions, '');
|
|
13
|
+
if (file === 'index' && parts.length > 1)
|
|
14
|
+
return parts.at(-2) ?? file;
|
|
15
|
+
return file;
|
|
16
|
+
}
|
|
17
|
+
/** The modules as Flowrensic is sent them, in their order. Undefined sends no list. */
|
|
18
|
+
export function interceptorList(modules) {
|
|
19
|
+
if (modules === undefined)
|
|
20
|
+
return undefined;
|
|
21
|
+
return create(WorkflowInterceptorsSchema, { names: modules.map(interceptorName) });
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=interceptor-names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptor-names.js","sourceRoot":"","sources":["../../src/interceptor-names.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,0BAA0B,EAA6B,MAAM,kCAAkC,CAAC;AAEzG,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;IAClE,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC1D,IAAI,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IACtE,OAAO,IAAI,CAAC;AACd,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,eAAe,CAAC,OAAsC;IACpE,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC5C,OAAO,MAAM,CAAC,0BAA0B,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;AACrF,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Context } from '@temporalio/activity';
|
|
2
|
+
import type { ActivityExecuteInput, ActivityInboundCallsInterceptor, ActivityInterceptorsFactory, Next } from '@temporalio/worker';
|
|
3
|
+
import type { AttemptSink } from './sink.js';
|
|
4
|
+
/**
|
|
5
|
+
* What the worker says of itself on each attempt. The env and the ephemeral run
|
|
6
|
+
* are not here: the sink sends them in the headers of its calls.
|
|
7
|
+
*/
|
|
8
|
+
export interface EnvOptions {
|
|
9
|
+
/** The version this worker serves, from its own config. A worker that
|
|
10
|
+
* carries none reports none, and a run with no version is on neither side of
|
|
11
|
+
* an overlap. */
|
|
12
|
+
version?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Records one event per activity attempt, which is everything Temporal's own
|
|
16
|
+
* OpenTelemetry spans throw away: the attempt number, the workflow type, the
|
|
17
|
+
* task queue, the failure classification, and the start to close timeout,
|
|
18
|
+
* maximum attempts and heartbeat timeout the activity context was handed for
|
|
19
|
+
* this attempt, and when the activity was first scheduled.
|
|
20
|
+
*
|
|
21
|
+
* Activity inbound, never workflow inbound. This runs in the activity worker
|
|
22
|
+
* where I/O is ordinary. Emitting from a workflow interceptor would be
|
|
23
|
+
* non-determinism in the product that sells determinism analysis.
|
|
24
|
+
*/
|
|
25
|
+
export declare class FlowrensicActivityInterceptor implements ActivityInboundCallsInterceptor {
|
|
26
|
+
private readonly ctx;
|
|
27
|
+
private readonly sink;
|
|
28
|
+
private readonly env;
|
|
29
|
+
constructor(ctx: Context, sink: AttemptSink, env?: EnvOptions);
|
|
30
|
+
execute(input: ActivityExecuteInput, next: Next<ActivityInboundCallsInterceptor, 'execute'>): Promise<unknown>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Pass to `Worker.create({ interceptors: { activity: [flowrensicInterceptor(sink, env)] } })`.
|
|
34
|
+
* `env` is the version the worker serves. The namespace of each attempt is the
|
|
35
|
+
* one Temporal gives in the activity info. The env and the ephemeral run are
|
|
36
|
+
* those the sink was made with.
|
|
37
|
+
*/
|
|
38
|
+
export declare function flowrensicInterceptor(sink: AttemptSink, env?: EnvOptions): ActivityInterceptorsFactory;
|
|
39
|
+
//# sourceMappingURL=interceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptor.d.ts","sourceRoot":"","sources":["../../src/interceptor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,KAAK,EACV,oBAAoB,EACpB,+BAA+B,EAC/B,2BAA2B,EAC3B,IAAI,EACL,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB;;qBAEiB;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AA2BD;;;;;;;;;;GAUG;AACH,qBAAa,6BAA8B,YAAW,+BAA+B;IAEjF,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAHtB,YACmB,GAAG,EAAE,OAAO,EACZ,IAAI,EAAE,WAAW,EACjB,GAAG,GAAE,UAAkB,EACtC;IAEE,OAAO,CACX,KAAK,EAAE,oBAAoB,EAC3B,IAAI,EAAE,IAAI,CAAC,+BAA+B,EAAE,SAAS,CAAC,GACrD,OAAO,CAAC,OAAO,CAAC,CAgDlB;CACF;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,GAAE,UAAkB,GAAG,2BAA2B,CAI7G"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { timestampFromDate } from '@bufbuild/protobuf/wkt';
|
|
2
|
+
import { ApplicationFailure, CancelledFailure } from '@temporalio/common';
|
|
3
|
+
import { Outcome } from './gen/flowrensic/v1/activity_metrics_pb.js';
|
|
4
|
+
const noEnv = {};
|
|
5
|
+
function classify(err) {
|
|
6
|
+
if (err instanceof CancelledFailure) {
|
|
7
|
+
return { outcome: Outcome.CANCELED, errorType: 'CancelledFailure' };
|
|
8
|
+
}
|
|
9
|
+
if (err instanceof ApplicationFailure) {
|
|
10
|
+
return { outcome: Outcome.FAILED, errorType: err.type ?? 'ApplicationFailure' };
|
|
11
|
+
}
|
|
12
|
+
if (err instanceof Error) {
|
|
13
|
+
return { outcome: Outcome.FAILED, errorType: err.constructor.name };
|
|
14
|
+
}
|
|
15
|
+
return { outcome: Outcome.FAILED, errorType: 'Unknown' };
|
|
16
|
+
}
|
|
17
|
+
/** The outcome and error type of a failed attempt, as two values. */
|
|
18
|
+
function classified(err) {
|
|
19
|
+
try {
|
|
20
|
+
const { outcome, errorType } = classify(err);
|
|
21
|
+
return [outcome, errorType];
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return [Outcome.FAILED, 'Unknown'];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Records one event per activity attempt, which is everything Temporal's own
|
|
29
|
+
* OpenTelemetry spans throw away: the attempt number, the workflow type, the
|
|
30
|
+
* task queue, the failure classification, and the start to close timeout,
|
|
31
|
+
* maximum attempts and heartbeat timeout the activity context was handed for
|
|
32
|
+
* this attempt, and when the activity was first scheduled.
|
|
33
|
+
*
|
|
34
|
+
* Activity inbound, never workflow inbound. This runs in the activity worker
|
|
35
|
+
* where I/O is ordinary. Emitting from a workflow interceptor would be
|
|
36
|
+
* non-determinism in the product that sells determinism analysis.
|
|
37
|
+
*/
|
|
38
|
+
export class FlowrensicActivityInterceptor {
|
|
39
|
+
ctx;
|
|
40
|
+
sink;
|
|
41
|
+
env;
|
|
42
|
+
constructor(ctx, sink, env = noEnv) {
|
|
43
|
+
this.ctx = ctx;
|
|
44
|
+
this.sink = sink;
|
|
45
|
+
this.env = env;
|
|
46
|
+
}
|
|
47
|
+
async execute(input, next) {
|
|
48
|
+
const info = this.ctx.info;
|
|
49
|
+
const startedAt = new Date();
|
|
50
|
+
const record = (outcome, errorType) => {
|
|
51
|
+
const endedAt = new Date();
|
|
52
|
+
this.sink.record({
|
|
53
|
+
$typeName: 'flowrensic.v1.ActivityAttempt',
|
|
54
|
+
namespace: info.namespace,
|
|
55
|
+
env: '',
|
|
56
|
+
ephemeralRun: '',
|
|
57
|
+
version: this.env.version ?? '',
|
|
58
|
+
workflowType: info.workflowType ?? '',
|
|
59
|
+
workflowExecutionId: info.workflowExecution?.workflowId ?? '',
|
|
60
|
+
runKey: info.workflowExecution?.runId ?? '',
|
|
61
|
+
activityType: info.activityType,
|
|
62
|
+
activityId: info.activityId,
|
|
63
|
+
attempt: info.attempt,
|
|
64
|
+
taskQueue: info.taskQueue,
|
|
65
|
+
outcome,
|
|
66
|
+
errorType,
|
|
67
|
+
startedAt: timestampFromDate(startedAt),
|
|
68
|
+
endedAt: timestampFromDate(endedAt),
|
|
69
|
+
durationMs: BigInt(endedAt.getTime() - startedAt.getTime()),
|
|
70
|
+
startToCloseTimeoutMs: BigInt(Math.round(info.startToCloseTimeoutMs)),
|
|
71
|
+
maximumAttempts: info.retryPolicy?.maximumAttempts ?? 0,
|
|
72
|
+
heartbeatTimeoutMs: BigInt(Math.round(info.heartbeatTimeoutMs ?? 0)),
|
|
73
|
+
scheduledAt: timestampFromDate(new Date(info.scheduledTimestampMs)),
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
// Reporting never changes what the activity returns or throws: an error
|
|
77
|
+
// inside it is swallowed.
|
|
78
|
+
const emit = (outcome, errorType) => {
|
|
79
|
+
try {
|
|
80
|
+
record(outcome, errorType);
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
try {
|
|
87
|
+
const result = await next(input);
|
|
88
|
+
emit(Outcome.COMPLETED, '');
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
emit(...classified(err));
|
|
93
|
+
throw err;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Pass to `Worker.create({ interceptors: { activity: [flowrensicInterceptor(sink, env)] } })`.
|
|
99
|
+
* `env` is the version the worker serves. The namespace of each attempt is the
|
|
100
|
+
* one Temporal gives in the activity info. The env and the ephemeral run are
|
|
101
|
+
* those the sink was made with.
|
|
102
|
+
*/
|
|
103
|
+
export function flowrensicInterceptor(sink, env = noEnv) {
|
|
104
|
+
return (ctx) => ({
|
|
105
|
+
inbound: new FlowrensicActivityInterceptor(ctx, sink, env),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptor.js","sourceRoot":"","sources":["../../src/interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAQ1E,OAAO,EAAE,OAAO,EAAE,MAAM,4CAA4C,CAAC;AAcrE,MAAM,KAAK,GAAe,EAAE,CAAC;AAE7B,SAAS,QAAQ,CAAC,GAAY;IAC5B,IAAI,GAAG,YAAY,gBAAgB,EAAE,CAAC;QACpC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,QAAQ,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC;IACtE,CAAC;IACD,IAAI,GAAG,YAAY,kBAAkB,EAAE,CAAC;QACtC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC,IAAI,IAAI,oBAAoB,EAAE,CAAC;IAClF,CAAC;IACD,IAAI,GAAG,YAAY,KAAK,EAAE,CAAC;QACzB,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC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G,EAAE,CAAC;YACb,IAAI,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;YACzB,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAiB,EAAE,GAAG,GAAe,KAAK;IAC9E,OAAO,CAAC,GAAY,EAAE,EAAE,CAAC,CAAC;QACxB,OAAO,EAAE,IAAI,6BAA6B,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC;KAC3D,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { InjectedSinks } from '@temporalio/worker';
|
|
2
|
+
import { type ClientContext } from './client.js';
|
|
3
|
+
import { type BufferOptions, type RecordSink } from './sink.js';
|
|
4
|
+
import type { FlowrensicSinks } from './workflow.js';
|
|
5
|
+
export interface QuerySinkOptions extends BufferOptions, ClientContext {
|
|
6
|
+
/** The Flowrensic server to send to. */
|
|
7
|
+
serverBaseUrl: string;
|
|
8
|
+
/** The env the worker runs in, sent with its key and ephemeral run in the headers of every send. */
|
|
9
|
+
currentEnv: string;
|
|
10
|
+
}
|
|
11
|
+
interface Answered {
|
|
12
|
+
readonly namespace: string;
|
|
13
|
+
readonly workflowType: string;
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly ok: boolean;
|
|
16
|
+
readonly at: number;
|
|
17
|
+
}
|
|
18
|
+
/** The sinks of the worker, with what the queries the workflows answer go to, and the buffer behind them. */
|
|
19
|
+
export interface QuerySinks {
|
|
20
|
+
readonly sinks: InjectedSinks<FlowrensicSinks>;
|
|
21
|
+
readonly buffer: RecordSink<Answered>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Pass sinks to `Worker.create({ sinks })`, beside the workflow module
|
|
25
|
+
* `@flowrensic/temporal-flowrensic-node-sdk/workflow` in `interceptors.workflowModules`. The queries
|
|
26
|
+
* the workflows answer are counted per workflow type, name and minute, and
|
|
27
|
+
* sent in batches. Call buffer.close() before the process ends.
|
|
28
|
+
*/
|
|
29
|
+
export declare function flowrensicQuerySinks(options: QuerySinkOptions): QuerySinks;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=query-sink.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-sink.d.ts","sourceRoot":"","sources":["../../src/query-sink.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGxD,OAAO,EAAqC,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAEpF,OAAO,EAAsB,KAAK,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AACpF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,MAAM,WAAW,gBAAiB,SAAQ,aAAa,EAAE,aAAa;IACpE,wCAAwC;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,oGAAoG;IACpG,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,QAAQ;IAChB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB;AAID,6GAA6G;AAC7G,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,eAAe,CAAC,CAAC;IAC/C,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,CAAC;CACvC;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,GAAG,UAAU,CAiD1E"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { timestampFromDate } from '@bufbuild/protobuf/wkt';
|
|
2
|
+
import { contextOf, createFlowrensicClient } from './client.js';
|
|
3
|
+
import { createRecordBuffer } from './sink.js';
|
|
4
|
+
const MINUTE = 60_000;
|
|
5
|
+
/**
|
|
6
|
+
* Pass sinks to `Worker.create({ sinks })`, beside the workflow module
|
|
7
|
+
* `@flowrensic/temporal-flowrensic-node-sdk/workflow` in `interceptors.workflowModules`. The queries
|
|
8
|
+
* the workflows answer are counted per workflow type, name and minute, and
|
|
9
|
+
* sent in batches. Call buffer.close() before the process ends.
|
|
10
|
+
*/
|
|
11
|
+
export function flowrensicQuerySinks(options) {
|
|
12
|
+
const client = createFlowrensicClient(options.serverBaseUrl, contextOf(options));
|
|
13
|
+
const buffer = createRecordBuffer({
|
|
14
|
+
async send(records, timeoutMs, id) {
|
|
15
|
+
const counts = new Map();
|
|
16
|
+
for (const one of records) {
|
|
17
|
+
const minute = Math.floor(one.at / MINUTE) * MINUTE;
|
|
18
|
+
const key = `${one.namespace}\u0000${one.workflowType}\u0000${one.name}\u0000${String(minute)}`;
|
|
19
|
+
let count = counts.get(key);
|
|
20
|
+
if (count === undefined) {
|
|
21
|
+
count = {
|
|
22
|
+
$typeName: 'flowrensic.v1.QueryCount',
|
|
23
|
+
namespace: one.namespace,
|
|
24
|
+
env: '',
|
|
25
|
+
workflowType: one.workflowType,
|
|
26
|
+
queryName: one.name,
|
|
27
|
+
answered: 0n,
|
|
28
|
+
failed: 0n,
|
|
29
|
+
minute: timestampFromDate(new Date(minute)),
|
|
30
|
+
};
|
|
31
|
+
counts.set(key, count);
|
|
32
|
+
}
|
|
33
|
+
if (one.ok)
|
|
34
|
+
count.answered += 1n;
|
|
35
|
+
else
|
|
36
|
+
count.failed += 1n;
|
|
37
|
+
}
|
|
38
|
+
await client.ingest.ingestQueryCounts({ counts: [...counts.values()], ...id }, { timeoutMs });
|
|
39
|
+
},
|
|
40
|
+
envOf: () => options.currentEnv,
|
|
41
|
+
}, options);
|
|
42
|
+
return {
|
|
43
|
+
buffer,
|
|
44
|
+
sinks: {
|
|
45
|
+
flowrensic: {
|
|
46
|
+
query: {
|
|
47
|
+
fn(info, name, ok) {
|
|
48
|
+
try {
|
|
49
|
+
buffer.record({ namespace: info.namespace, workflowType: info.workflowType, name, ok, at: Date.now() });
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
callDuringReplay: false,
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=query-sink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-sink.js","sourceRoot":"","sources":["../../src/query-sink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAI3D,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAsB,MAAM,aAAa,CAAC;AAEpF,OAAO,EAAE,kBAAkB,EAAuC,MAAM,WAAW,CAAC;AAkBpF,MAAM,MAAM,GAAG,MAAM,CAAC;AAQtB;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAyB;IAC5D,MAAM,MAAM,GAAG,sBAAsB,CAAC,OAAO,CAAC,aAAa,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IACjF,MAAM,MAAM,GAAG,kBAAkB,CAC/B;QACE,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE;YAC/B,MAAM,MAAM,GAAG,IAAI,GAAG,EAAsB,CAAC;YAC7C,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;gBAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;gBACpD,MAAM,GAAG,GAAG,GAAG,GAAG,CAAC,SAAS,SAAS,GAAG,CAAC,YAAY,SAAS,GAAG,CAAC,IAAI,SA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CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;wBAC1G,CAAC;wBAAC,MAAM,CAAC;4BACP,OAAO;wBACT,CAAC;oBACH,CAAC;oBACD,gBAAgB,EAAE,KAAK;iBACxB;aACF;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/** Manifest written beside the histories, the same one the CLI writes. */
|
|
2
|
+
export declare const INDEX_NAME = "replay-set.json";
|
|
3
|
+
/** One history on disk, with the metadata the server chose it by. */
|
|
4
|
+
export interface ReplaySetEntry {
|
|
5
|
+
readonly run_id: string;
|
|
6
|
+
readonly file: string;
|
|
7
|
+
readonly status: string;
|
|
8
|
+
/** The env the history comes from. */
|
|
9
|
+
readonly env?: string;
|
|
10
|
+
/** The build ids the history carries, unknown when it carries none. */
|
|
11
|
+
readonly code_versions: readonly string[];
|
|
12
|
+
readonly events: number;
|
|
13
|
+
readonly started_at: string;
|
|
14
|
+
readonly closed_at?: string;
|
|
15
|
+
}
|
|
16
|
+
/** A stored run the server could not read, so it is not in the set. */
|
|
17
|
+
export interface LeftOutEntry {
|
|
18
|
+
readonly run_id: string;
|
|
19
|
+
readonly reason: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ReplaySet {
|
|
22
|
+
readonly workflow_type: string;
|
|
23
|
+
/** The envs the histories come from, in the order they were asked for. */
|
|
24
|
+
readonly envs: readonly string[];
|
|
25
|
+
readonly fetched_at: string;
|
|
26
|
+
readonly server: string;
|
|
27
|
+
readonly histories: readonly ReplaySetEntry[];
|
|
28
|
+
/** Empty when every stored history of the type and envs could be read. */
|
|
29
|
+
readonly left_out: readonly LeftOutEntry[];
|
|
30
|
+
/** Why the download failed, when failOnError was false and it did. The set is then empty. */
|
|
31
|
+
readonly failed?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface FetchOptions {
|
|
34
|
+
/** Flowrensic base URL, e.g. `http://flowrensic:8080`. */
|
|
35
|
+
serverBaseUrl: string;
|
|
36
|
+
/** The workflow type to replay. A set spans one, because that is what a replayer is built for. */
|
|
37
|
+
replayHistoryWorkflow: string;
|
|
38
|
+
/** Directory to write the histories and the manifest into. */
|
|
39
|
+
replayHistoryOutDir: string;
|
|
40
|
+
/**
|
|
41
|
+
* The envs to replay from, such as prod and staging. Each one must be the
|
|
42
|
+
* current env or an env it may read. The set of each env comes in this order.
|
|
43
|
+
*/
|
|
44
|
+
replayHistoryFromEnvs: readonly string[];
|
|
45
|
+
/** The env of the caller, sent in the header Flowrensic-Current-Env. */
|
|
46
|
+
currentEnv: string;
|
|
47
|
+
/** The access key of the env of the caller. The request carries it. */
|
|
48
|
+
envAccessKey: string;
|
|
49
|
+
/** The ephemeral run of the caller, such as the CI build number. For an env of kind ephemeral, without one the run is default. */
|
|
50
|
+
currentEphemeralRun?: string;
|
|
51
|
+
/** How long the download may take, in milliseconds. Left out, 60 seconds. */
|
|
52
|
+
timeoutMs?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Whether a download that failed rejects, so the CI job fails. Left out,
|
|
55
|
+
* true. False resolves with an empty set whose failed field says why, and
|
|
56
|
+
* writes no manifest.
|
|
57
|
+
*/
|
|
58
|
+
failOnError?: boolean;
|
|
59
|
+
}
|
|
60
|
+
/** What one history did when replayed against the checkout under test. */
|
|
61
|
+
export interface ReplayVerdict {
|
|
62
|
+
readonly runId: string;
|
|
63
|
+
readonly workflowType: string;
|
|
64
|
+
readonly passed: boolean;
|
|
65
|
+
/** The replayer's own message, kept verbatim: it names what diverged. */
|
|
66
|
+
readonly error?: string;
|
|
67
|
+
}
|
|
68
|
+
export interface PublishOptions {
|
|
69
|
+
serverBaseUrl: string;
|
|
70
|
+
/**
|
|
71
|
+
* The commit, tag or build replayed. Only the pipeline knows it, and a
|
|
72
|
+
* verdict without one cannot be attributed to a change.
|
|
73
|
+
*/
|
|
74
|
+
codeVersion: string;
|
|
75
|
+
verdicts: readonly ReplayVerdict[];
|
|
76
|
+
/** The env the verdicts are sent for, sent in the header Flowrensic-Current-Env. */
|
|
77
|
+
currentEnv: string;
|
|
78
|
+
/** The access key of that env. */
|
|
79
|
+
envAccessKey: string;
|
|
80
|
+
/** The ephemeral run of that env, such as the CI build number. For an env of kind ephemeral, without one the run is default. */
|
|
81
|
+
currentEphemeralRun?: string;
|
|
82
|
+
/**
|
|
83
|
+
* The module paths of the workflow interceptors the replay ran with, the
|
|
84
|
+
* workflowInterceptorModules its bundle was built with. Every result is sent
|
|
85
|
+
* with their names, to compare with the list the workers of the env load.
|
|
86
|
+
* Left out, no list is sent, which is not an empty list.
|
|
87
|
+
*/
|
|
88
|
+
workflowInterceptors?: readonly string[];
|
|
89
|
+
/**
|
|
90
|
+
* How long refused results are sent again before publishVerdicts gives up
|
|
91
|
+
* with the last error, 10 minutes when left out. Results Flowrensic does not
|
|
92
|
+
* answer, or answers try again later, are sent again (FPP-135-R23).
|
|
93
|
+
*/
|
|
94
|
+
sendAgainForMs?: number;
|
|
95
|
+
/** How long one call may take, in milliseconds. Left out, 30 seconds. */
|
|
96
|
+
timeoutMs?: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Fetches the set the server picks for a workflow type in each env named, in
|
|
100
|
+
* one request, and writes it to disk.
|
|
101
|
+
*
|
|
102
|
+
* Which histories are worth replaying is the server's call, not the caller's.
|
|
103
|
+
* What comes down is the engine's own history, verbatim, so a replayer reads
|
|
104
|
+
* it the way the engine wrote it.
|
|
105
|
+
*
|
|
106
|
+
* Nothing here runs a workflow. Replay belongs to the suite that owns the
|
|
107
|
+
* code, through its own SDK, and `publishVerdicts` takes the outcome back.
|
|
108
|
+
*/
|
|
109
|
+
export declare function fetchReplaySet(options: FetchOptions): Promise<ReplaySet>;
|
|
110
|
+
/** Reads a manifest a fetch left behind, the CLI's or this package's. */
|
|
111
|
+
export declare function readReplaySet(dir: string): Promise<ReplaySet>;
|
|
112
|
+
/** Histories in a directory, for a caller that wants them without the index. */
|
|
113
|
+
export declare function listHistoryFiles(dir: string): Promise<string[]>;
|
|
114
|
+
/**
|
|
115
|
+
* Reports what a replay found, against the history and the version replayed,
|
|
116
|
+
* so a break is attributed to a code change rather than to a failing test.
|
|
117
|
+
*/
|
|
118
|
+
export declare function publishVerdicts(options: PublishOptions): Promise<void>;
|
|
119
|
+
//# sourceMappingURL=replay.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../../src/replay.ts"],"names":[],"mappings":"AAWA,0EAA0E;AAC1E,eAAO,MAAM,UAAU,oBAAoB,CAAC;AAE5C,qEAAqE;AACrE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,sCAAsC;IACtC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,uEAAuE;IACvE,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,uEAAuE;AACvE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,0EAA0E;IAC1E,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,SAAS,cAAc,EAAE,CAAC;IAC9C,0EAA0E;IAC1E,QAAQ,CA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IACxB,yEAAyE;IACzE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAkCD;;;;;;;;;;GAUG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,CA2E9E;AAUD,yEAAyE;AACzE,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAOnE;AAED,gFAAgF;AAChF,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAGrE;AAoBD;;;GAGG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAiC5E"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { mkdir, readFile, readdir, rename, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { timestampDate, timestampFromDate } from '@bufbuild/protobuf/wkt';
|
|
4
|
+
import { Code, ConnectError } from '@connectrpc/connect';
|
|
5
|
+
import { ciError, ciFailure } from './ci.js';
|
|
6
|
+
import { contextOf, createFlowrensicClient } from './client.js';
|
|
7
|
+
import { interceptorList } from './interceptor-names.js';
|
|
8
|
+
import { RunStatus } from './gen/flowrensic/v1/replay_pb.js';
|
|
9
|
+
/** Manifest written beside the histories, the same one the CLI writes. */
|
|
10
|
+
export const INDEX_NAME = 'replay-set.json';
|
|
11
|
+
// A manifest reads `completed`, the same label the CLI writes. A table rather
|
|
12
|
+
// than a reverse enum lookup, so adding a status is a compile error here.
|
|
13
|
+
const STATUS_LABELS = {
|
|
14
|
+
[RunStatus.UNSPECIFIED]: 'unspecified',
|
|
15
|
+
[RunStatus.RUNNING]: 'running',
|
|
16
|
+
[RunStatus.COMPLETED]: 'completed',
|
|
17
|
+
[RunStatus.FAILED]: 'failed',
|
|
18
|
+
[RunStatus.CANCELED]: 'canceled',
|
|
19
|
+
[RunStatus.TERMINATED]: 'terminated',
|
|
20
|
+
[RunStatus.TIMED_OUT]: 'timed_out',
|
|
21
|
+
[RunStatus.CONTINUED_AS_NEW]: 'continued_as_new',
|
|
22
|
+
[RunStatus.PAUSED]: 'paused',
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* What a download writes to stderr, the same lines in every SDK and the CLI:
|
|
26
|
+
* the workflow type and the envs, how many histories the answer held and how
|
|
27
|
+
* many were saved, the run id of each, and each run left out with its reason.
|
|
28
|
+
*/
|
|
29
|
+
function fetchedLog(set, got, dir) {
|
|
30
|
+
const lines = [
|
|
31
|
+
`replay set: workflow ${set.workflow_type}, envs ${set.envs.join(', ')}`,
|
|
32
|
+
`got ${String(got)} histories, saved ${String(set.histories.length)} in ${dir}`,
|
|
33
|
+
...set.histories.map((one) => ` ${one.run_id}`),
|
|
34
|
+
...set.left_out.map((one) => `left out ${one.run_id}: ${one.reason}`),
|
|
35
|
+
];
|
|
36
|
+
return `${lines.join('\n')}\n`;
|
|
37
|
+
}
|
|
38
|
+
/** How long a replay set download may take when the options carry no limit. */
|
|
39
|
+
const downloadTimeoutMs = 60_000;
|
|
40
|
+
/**
|
|
41
|
+
* Fetches the set the server picks for a workflow type in each env named, in
|
|
42
|
+
* one request, and writes it to disk.
|
|
43
|
+
*
|
|
44
|
+
* Which histories are worth replaying is the server's call, not the caller's.
|
|
45
|
+
* What comes down is the engine's own history, verbatim, so a replayer reads
|
|
46
|
+
* it the way the engine wrote it.
|
|
47
|
+
*
|
|
48
|
+
* Nothing here runs a workflow. Replay belongs to the suite that owns the
|
|
49
|
+
* code, through its own SDK, and `publishVerdicts` takes the outcome back.
|
|
50
|
+
*/
|
|
51
|
+
export async function fetchReplaySet(options) {
|
|
52
|
+
const { serverBaseUrl } = options;
|
|
53
|
+
const workflowType = options.replayHistoryWorkflow;
|
|
54
|
+
const dir = options.replayHistoryOutDir;
|
|
55
|
+
const envs = [...options.replayHistoryFromEnvs];
|
|
56
|
+
const timeoutMs = options.timeoutMs ?? downloadTimeoutMs;
|
|
57
|
+
const client = createFlowrensicClient(serverBaseUrl, contextOf(options));
|
|
58
|
+
// The answer comes in pages of whole env sets: ask until the server says
|
|
59
|
+
// there is no more, and keep every page in order.
|
|
60
|
+
const found = { histories: [], leftOut: [] };
|
|
61
|
+
try {
|
|
62
|
+
let pageToken = '';
|
|
63
|
+
do {
|
|
64
|
+
const page = await client.query.listReplayHistories({ workflowType, envs, page: { pageToken } }, { timeoutMs });
|
|
65
|
+
found.histories.push(...page.histories);
|
|
66
|
+
found.leftOut.push(...page.leftOut);
|
|
67
|
+
pageToken = page.page?.nextPageToken ?? '';
|
|
68
|
+
} while (pageToken !== '');
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
if (options.failOnError !== false)
|
|
72
|
+
throw ciError('replay set download', serverBaseUrl, timeoutMs, error);
|
|
73
|
+
const message = ciFailure('replay set download', serverBaseUrl, timeoutMs, error);
|
|
74
|
+
return {
|
|
75
|
+
workflow_type: workflowType,
|
|
76
|
+
envs,
|
|
77
|
+
fetched_at: new Date().toISOString(),
|
|
78
|
+
server: serverBaseUrl,
|
|
79
|
+
histories: [],
|
|
80
|
+
left_out: [],
|
|
81
|
+
failed: message,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
// An empty set is not an error: a workflow type with no runs yet is a normal
|
|
85
|
+
// state on a new pipeline, and the caller decides what to do about it.
|
|
86
|
+
await mkdir(dir, { recursive: true, mode: 0o750 });
|
|
87
|
+
const histories = [];
|
|
88
|
+
for (const history of found.histories) {
|
|
89
|
+
const file = `${history.runId}.json`;
|
|
90
|
+
// The answer carries each history. Written and renamed, so a failed write
|
|
91
|
+
// never leaves a half history for a replayer to read as a non-determinism
|
|
92
|
+
// report.
|
|
93
|
+
const temp = join(dir, `.fetch-${history.runId}`);
|
|
94
|
+
await writeFile(temp, history.history, { mode: 0o600 });
|
|
95
|
+
await rename(temp, join(dir, file));
|
|
96
|
+
histories.push({
|
|
97
|
+
run_id: history.runId,
|
|
98
|
+
file,
|
|
99
|
+
status: STATUS_LABELS[history.status],
|
|
100
|
+
...(history.env === '' ? {} : { env: history.env }),
|
|
101
|
+
code_versions: history.codeVersions,
|
|
102
|
+
events: history.events,
|
|
103
|
+
started_at: (history.startedAt ? timestampDate(history.startedAt) : new Date(0)).toISOString(),
|
|
104
|
+
...(history.closedAt ? { closed_at: timestampDate(history.closedAt).toISOString() } : {}),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const set = {
|
|
108
|
+
workflow_type: workflowType,
|
|
109
|
+
envs,
|
|
110
|
+
fetched_at: new Date().toISOString(),
|
|
111
|
+
server: serverBaseUrl,
|
|
112
|
+
histories,
|
|
113
|
+
left_out: found.leftOut.map((entry) => ({ run_id: entry.runId, reason: entry.reason })),
|
|
114
|
+
};
|
|
115
|
+
await writeFile(join(dir, INDEX_NAME), `${JSON.stringify(set, null, 2)}\n`, { mode: 0o600 });
|
|
116
|
+
process.stderr.write(fetchedLog(set, found.histories.length, dir));
|
|
117
|
+
return set;
|
|
118
|
+
}
|
|
119
|
+
function isReplaySet(value) {
|
|
120
|
+
if (typeof value !== 'object' || value === null)
|
|
121
|
+
return false;
|
|
122
|
+
if (!('workflow_type' in value) || typeof value.workflow_type !== 'string')
|
|
123
|
+
return false;
|
|
124
|
+
if (!('envs' in value) || !Array.isArray(value.envs) || !value.envs.every((one) => typeof one === 'string'))
|
|
125
|
+
return false;
|
|
126
|
+
return 'histories' in value && Array.isArray(value.histories);
|
|
127
|
+
}
|
|
128
|
+
/** Reads a manifest a fetch left behind, the CLI's or this package's. */
|
|
129
|
+
export async function readReplaySet(dir) {
|
|
130
|
+
const path = join(dir, INDEX_NAME);
|
|
131
|
+
const parsed = JSON.parse(await readFile(path, 'utf8'));
|
|
132
|
+
if (!isReplaySet(parsed)) {
|
|
133
|
+
throw new Error(`${path} is not a replay set manifest`);
|
|
134
|
+
}
|
|
135
|
+
return parsed;
|
|
136
|
+
}
|
|
137
|
+
/** Histories in a directory, for a caller that wants them without the index. */
|
|
138
|
+
export async function listHistoryFiles(dir) {
|
|
139
|
+
const names = await readdir(dir);
|
|
140
|
+
return names.filter((n) => n.endsWith('.json') && n !== INDEX_NAME).sort();
|
|
141
|
+
}
|
|
142
|
+
/** How long one call of publishVerdicts may take when the options carry no limit. */
|
|
143
|
+
const publishTimeoutMs = 30_000;
|
|
144
|
+
/** How long publishVerdicts sends refused results again before it gives up. */
|
|
145
|
+
const SEND_AGAIN_FOR_MS = 10 * 60_000;
|
|
146
|
+
/**
|
|
147
|
+
* The time to wait before sending again a call that Flowrensic did not answer
|
|
148
|
+
* or answered try again later: its Retry-After, or a second. Undefined for any
|
|
149
|
+
* other error, which is not sent again.
|
|
150
|
+
*/
|
|
151
|
+
function waitBeforeSendingAgain(error) {
|
|
152
|
+
if (!(error instanceof ConnectError))
|
|
153
|
+
return undefined;
|
|
154
|
+
if (error.code !== Code.Unavailable && error.code !== Code.DeadlineExceeded && error.code !== Code.ResourceExhausted)
|
|
155
|
+
return undefined;
|
|
156
|
+
const seconds = Number(error.metadata.get('retry-after') ?? '');
|
|
157
|
+
return Number.isFinite(seconds) && seconds > 0 ? seconds * 1000 : 1000;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Reports what a replay found, against the history and the version replayed,
|
|
161
|
+
* so a break is attributed to a code change rather than to a failing test.
|
|
162
|
+
*/
|
|
163
|
+
export async function publishVerdicts(options) {
|
|
164
|
+
const { serverBaseUrl, codeVersion, verdicts } = options;
|
|
165
|
+
if (verdicts.length === 0)
|
|
166
|
+
return;
|
|
167
|
+
const interceptors = interceptorList(options.workflowInterceptors);
|
|
168
|
+
const client = createFlowrensicClient(serverBaseUrl, contextOf(options));
|
|
169
|
+
const replayedAt = timestampFromDate(new Date());
|
|
170
|
+
const results = verdicts.map((v) => ({
|
|
171
|
+
runId: v.runId,
|
|
172
|
+
codeVersion,
|
|
173
|
+
workflowType: v.workflowType,
|
|
174
|
+
passed: v.passed,
|
|
175
|
+
error: v.error ?? '',
|
|
176
|
+
replayedAt,
|
|
177
|
+
...(interceptors === undefined ? {} : { workflowInterceptors: interceptors }),
|
|
178
|
+
}));
|
|
179
|
+
const giveUpAt = Date.now() + (options.sendAgainForMs ?? SEND_AGAIN_FOR_MS);
|
|
180
|
+
const timeoutMs = options.timeoutMs ?? publishTimeoutMs;
|
|
181
|
+
for (;;) {
|
|
182
|
+
try {
|
|
183
|
+
await client.ingest.ingestReplayResults({ results }, { timeoutMs });
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
const wait = waitBeforeSendingAgain(error);
|
|
188
|
+
if (wait === undefined || Date.now() + wait > giveUpAt) {
|
|
189
|
+
throw ciError('replay results', serverBaseUrl, timeoutMs, error);
|
|
190
|
+
}
|
|
191
|
+
await new Promise((resolve) => {
|
|
192
|
+
setTimeout(resolve, wait);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=replay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replay.js","sourceRoot":"","sources":["../../src/replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,SAAS,EAA2C,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