4
4
import * as fs from 'fs/promises' ;
5
5
import { inspect } from 'util' ;
6
6
console . log ( process . versions ) ;
7
- const API_PATH = "https://performance-monitoring-service-rest.server-tig.prod.corp.mongodb.com/raw_perf_results"
7
+ const API_PATH = "https://performance-monitoring-service-rest.server-tig.prod.corp.mongodb.com/raw_perf_results" ;
8
8
9
9
const resultFile = process . argv [ 2 ] ;
10
10
if ( resultFile == undefined ) {
@@ -18,13 +18,29 @@ const {
18
18
project,
19
19
task_id,
20
20
task_name,
21
- revision_order_id : order ,
21
+ revision_order_id,
22
22
build_variant : variant ,
23
23
version_id : version
24
24
} = process . env ;
25
25
26
+ const orderSplit = revision_order_id ?. split ( '_' ) ;
27
+ let order = orderSplit ? orderSplit [ orderSplit . length - 1 ] : undefined ;
28
+
29
+ if ( ! order ) throw new Error ( `failed to get order, got "${ order } "` ) ;
30
+
31
+ order = Number ( order ) ;
32
+
33
+ if ( ! Number . isInteger ( order ) ) throw new Error ( `Failed to parse integer from order, got ${ order } ` ) ;
34
+
35
+ let results = await fs . readFile ( resultFile , 'utf8' ) ;
36
+ results = JSON . parse ( results ) ;
37
+
38
+ // FIXME(NODE-6838): We are using dummy dates here just to be able to successfully post our results
39
+ for ( const r of results ) {
40
+ r . info . created_at = new Date ( ) . toISOString ( ) ;
41
+ r . info . completed_at = new Date ( ) . toISOString ( ) ;
42
+ }
26
43
27
- const results = await fs . readFile ( resultFile , 'utf8' ) ;
28
44
const body = {
29
45
id : {
30
46
project,
@@ -36,7 +52,7 @@ const body = {
36
52
execution,
37
53
mainline : requester === 'commit'
38
54
} ,
39
- results : JSON . parse ( results )
55
+ results
40
56
} ;
41
57
42
58
console . log ( inspect ( body , { depth : Infinity } ) ) ;
@@ -49,8 +65,16 @@ const resp = await fetch(API_PATH, {
49
65
body : JSON . stringify ( body )
50
66
} ) ;
51
67
52
- if ( resp . status !== 200 ) {
53
- throw new Error ( `Got status code: ${ resp . status } \nResponse body: ${ await resp . text ( ) } ` ) ;
68
+
69
+ let jsonResponse ;
70
+ try {
71
+ jsonResponse = await resp . json ( ) ;
72
+ } catch ( e ) {
73
+ throw new Error ( "Failed to parse json response" , { cause : e } ) ;
54
74
}
55
75
76
+ console . log ( inspect ( jsonResponse , { depth : Infinity } ) ) ;
77
+
78
+ if ( ! jsonResponse . message ) throw new Error ( "Didn't get success message" ) ;
79
+
56
80
console . log ( "Successfully posted results" ) ;
0 commit comments