@output.ai/core 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -3,6 +3,9 @@ import { getRedisClient } from './redis_client.js';
|
|
|
3
3
|
import buildTraceTree from '../../tools/build_trace_tree.js';
|
|
4
4
|
import { EOL } from 'node:os';
|
|
5
5
|
import { loadEnv, getVars } from './configs.js';
|
|
6
|
+
import { createChildLogger } from '#logger';
|
|
7
|
+
|
|
8
|
+
const log = createChildLogger( 'S3 Processor' );
|
|
6
9
|
|
|
7
10
|
const createRedisKey = ( { workflowId, workflowName } ) => `traces/${workflowName}/${workflowId}`;
|
|
8
11
|
|
|
@@ -81,6 +84,11 @@ export const exec = async ( { entry, executionContext } ) => {
|
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
const content = buildTraceTree( await getEntries( cacheKey ) );
|
|
87
|
+
// if the trace tree is incomplete it will return null, in this case we can safely discard
|
|
88
|
+
if ( !content ) {
|
|
89
|
+
log.warn( 'Incomplete trace file discarded', { workflowId, error: 'incomplete_trace_file' } );
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
84
92
|
await upload( {
|
|
85
93
|
key: getS3Key( { workflowId, workflowName, startTime } ),
|
|
86
94
|
content: JSON.stringify( content, undefined, 2 ) + EOL
|
|
@@ -87,5 +87,21 @@ describe( 'tracing/processors/s3', () => {
|
|
|
87
87
|
'https://my-bucket.s3.amazonaws.com/WF/2020/01/02/2020-01-02-03-04-05-678Z_id1.json'
|
|
88
88
|
);
|
|
89
89
|
} );
|
|
90
|
+
|
|
91
|
+
it( 'exec(): when buildTraceTree returns null (incomplete tree), does not upload or bust cache', async () => {
|
|
92
|
+
const { exec } = await import( './index.js' );
|
|
93
|
+
const startTime = Date.parse( '2020-01-02T03:04:05.678Z' );
|
|
94
|
+
const ctx = { executionContext: { workflowId: 'id1', workflowName: 'WF', startTime } };
|
|
95
|
+
|
|
96
|
+
redisMulti.exec.mockResolvedValue( [] );
|
|
97
|
+
zRangeMock.mockResolvedValue( [ JSON.stringify( { id: 'wf', phase: 'end', timestamp: startTime } ) ] );
|
|
98
|
+
buildTraceTreeMock.mockReturnValueOnce( null );
|
|
99
|
+
|
|
100
|
+
await exec( { ...ctx, entry: { id: 'wf', phase: 'end', timestamp: startTime } } );
|
|
101
|
+
|
|
102
|
+
expect( buildTraceTreeMock ).toHaveBeenCalledTimes( 1 );
|
|
103
|
+
expect( uploadMock ).not.toHaveBeenCalled();
|
|
104
|
+
expect( delMock ).not.toHaveBeenCalled();
|
|
105
|
+
} );
|
|
90
106
|
} );
|
|
91
107
|
|
|
@@ -46,7 +46,7 @@ const createEntry = id => ( {
|
|
|
46
46
|
* The result tree has a single root: the only node without parentId, normally the workflow itself.
|
|
47
47
|
*
|
|
48
48
|
* @param {object[]} entries - The list of entries
|
|
49
|
-
* @returns {
|
|
49
|
+
* @returns {object}
|
|
50
50
|
*/
|
|
51
51
|
export default entries => {
|
|
52
52
|
const nodes = new Map();
|
|
@@ -71,6 +71,9 @@ export default entries => {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
const
|
|
75
|
-
|
|
74
|
+
const rootNode = nodes.get( entries.find( e => !e.parentId )?.id );
|
|
75
|
+
if ( !rootNode ) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return rootNode;
|
|
76
79
|
};
|
|
@@ -1,7 +1,32 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import
|
|
2
|
+
import buildTraceTree from './build_trace_tree.js';
|
|
3
3
|
|
|
4
4
|
describe( 'build_trace_tree', () => {
|
|
5
|
+
it( 'returns null when entries is empty', () => {
|
|
6
|
+
expect( buildTraceTree( [] ) ).toBeNull();
|
|
7
|
+
} );
|
|
8
|
+
|
|
9
|
+
it( 'returns null when there is no root (all entries have parentId)', () => {
|
|
10
|
+
const entries = [
|
|
11
|
+
{ id: 'a', parentId: 'x', phase: 'start', name: 'a', timestamp: 1 },
|
|
12
|
+
{ id: 'b', parentId: 'a', phase: 'start', name: 'b', timestamp: 2 }
|
|
13
|
+
];
|
|
14
|
+
expect( buildTraceTree( entries ) ).toBeNull();
|
|
15
|
+
} );
|
|
16
|
+
|
|
17
|
+
it( 'error phase sets error and endedAt on node', () => {
|
|
18
|
+
const entries = [
|
|
19
|
+
{ kind: 'wf', id: 'r', parentId: undefined, phase: 'start', name: 'root', details: {}, timestamp: 100 },
|
|
20
|
+
{ kind: 'step', id: 's', parentId: 'r', phase: 'start', name: 'step', details: {}, timestamp: 200 },
|
|
21
|
+
{ kind: 'step', id: 's', parentId: 'r', phase: 'error', name: 'step', details: { message: 'failed' }, timestamp: 300 }
|
|
22
|
+
];
|
|
23
|
+
const result = buildTraceTree( entries );
|
|
24
|
+
expect( result ).not.toBeNull();
|
|
25
|
+
expect( result.children ).toHaveLength( 1 );
|
|
26
|
+
expect( result.children[0].error ).toEqual( { message: 'failed' } );
|
|
27
|
+
expect( result.children[0].endedAt ).toBe( 300 );
|
|
28
|
+
} );
|
|
29
|
+
|
|
5
30
|
it( 'builds a tree from workflow/step/IO entries with grouping and sorting', () => {
|
|
6
31
|
const entries = [
|
|
7
32
|
// workflow start
|
|
@@ -28,7 +53,7 @@ describe( 'build_trace_tree', () => {
|
|
|
28
53
|
{ kind: 'workflow', phase: 'end', name: 'wf', id: 'wf', parentId: undefined, details: { ok: true }, timestamp: 3000 }
|
|
29
54
|
];
|
|
30
55
|
|
|
31
|
-
const result =
|
|
56
|
+
const result = buildTraceTree( entries );
|
|
32
57
|
|
|
33
58
|
const expected = {
|
|
34
59
|
id: 'wf',
|