11const configs = new reports . HTTPArchiveReports ( )
22const metrics = configs . listMetrics ( )
33
4+ const bucket = 'httparchive'
5+ const storagePath = '/reports/'
6+
7+ function generateExportQuery ( metric , sql , params , ctx ) {
8+ if ( sql . type === 'histogram' ) {
9+ return `
10+ SELECT
11+ * EXCEPT(date)
12+ FROM ${ ctx . self ( ) }
13+ WHERE date = '${ params . date } '
14+ `
15+ } else if ( sql . type === 'timeseries' ) {
16+ return `
17+ SELECT
18+ FORMAT_DATE('%Y_%m_%d', date) AS date,
19+ * EXCEPT(date)
20+ FROM reports.${ metric } _timeseries
21+ ` } else {
22+ throw new Error ( 'Unknown SQL type' )
23+ }
24+ }
25+
26+ function generateExportPath ( metric , sql , params ) {
27+ if ( sql . type === 'histogram' ) {
28+ return `${ storagePath } ${ params . date . replaceAll ( '-' , '_' ) } /${ metric } .json`
29+ } else if ( sql . type === 'timeseries' ) {
30+ return `${ storagePath } ${ metric } .json`
31+ } else {
32+ throw new Error ( 'Unknown SQL type' )
33+ }
34+ }
35+
436const iterations = [ ]
537for (
6- let month = constants . currentMonth ; month >= constants . currentMonth ; month = constants . fnPastMonth ( month ) ) {
38+ let date = constants . currentMonth ; month >= constants . currentMonth ; month = constants . fnPastMonth ( month ) ) {
739 iterations . push ( {
8- date : month ,
9- devRankFilter : constants . devRankFilter
40+ date : date
1041 } )
1142}
1243
@@ -31,10 +62,10 @@ SELECT
3162 JSON '''{
3263 "destination": "cloud_storage",
3364 "config": {
34- "bucket": "httparchive ",
35- "name": "reports/ ${ constants . environment } / ${ metric . id } _ ${ sql . type } _ ${ params . date } .json "
65+ "bucket": "${ bucket } ",
66+ "name": "${ generateExportPath ( metric , sql , params ) } "
3667 },
37- "query": "SELECT FORMAT_DATE('%Y_%m_%d', date) AS date, * EXCEPT(date) FROM ${ ctx . self ( ) } "
68+ "query": "${ generateExportQuery ( metric , sql , params , ctx ) } "}
3869 }'''
3970 );
4071 ` )
@@ -57,17 +88,14 @@ INSERT INTO reports.${metric.id}_${sql.type}` + sql.query(ctx, params)
5788 JSON '''{
5889 "destination": "cloud_storage",
5990 "config": {
60- "bucket": "httparchive ",
61- "name": "reports/ ${ constants . environment } / ${ metric . id } _ ${ sql . type } _ ${ params . date } .json "
91+ "bucket": "${ bucket } ",
92+ "name": "${ generateExportPath ( metric , sql , params ) } "
6293 },
63- "query": "SELECT FORMAT_DATE('%Y_%m_%d', date) AS date, * EXCEPT(date) FROM ${ ctx . self ( ) } "
94+ "query": "${ generateExportQuery ( metric , sql , params , ctx ) } "}
6495 }'''
6596 );
6697 ` )
6798 } )
6899 } )
69100 } )
70101}
71-
72- // --"query": "SELECT * EXCEPT(date) FROM ${ctx.self()} WHERE date = '${params.date}'"
73- // `${this.storagePath}${date.replaceAll('-', '_')}/${metric}.json`
0 commit comments