Skip to content

Commit b592684

Browse files
committed
pql optimization init
1 parent 9dcd3b3 commit b592684

20 files changed

+1122
-24
lines changed

promql/index.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,14 @@ const getIdxSubquery = (conds, fromMs, toMs) => {
117117
).groupBy('fingerprint')
118118
}
119119

120-
module.exports.getData = async (matchers, fromMs, toMs) => {
120+
module.exports.getData = async (matchers, fromMs, toMs, subqueries) => {
121121
const db = DATABASE_NAME()
122+
const subq = (subqueries || {})[getMetricName(matchers)]
123+
if (subq) {
124+
const data = await rawRequest(subq + ' FORMAT RowBinary',
125+
null, db, { responseType: 'arraybuffer' })
126+
return new Uint8Array(data.data)
127+
}
122128
const matches = getMatchersIdxCond(matchers)
123129
const idx = getIdxSubquery(matches, fromMs, toMs)
124130
const withIdx = new Sql.With('idx', idx, !!clusterName)
@@ -176,4 +182,12 @@ module.exports.getData = async (matchers, fromMs, toMs) => {
176182
return new Uint8Array(data.data)
177183
}
178184

185+
function getMetricName(matchers) {
186+
for (const matcher of matchers) {
187+
if (matcher[0] === '__name__' && matcher[1] === '=') {
188+
return matcher[2]
189+
}
190+
}
191+
}
192+
179193
prometheus.getData = module.exports.getData

0 commit comments

Comments
 (0)