11const configs = new reports . HTTPArchiveReports ( )
22const metrics = configs . listMetrics ( )
3+ const lenses = configs . lenses ;
34
45const bucket = 'httparchive'
56const storagePath = '/reports/dev/'
@@ -8,31 +9,30 @@ const storagePath = '/reports/dev/'
89const startDate = '2024-12-01' // constants.currentMonth;
910const endDate = '2024-12-01' // constants.currentMonth;
1011
11- function generateExportPath ( metric , sql , params ) {
12- if ( sql . type === 'histogram' ) {
13- return `${ storagePath } ${ params . date . replaceAll ( '-' , '_' ) } /${ metric . id } .json`
14- } else if ( sql . type === 'timeseries' ) {
15- return `${ storagePath } ${ metric . id } .json`
12+ function generateExportPath ( ctx , params ) {
13+ if ( params . sql . type === 'histogram' ) {
14+ return `${ storagePath } ${ params . date . replaceAll ( '-' , '_' ) } /${ params . metric . id } .json`
15+ } else if ( params . sql . type === 'timeseries' ) {
16+ return `${ storagePath } ${ params . metric . id } .json`
1617 } else {
1718 throw new Error ( 'Unknown SQL type' )
1819 }
1920}
2021
21- function generateExportQuery ( metric , sql , params , ctx ) {
22+ function generateExportQuery ( ctx , params ) {
2223 let query = ''
23- if ( sql . type === 'histogram' ) {
24+ if ( params . sql . type === 'histogram' ) {
2425 query = `
25- SELECT
26- * EXCEPT(date)
27- FROM ${ ctx . self ( ) }
26+ SELECT * EXCEPT(date)
27+ FROM \`reports.${ params . sql . type } \`
2828WHERE date = '${ params . date } '
2929`
30- } else if ( sql . type === 'timeseries' ) {
30+ } else if ( params . sql . type === 'timeseries' ) {
3131 query = `
3232SELECT
3333 FORMAT_DATE('%Y_%m_%d', date) AS date,
3434 * EXCEPT(date)
35- FROM ${ ctx . self ( ) }
35+ FROM \`reports. ${ params . sql . type } \`
3636`
3737 } else {
3838 throw new Error ( 'Unknown SQL type' )
@@ -42,17 +42,6 @@ FROM ${ctx.self()}
4242 return queryOutput
4343}
4444
45- const lenses = {
46- all : '' ,
47- top1k : 'AND rank <= 1000' ,
48- top10k : 'AND rank <= 10000' ,
49- top100k : 'AND rank <= 100000' ,
50- top1m : 'AND rank <= 1000000' ,
51- drupal : 'AND \'Drupal\' IN UNNEST(technologies.technology)' ,
52- magento : 'AND \'Magento\' IN UNNEST(technologies.technology)' ,
53- wordpress : 'AND \'WordPress\' IN UNNEST(technologies.technology)'
54- }
55-
5645const iterations = [ ]
5746// dates
5847for (
@@ -91,25 +80,23 @@ CREATE TABLE IF NOT EXISTS reports.${params.sql.type} (
9180 data JSON
9281)
9382PARTITION BY date
94- CLUSTER BY metric, lens;
83+ CLUSTER BY metric, lens, client ;
9584
9685DELETE FROM reports.${ params . sql . type }
9786WHERE date = '${ params . date } '
98- AND metric = '${ params . metric . id } '
99- AND lens = '${ params . lens . sql } ';
87+ AND metric = '${ params . metric . id } ';
10088
101- INSERT INTO reports.${ params . sql . type }
102- ${ params . sql . query ( ctx , params ) } ;
89+ INSERT INTO reports.${ params . sql . type } ${ params . sql . query ( ctx , params ) } ;
10390
10491SELECT
10592reports.run_export_job(
10693 JSON '''{
10794 "destination": "cloud_storage",
10895 "config": {
10996 "bucket": "${ bucket } ",
110- "name": "${ generateExportPath ( params . metric , params . sql , params ) } "
97+ "name": "${ generateExportPath ( ctx , params ) } "
11198 },
112- "query": "${ generateExportQuery ( params . metric , params . sql , params , ctx ) } "
99+ "query": "${ generateExportQuery ( ctx , params ) } "
113100 }'''
114101);
115102 ` )
0 commit comments