-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
112 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
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') | ||
/** | ||
* | ||
* @param rows {Row[]} | ||
* @param script {Token} | ||
*/ | ||
function postProcess (rows, script) { | ||
const selectAttrs = script.Children('aggregator') | ||
.filter(x => x.Child('fn').value === 'select') | ||
.map(x => x.Children('label_name')) | ||
.reduce((acc, x) => { | ||
let attrs = x.map(y => ({ | ||
name: y.value, | ||
path: y.value.split('.').filter(y => y) | ||
})) | ||
if (attrs[0] === 'span' || attrs[0] === 'resource') { | ||
attrs = attrs.slice(1) | ||
} | ||
return [...acc, ...attrs] | ||
}, []) | ||
rows = rows.map(row => ({ | ||
...row, | ||
objs: row.payload.map((payload, i) => { | ||
let span = 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) | ||
} | ||
return null | ||
}) | ||
})) | ||
const spans = (row) => row.span_id.map((spanId, i) => ({ | ||
spanID: spanId, | ||
startTimeUnixNano: row.timestamp_ns[i], | ||
durationNanos: row.duration[i], | ||
attributes: selectAttrs.map(attr => ({ | ||
key: attr.name, | ||
value: { | ||
stringValue: (row.objs[i].tags.find(t => t[0] === attr.path.join('.')) || [null, null])[1] | ||
} | ||
})).filter(x => x.value.stringValue) | ||
})) | ||
const traces = rows.map(row => ({ | ||
traceID: row.trace_id, | ||
rootServiceName: row.root_service_name, | ||
rootTraceName: row.root_trace_name, | ||
startTimeUnixNano: row.start_time_unix_nano, | ||
durationMs: row.duration_ms, | ||
spanSet: { spans: spans(row) }, | ||
spanSets: [ | ||
{ | ||
spans: spans(row), | ||
matched: row.span_id.length | ||
} | ||
] | ||
})) | ||
return traces | ||
} | ||
|
||
module.exports = { | ||
postProcess | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export interface Row { | ||
trace_id: string; | ||
span_id: string[]; | ||
duration: string[]; | ||
timestamp_ns: string[]; | ||
start_time_unix_nano: string; | ||
duration_ms: number; | ||
root_service_name: string; | ||
payload: string[]; | ||
payload_type: number[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters