Skip to content

Commit

Permalink
replace msgpack-lite with official library for tests (#5173)
Browse files Browse the repository at this point in the history
* replace msgpack-lite with official library for tests

* remove int64-buffer

* fix serializing traces in tests

* replace bigint with int instead of str

* fix moleculer test

* fix llmobs tests

* fix langchain tests
  • Loading branch information
rochdev authored and watson committed Jan 31, 2025
1 parent aac2baf commit d43c70a
Show file tree
Hide file tree
Showing 20 changed files with 87 additions and 124 deletions.
3 changes: 1 addition & 2 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dev,@apollo/server,MIT,Copyright (c) 2016-2020 Apollo Graph, Inc. (Formerly Mete
dev,@types/node,MIT,Copyright Authors
dev,@eslint/eslintrc,MIT,Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
dev,@eslint/js,MIT,Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
dev,@msgpack/msgpack,ISC,Copyright 2019 The MessagePack Community
dev,@stylistic/eslint-plugin-js,MIT,Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
dev,autocannon,MIT,Copyright 2016 Matteo Collina
dev,aws-sdk,Apache 2.0,Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Expand All @@ -58,12 +59,10 @@ dev,get-port,MIT,Copyright Sindre Sorhus
dev,glob,ISC,Copyright Isaac Z. Schlueter and Contributors
dev,globals,MIT,Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
dev,graphql,MIT,Copyright 2015 Facebook Inc.
dev,int64-buffer,MIT,Copyright 2015-2016 Yusuke Kawasaki
dev,jszip,MIT,Copyright 2015-2016 Stuart Knightley and contributors
dev,knex,MIT,Copyright (c) 2013-present Tim Griesser
dev,mkdirp,MIT,Copyright 2010 James Halliday
dev,mocha,MIT,Copyright 2011-2018 JS Foundation and contributors https://js.foundation
dev,msgpack-lite,MIT,Copyright 2015 Yusuke Kawasaki
dev,multer,MIT,Copyright 2014 Hage Yaapa
dev,nock,MIT,Copyright 2017 Pedro Teixeira and other contributors
dev,nyc,ISC,Copyright 2015 Contributors
Expand Down
7 changes: 3 additions & 4 deletions integration-tests/ci-visibility-intake.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const express = require('express')
const bodyParser = require('body-parser')
const msgpack = require('msgpack-lite')
const codec = msgpack.createCodec({ int64: true })
const msgpack = require('@msgpack/msgpack')
const http = require('http')
const multer = require('multer')
const upload = multer()
Expand Down Expand Up @@ -81,7 +80,7 @@ class FakeCiVisIntake extends FakeAgent {
res.status(200).send({ rate_by_service: { 'service:,env:': 1 } })
this.emit('message', {
headers: req.headers,
payload: msgpack.decode(req.body, { codec }),
payload: msgpack.decode(req.body, { useBigInt64: true }),
url: req.url
})
})
Expand All @@ -100,7 +99,7 @@ class FakeCiVisIntake extends FakeAgent {
res.status(200).send('OK')
this.emit('message', {
headers: req.headers,
payload: msgpack.decode(req.body, { codec }),
payload: msgpack.decode(req.body, { useBigInt64: true }),
url: req.url
})
}, waitingTime || 0)
Expand Down
5 changes: 2 additions & 3 deletions integration-tests/helpers/fake-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const EventEmitter = require('events')
const http = require('http')
const express = require('express')
const bodyParser = require('body-parser')
const msgpack = require('msgpack-lite')
const codec = msgpack.createCodec({ int64: true })
const msgpack = require('@msgpack/msgpack')
const upload = require('multer')()

module.exports = class FakeAgent extends EventEmitter {
Expand Down Expand Up @@ -241,7 +240,7 @@ function buildExpressServer (agent) {
res.status(200).send({ rate_by_service: { 'service:,env:': 1 } })
agent.emit('message', {
headers: req.headers,
payload: msgpack.decode(req.body, { codec })
payload: msgpack.decode(req.body, { useBigInt64: true })
})
})

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"@apollo/server": "^4.11.0",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.11.1",
"@msgpack/msgpack": "^3.0.0-beta3",
"@stylistic/eslint-plugin-js": "^2.8.0",
"@types/node": "^16.0.0",
"autocannon": "^4.5.2",
Expand All @@ -142,12 +143,10 @@
"glob": "^7.1.6",
"globals": "^15.10.0",
"graphql": "0.13.2",
"int64-buffer": "^0.1.9",
"jszip": "^3.5.0",
"knex": "^2.4.2",
"mkdirp": "^3.0.1",
"mocha": "^10",
"msgpack-lite": "^0.1.26",
"multer": "^1.4.5-lts.1",
"nock": "^11.3.3",
"nyc": "^15.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/datadog-plugin-moleculer/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const os = require('os')
const agent = require('../../dd-trace/test/plugins/agent')
const { expectedSchema, rawExpectedSchema } = require('./naming')

const sort = trace => trace.sort((a, b) => a.start.toNumber() - b.start.toNumber())
const sort = trace => trace.sort((a, b) => Number(a.start - b.start))

describe('Plugin', () => {
let broker
Expand Down
9 changes: 4 additions & 5 deletions packages/datadog-plugin-net/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const dns = require('dns')
const agent = require('../../dd-trace/test/plugins/agent')
const { expectSomeSpan } = require('../../dd-trace/test/plugins/helpers')
const { Int64BE } = require('int64-buffer') // TODO remove dependency
const { ERROR_MESSAGE, ERROR_TYPE, ERROR_STACK } = require('../../dd-trace/src/constants')

describe('Plugin', () => {
Expand Down Expand Up @@ -66,7 +65,7 @@ describe('Plugin', () => {
'span.kind': 'client',
'ipc.path': '/tmp/dd-trace.sock'
},
parent_id: new Int64BE(parent.context()._spanId._buffer)
parent_id: BigInt(parent.context()._spanId.toString(10))
}).then(done).catch(done)

tracer.scope().activate(parent, () => {
Expand Down Expand Up @@ -121,7 +120,7 @@ describe('Plugin', () => {
'tcp.remote.port': port,
'tcp.local.port': socket.localPort
},
parent_id: new Int64BE(parent.context()._spanId._buffer)
parent_id: BigInt(parent.context()._spanId.toString(10))
}, 2000).then(done).catch(done)
})
})
Expand Down Expand Up @@ -152,7 +151,7 @@ describe('Plugin', () => {
'tcp.remote.port': port,
'tcp.local.port': socket.localPort
},
parent_id: new Int64BE(parent.context()._spanId._buffer)
parent_id: BigInt(parent.context()._spanId.toString(10))
}).then(done).catch(done)
})
})
Expand All @@ -168,7 +167,7 @@ describe('Plugin', () => {
'span.kind': 'client',
'ipc.path': '/tmp/dd-trace.sock'
},
parent_id: new Int64BE(parent.context()._spanId._buffer)
parent_id: BigInt(parent.context()._spanId.toString(10))
}).then(done).catch(done)

tracer.scope().activate(parent, () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/dd-trace/src/id.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ let batch = 0
// Internal representation of a trace or span ID.
class Identifier {
constructor (value, radix = 16) {
this._isUint64BE = true // msgpack-lite compatibility
this._buffer = radix === 16
? createBuffer(value)
: fromString(value, radix)
Expand All @@ -31,7 +30,6 @@ class Identifier {
return this._buffer
}

// msgpack-lite compatibility
toArray () {
if (this._buffer.length === 8) {
return this._buffer
Expand Down
9 changes: 4 additions & 5 deletions packages/dd-trace/test/datastreams/processor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require('../setup/tap')

const { hostname } = require('os')
const Uint64 = require('int64-buffer').Uint64BE

const { LogCollapsingLowestDenseDDSketch } = require('@datadog/sketches-js')

Expand Down Expand Up @@ -66,8 +65,8 @@ describe('StatsPoint', () => {
payloadSize.accept(100)

const encoded = aggStats.encode()
expect(encoded.Hash.toString()).to.equal(new Uint64(DEFAULT_CURRENT_HASH).toString())
expect(encoded.ParentHash.toString()).to.equal(new Uint64(DEFAULT_PARENT_HASH).toString())
expect(encoded.Hash.toString(16)).to.equal(DEFAULT_CURRENT_HASH.toString('hex'))
expect(encoded.ParentHash.toString(16)).to.equal(DEFAULT_PARENT_HASH.toString('hex'))
expect(encoded.EdgeTags).to.deep.equal(aggStats.edgeTags)
expect(encoded.EdgeLatency).to.deep.equal(edgeLatency.toProto())
expect(encoded.PathwayLatency).to.deep.equal(pathwayLatency.toProto())
Expand Down Expand Up @@ -278,8 +277,8 @@ describe('DataStreamsProcessor', () => {
payloadSize.accept(mockCheckpoint.payloadSize)

const encoded = checkpointBucket.encode()
expect(encoded.Hash.toString()).to.equal(new Uint64(DEFAULT_CURRENT_HASH).toString())
expect(encoded.ParentHash.toString()).to.equal(new Uint64(DEFAULT_PARENT_HASH).toString())
expect(encoded.Hash.toString(16)).to.equal(DEFAULT_CURRENT_HASH.toString('hex'))
expect(encoded.ParentHash.toString(16)).to.equal(DEFAULT_PARENT_HASH.toString('hex'))
expect(encoded.EdgeTags).to.deep.equal(mockCheckpoint.edgeTags)
expect(encoded.EdgeLatency).to.deep.equal(edgeLatency.toProto())
expect(encoded.PathwayLatency).to.deep.equal(pathwayLatency.toProto())
Expand Down
5 changes: 2 additions & 3 deletions packages/dd-trace/test/datastreams/writer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
require('../setup/tap')
const pkg = require('../../../../package.json')
const stubRequest = sinon.stub()
const msgpack = require('msgpack-lite')
const codec = msgpack.createCodec({ int64: true })
const msgpack = require('@msgpack/msgpack')

const stubZlib = {
gzip: (payload, _opts, fn) => {
Expand Down Expand Up @@ -34,7 +33,7 @@ describe('DataStreamWriter unix', () => {
writer = new DataStreamsWriter(unixConfig)
writer.flush({})
const stubRequestCall = stubRequest.getCalls()[0]
const decodedPayload = msgpack.decode(stubRequestCall?.args[0], { codec })
const decodedPayload = msgpack.decode(stubRequestCall?.args[0])
const requestOptions = stubRequestCall?.args[1]
expect(decodedPayload).to.deep.equal({})
expect(requestOptions).to.deep.equal({
Expand Down
5 changes: 2 additions & 3 deletions packages/dd-trace/test/dd-trace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require('./setup/tap')

const Uint64BE = require('int64-buffer').Uint64BE
const agent = require('./plugins/agent')

const { SAMPLING_PRIORITY_KEY, DECISION_MAKER_KEY } = require('../src/constants')
Expand Down Expand Up @@ -34,8 +33,8 @@ describe('dd-trace', () => {
expect(payload[0][0].service).to.equal('test')
expect(payload[0][0].name).to.equal('hello')
expect(payload[0][0].resource).to.equal('/hello/:name')
expect(payload[0][0].start).to.be.instanceof(Uint64BE)
expect(payload[0][0].duration).to.be.instanceof(Uint64BE)
expect(typeof payload[0][0].start).to.equal('bigint')
expect(typeof payload[0][0].duration).to.equal('bigint')
expect(payload[0][0].metrics).to.have.property(SAMPLING_PRIORITY_KEY)
expect(payload[0][0].meta).to.have.property(DECISION_MAKER_KEY)
})
Expand Down
Loading

0 comments on commit d43c70a

Please sign in to comment.