Skip to content

Commit be7b7e2

Browse files
rochdevtlhunter
authored andcommitted
update encoding format and decode manually
1 parent c7384aa commit be7b7e2

File tree

4 files changed

+224
-258
lines changed

4 files changed

+224
-258
lines changed

benchmark/sirun/plugin-koa/internal-tracer/encoder.js

Lines changed: 11 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { Client } = require('./client')
77
const processStartTime = BigInt(Date.now() * 1e6)
88
const processStartTicks = process.hrtime.bigint()
99
const now = () => Number(processStartTime + process.hrtime.bigint() - processStartTicks)
10-
const service = process.env.DD_SERVICE || 'unnamed-node-app'
10+
// const service = process.env.DD_SERVICE || 'unnamed-node-app'
1111
const ARRAY_OF_TWO = 0x92
1212
const SOFT_LIMIT = 8 * 1024 * 1024 // 8MB
1313
const flushInterval = 2000
@@ -52,8 +52,9 @@ class Encoder {
5252
// resource comes from mixing http method and route
5353
// error will be its own event
5454

55-
this._encodeFixArray(bytes, 7)
55+
this._encodeFixArray(bytes, 2)
5656
this._encodeShort(bytes, eventTypes.KOA_REQUEST_START) // implied: name
57+
this._encodeFixArray(bytes, 6)
5758
this._encodeLong(bytes, now())
5859
this._encodeId(bytes, store.traceContext.traceId)
5960
this._encodeId(bytes, store.traceContext.spanId)
@@ -70,8 +71,9 @@ class Encoder {
7071

7172
if (!store || !store.traceContext) return
7273

73-
this._encodeFixArray(bytes, 5)
74+
this._encodeFixArray(bytes, 2)
7475
this._encodeShort(bytes, eventTypes.KOA_REQUEST_FINISH) // implied: name
76+
this._encodeFixArray(bytes, 4)
7577
this._encodeLong(bytes, now())
7678
this._encodeId(bytes, store.traceContext.traceId)
7779
this._encodeId(bytes, store.traceContext.spanId)
@@ -86,8 +88,9 @@ class Encoder {
8688

8789
if (!store || !store.traceContext) return // TODO: support errors without tracing
8890

89-
this._encodeFixArray(bytes, 7)
91+
this._encodeFixArray(bytes, 2)
9092
this._encodeShort(bytes, eventTypes.ERROR) // implied: name
93+
this._encodeFixArray(bytes, 6)
9194
this._encodeLong(bytes, now())
9295
this._encodeId(bytes, store.traceContext.traceId)
9396
this._encodeId(bytes, store.traceContext.spanId)
@@ -98,8 +101,7 @@ class Encoder {
98101
this._afterEncode()
99102
}
100103

101-
// TODO: support new payload format
102-
makePayload05 () {
104+
makePayload () {
103105
const prefixSize = 1
104106
const stringSize = this._stringBytes.length + 5
105107
const eventSize = this._eventBytes.length + 5
@@ -110,31 +112,7 @@ class Encoder {
110112
buffer[offset++] = ARRAY_OF_TWO
111113

112114
offset = this._writeStrings(buffer, offset)
113-
offset = this._writeEvents(buffer, offset)
114-
115-
this._reset()
116-
117-
return buffer
118-
}
119-
120-
makePayload () {
121-
this._encodeMap(this._metadataBytes, { service }) // HACK
122-
123-
const metadataBytes = this._metadataBytes
124-
const metadataSize = metadataBytes.length + 9
125-
const eventSize = this._eventBytes.length + 5 + 7
126-
const buffer = Buffer.allocUnsafe(1 + metadataSize + eventSize)
127-
128-
let offset = 0
129-
130-
buffer[offset++] = 0x82 // fixmap(2)
131-
132-
buffer[offset++] = 0xa8 // fixstr(8)
133-
offset += buffer.write('metadata', offset)
134-
offset += metadataBytes.buffer.copy(buffer, offset, 0, metadataBytes.length)
135-
136-
buffer[offset++] = 0xa6 // fixstr(6)
137-
offset += buffer.write('events', offset)
115+
// TODO: add metadata
138116
offset = this._writeEvents(buffer, offset)
139117

140118
this._reset()
@@ -308,17 +286,9 @@ class Encoder {
308286
}
309287
}
310288

311-
_encodeString05 (bytes, value = '') {
312-
this._cacheString(value)
313-
this._encodeInteger(bytes, this._stringMap[value])
314-
}
315-
316289
_encodeString (bytes, value = '') {
317290
this._cacheString(value)
318-
319-
const { start, end } = this._stringMap[value]
320-
321-
this._stringBytes.copy(bytes, start, end)
291+
this._encodeInteger(bytes, this._stringMap[value])
322292
}
323293

324294
_encodeFloat (bytes, value) {
@@ -341,23 +311,13 @@ class Encoder {
341311
}
342312
}
343313

344-
_cacheString05 (value) {
314+
_cacheString (value) {
345315
if (!(value in this._stringMap)) {
346316
this._stringMap[value] = this._stringCount++
347317
this._stringBytes.write(value)
348318
}
349319
}
350320

351-
_cacheString (value) {
352-
if (!(value in this._stringMap)) {
353-
this._stringCount++
354-
this._stringMap[value] = {
355-
start: this._stringBytes.length,
356-
end: this._stringBytes.length + this._stringBytes.write(value)
357-
}
358-
}
359-
}
360-
361321
_writeArrayPrefix (buffer, offset, count) {
362322
buffer[offset++] = 0xdd
363323
buffer.writeUInt32BE(count, offset)

collector/Cargo.lock

Lines changed: 0 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

collector/Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ name = "dd-trace-collector"
33
version = "0.1.0"
44
edition = "2021"
55

6+
[profile.release]
7+
codegen-units = 1
8+
lto = true
9+
opt-level = 3
10+
panic = "abort"
11+
strip = true
12+
613
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
714

815
[dependencies]
916
hyper = { version = "0.14.24", features = ["full"] }
1017
rmp = "0.8.11"
11-
rmp-serde = "1.1.1"
12-
serde = { version = "1.0.152", features = ["derive"] }
13-
serde_json = "1.0.93"
1418
tokio = { version = "1.25.0", features = ["full"] }

0 commit comments

Comments
 (0)