diff --git a/.changeset/little-parents-rescue.md b/.changeset/little-parents-rescue.md new file mode 100644 index 00000000..a9c1d5d6 --- /dev/null +++ b/.changeset/little-parents-rescue.md @@ -0,0 +1,7 @@ +--- +"@hyperdx/common-utils": patch +"@hyperdx/api": patch +"@hyperdx/app": patch +--- + +fix: Ensure percentile aggregations on histograms don't create invalid SQL queries due to improperly escaped aliases. diff --git a/packages/common-utils/src/__tests__/__snapshots__/renderChartConfig.test.ts.snap b/packages/common-utils/src/__tests__/__snapshots__/renderChartConfig.test.ts.snap index e1933afc..826e0d23 100644 --- a/packages/common-utils/src/__tests__/__snapshots__/renderChartConfig.test.ts.snap +++ b/packages/common-utils/src/__tests__/__snapshots__/renderChartConfig.test.ts.snap @@ -82,10 +82,10 @@ exports[`renderChartConfig histogram metric queries should generate a query with WHEN upper_bound = inf THEN point[upper_idx - 1].2 WHEN lower_bound = inf THEN point[1].2 ELSE lower_bound + (upper_bound - lower_bound) * ((rank - lower_count) / (upper_count - lower_count)) - END AS Value + END AS \\"Value\\" FROM points WHERE length(point) > 1 AND total > 0 - ) SELECT \`__hdx_time_bucket\`, group, Value FROM metrics WHERE (\`__hdx_time_bucket\` >= fromUnixTimestamp64Milli(1739318400000) AND \`__hdx_time_bucket\` <= fromUnixTimestamp64Milli(1765670400000)) LIMIT 10 SETTINGS short_circuit_function_evaluation = 'force_enable'" + ) SELECT \`__hdx_time_bucket\`, group, \\"Value\\" FROM metrics WHERE (\`__hdx_time_bucket\` >= fromUnixTimestamp64Milli(1739318400000) AND \`__hdx_time_bucket\` <= fromUnixTimestamp64Milli(1765670400000)) LIMIT 10 SETTINGS short_circuit_function_evaluation = 'force_enable'" `; exports[`renderChartConfig histogram metric queries should generate a query without grouping but time bucketing 1`] = ` @@ -166,10 +166,10 @@ exports[`renderChartConfig histogram metric queries should generate a query with WHEN upper_bound = inf THEN point[upper_idx - 1].2 WHEN lower_bound = inf THEN point[1].2 ELSE lower_bound + (upper_bound - lower_bound) * ((rank - lower_count) / (upper_count - lower_count)) - END AS Value + END AS \\"Value\\" FROM points WHERE length(point) > 1 AND total > 0 - ) SELECT \`__hdx_time_bucket\`, Value FROM metrics WHERE (\`__hdx_time_bucket\` >= fromUnixTimestamp64Milli(1739318400000) AND \`__hdx_time_bucket\` <= fromUnixTimestamp64Milli(1765670400000)) LIMIT 10 SETTINGS short_circuit_function_evaluation = 'force_enable'" + ) SELECT \`__hdx_time_bucket\`, \\"Value\\" FROM metrics WHERE (\`__hdx_time_bucket\` >= fromUnixTimestamp64Milli(1739318400000) AND \`__hdx_time_bucket\` <= fromUnixTimestamp64Milli(1765670400000)) LIMIT 10 SETTINGS short_circuit_function_evaluation = 'force_enable'" `; exports[`renderChartConfig histogram metric queries should generate a query without grouping or time bucketing 1`] = ` @@ -250,10 +250,10 @@ exports[`renderChartConfig histogram metric queries should generate a query with WHEN upper_bound = inf THEN point[upper_idx - 1].2 WHEN lower_bound = inf THEN point[1].2 ELSE lower_bound + (upper_bound - lower_bound) * ((rank - lower_count) / (upper_count - lower_count)) - END AS Value + END AS \\"Value\\" FROM points WHERE length(point) > 1 AND total > 0 - ) SELECT \`__hdx_time_bucket\`, Value FROM metrics WHERE (\`__hdx_time_bucket\` >= fromUnixTimestamp64Milli(1739318400000) AND \`__hdx_time_bucket\` <= fromUnixTimestamp64Milli(1765670400000)) LIMIT 10 SETTINGS short_circuit_function_evaluation = 'force_enable'" + ) SELECT \`__hdx_time_bucket\`, \\"Value\\" FROM metrics WHERE (\`__hdx_time_bucket\` >= fromUnixTimestamp64Milli(1739318400000) AND \`__hdx_time_bucket\` <= fromUnixTimestamp64Milli(1765670400000)) LIMIT 10 SETTINGS short_circuit_function_evaluation = 'force_enable'" `; exports[`renderChartConfig should generate sql for a single gauge metric 1`] = ` diff --git a/packages/common-utils/src/renderChartConfig.ts b/packages/common-utils/src/renderChartConfig.ts index c12ed21e..9dd43fee 100644 --- a/packages/common-utils/src/renderChartConfig.ts +++ b/packages/common-utils/src/renderChartConfig.ts @@ -1250,13 +1250,13 @@ async function translateMetricChartConfig( WHEN upper_bound = inf THEN point[upper_idx - 1].2 WHEN lower_bound = inf THEN point[1].2 ELSE lower_bound + (upper_bound - lower_bound) * ((rank - lower_count) / (upper_count - lower_count)) - END AS ${valueAlias} + END AS "${valueAlias}" FROM points WHERE length(point) > 1 AND total > 0 `, }, ], - select: `\`__hdx_time_bucket\`${groupBy ? ', group' : ''}, ${valueAlias}`, + select: `\`__hdx_time_bucket\`${groupBy ? ', group' : ''}, "${valueAlias}"`, from: { databaseName: '', tableName: 'metrics',