Skip to content

Commit

Permalink
pql optimization init
Browse files Browse the repository at this point in the history
  • Loading branch information
akvlad committed Jun 19, 2024
1 parent 9dcd3b3 commit b592684
Show file tree
Hide file tree
Showing 20 changed files with 1,122 additions and 24 deletions.
16 changes: 15 additions & 1 deletion promql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,14 @@ const getIdxSubquery = (conds, fromMs, toMs) => {
).groupBy('fingerprint')
}

module.exports.getData = async (matchers, fromMs, toMs) => {
module.exports.getData = async (matchers, fromMs, toMs, subqueries) => {
const db = DATABASE_NAME()
const subq = (subqueries || {})[getMetricName(matchers)]
if (subq) {
const data = await rawRequest(subq + ' FORMAT RowBinary',
null, db, { responseType: 'arraybuffer' })
return new Uint8Array(data.data)
}
const matches = getMatchersIdxCond(matchers)
const idx = getIdxSubquery(matches, fromMs, toMs)
const withIdx = new Sql.With('idx', idx, !!clusterName)
Expand Down Expand Up @@ -176,4 +182,12 @@ module.exports.getData = async (matchers, fromMs, toMs) => {
return new Uint8Array(data.data)
}

function getMetricName(matchers) {
for (const matcher of matchers) {
if (matcher[0] === '__name__' && matcher[1] === '=') {
return matcher[2]
}
}
}

prometheus.getData = module.exports.getData
Loading

0 comments on commit b592684

Please sign in to comment.