Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

promql optimization: rate & sum #528

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion traceql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const search = async (query, limit, from, to) => {
(a, b) => b.startTimeUnixNano.localeCompare(a.startTimeUnixNano))
)
)
console.log(JSON.stringify(res, 2))
return res
}

Expand Down
25 changes: 14 additions & 11 deletions traceql/post_processor/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
const Otlp = require('../../lib/db/otlp')
const Zipkin = require('../../lib/db/zipkin')
const protobufjs = require('protobufjs')
const path = require('path')
const OTLPSpan = protobufjs.loadSync(path.join(__dirname, '..', '..',
'lib', 'otlp.proto')).lookupType('Span')
const { flatOTLPAttrs, OTLPgetServiceNames } = require('../../lib/utils')
/**
*
* @param rows {Row[]}
Expand All @@ -27,16 +23,23 @@ function postProcess (rows, script) {
...row,
objs: row.payload.map((payload, i) => {
let span = null
let attrs = null
let serviceName = null

switch (row.payload_type[i]) {
case 1:
return new Zipkin(JSON.parse(Buffer.from(payload, 'base64').toString()))
case 2:
span = OTLPSpan.toObject(
OTLPSpan.decode(Buffer.from(payload, 'base64')), {
longs: String,
bytes: String
})
return new Otlp(span)
span = JSON.parse(Buffer.from(payload, 'base64').toString())
attrs = flatOTLPAttrs(span.attributes)
serviceName = OTLPgetServiceNames(attrs)
attrs.name = span.name
attrs['service.name'] = serviceName.local
if (serviceName.remote) {
attrs['remoteService.name'] = serviceName.remote
}
attrs = [...Object.entries(attrs)]
return { tags: attrs }
}
return null
})
Expand Down
Loading