From ef1a3aad4c25de79a05fc887fe694c70dbe698ea Mon Sep 17 00:00:00 2001 From: akvlad Date: Mon, 24 Jun 2024 13:44:43 +0300 Subject: [PATCH] promql optimization: rate & sum --- traceql/index.js | 1 - traceql/post_processor/index.js | 25 ++++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/traceql/index.js b/traceql/index.js index 71690db0..5b0bf729 100644 --- a/traceql/index.js +++ b/traceql/index.js @@ -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 } diff --git a/traceql/post_processor/index.js b/traceql/post_processor/index.js index b3515af5..124711d2 100644 --- a/traceql/post_processor/index.js +++ b/traceql/post_processor/index.js @@ -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[]} @@ -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 })