Skip to content

Commit

Permalink
fix & e2e cover
Browse files Browse the repository at this point in the history
  • Loading branch information
akvlad committed Oct 8, 2024
1 parent 2922578 commit 303097a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions parser/registry/smart_optimizations/optimization_v3_2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getDuration, preJoinLabels, dist } = require('../common')
const { getDuration, preJoinLabels, dist, sharedParamNames } = require('../common')
const reg = require('./log_range_agg_reg_v3_2')
const Sql = require('@cloki/clickhouse-sql')
const { DATABASE_NAME, checkVersion } = require('../../../lib/utils')
Expand Down Expand Up @@ -44,24 +44,30 @@ function isLogPipeline (token) {
*/
module.exports.apply = (token, fromNS, toNS, stepNS) => {
fromNS = Math.floor(fromNS / 15000000000) * 15000000000
const fromParam = new Sql.Parameter(sharedParamNames.from)
const toParam = new Sql.Parameter(sharedParamNames.to)
const tsClause = toNS
? Sql.between('samples.timestamp_ns', fromNS, toNS)
: Sql.Gt('samples.timestamp_ns', fromNS)
let q = (new Sql.Select())
.select(['samples.fingerprint', 'fingerprint'])
.from([`${DATABASE_NAME()}.metrics_15s${_dist}`, 'samples'])
.where(tsClause)
.addParam(fromParam)
.addParam(toParam)
fromParam.set(fromNS)
toParam.set(toNS)

q.ctx = {
step: stepNS / 1000000000,
inline: !!clusterName
}

preJoinLabels(token, q, dist)

for (const streamSelectorRule of token.Children('log_stream_selector_rule')) {
q = streamSelectorReg[streamSelectorRule.Child('operator').value](streamSelectorRule, q)
}
preJoinLabels(token, q, dist)
q = q.groupBy('labels')

const lra = token.Child('log_range_aggregation')
q = reg[lra.Child('log_range_aggregation_fn').value](lra, q)
Expand Down

0 comments on commit 303097a

Please sign in to comment.