Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 16d0d3a

Browse files
authored
chore: remove koalas dependency (#6556)
This refactors all of the rest of calesce calls to use native ?? instead of the custom logic. It also fixes small regressions and adds test cases for these with the former change.
1 parent 9ad3c91 commit 16d0d3a

File tree

13 files changed

+96
-41
lines changed

13 files changed

+96
-41
lines changed

LICENSE-3rdparty.csv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ require,import-in-the-middle,Apache license 2.0,Copyright 2021 Datadog Inc.
1616
require,istanbul-lib-coverage,BSD-3-Clause,Copyright 2012-2015 Yahoo! Inc.
1717
require,jest-docblock,MIT,Copyright Meta Platforms, Inc. and affiliates.
1818
require,jsonpath-plus,MIT,Copyright (c) 2011-2019 Stefan Goessner, Subbu Allamaraju, Mike Brevoort, Robert Krahn, Brett Zamir, Richard Schneider
19-
require,koalas,MIT,Copyright 2013-2017 Brian Woodward
2019
require,limiter,MIT,Copyright 2011 John Hurliman
2120
require,lodash.sortby,MIT,Copyright JS Foundation and other contributors
2221
require,lru-cache,ISC,Copyright (c) 2010-2022 Isaac Z. Schlueter and Contributors

integration-tests/appsec/graphql.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('graphql', () => {
1414
let sandbox, cwd, agent, webFile, proc
1515

1616
before(async function () {
17-
sandbox = await createSandbox(['@apollo/server', 'graphql', 'koalas'])
17+
sandbox = await createSandbox(['@apollo/server', 'graphql'])
1818
cwd = sandbox.folder
1919
webFile = path.join(cwd, 'graphql/index.js')
2020
})

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@
130130
"istanbul-lib-coverage": "^3.2.2",
131131
"jest-docblock": "^29.7.0",
132132
"jsonpath-plus": "^10.3.0",
133-
"koalas": "^1.0.2",
134133
"limiter": "^1.1.5",
135134
"lodash.sortby": "^4.7.0",
136135
"lru-cache": "^10.4.3",

packages/datadog-plugin-aws-sdk/src/base.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@ function normalizeConfig (config, serviceIdentifier) {
275275
specificConfig.batchPropagationEnabled ??
276276
getEnvironmentVariable(`DD_TRACE_AWS_SDK_${serviceId}_BATCH_PROPAGATION_ENABLED`) ??
277277
config.batchPropagationEnabled ??
278-
getEnvironmentVariable('DD_TRACE_AWS_SDK_BATCH_PROPAGATION_ENABLED') ??
279-
false
278+
getEnvironmentVariable('DD_TRACE_AWS_SDK_BATCH_PROPAGATION_ENABLED')
280279
)
281280

282281
// Merge the specific config back into the main config

packages/dd-trace/src/config.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const os = require('os')
55
const uuid = require('crypto-randomuuid') // we need to keep the old uuid dep because of cypress
66
const { URL } = require('url')
77
const log = require('./log')
8-
const coalesce = require('koalas')
98
const tagger = require('./tagger')
109
const set = require('../../datadog-core/src/utils/src/set')
1110
const { isTrue, isFalse, normalizeProfilingEnabledValue } = require('./util')
@@ -333,7 +332,7 @@ class Config {
333332
)
334333

335334
const DD_TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH = maybeInt(
336-
getEnvironmentVariable('DD_TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH'),
335+
getEnvironmentVariable('DD_TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH') ??
337336
options.cloudPayloadTagging?.maxDepth
338337
) ?? 10
339338

@@ -998,8 +997,7 @@ class Config {
998997
this._setBoolean(opts, 'runtimeMetricsRuntimeId', options.runtimeMetricsRuntimeId)
999998
this._setArray(opts, 'sampler.spanSamplingRules', reformatSpanSamplingRules(options.spanSamplingRules))
1000999
this._setUnit(opts, 'sampleRate', options.sampleRate ?? options.ingestion.sampleRate)
1001-
const ingestion = options.ingestion || {}
1002-
opts['sampler.rateLimit'] = coalesce(options.rateLimit, ingestion.rateLimit)
1000+
opts['sampler.rateLimit'] = maybeInt(options.rateLimit ?? options.ingestion.rateLimit)
10031001
this._setSamplingRule(opts, 'sampler.rules', options.samplingRules)
10041002
this._setString(opts, 'service', options.service || tags.service)
10051003
opts.serviceMapping = options.serviceMapping

packages/dd-trace/src/profiling/config.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict'
22

3-
const coalesce = require('koalas')
43
const os = require('os')
54
const path = require('path')
65
const { URL, format, pathToFileURL } = require('url')
@@ -59,8 +58,8 @@ class Config {
5958
const host = os.hostname()
6059
const version = options.version ?? DD_VERSION
6160
// Must be longer than one minute so pad with five seconds
62-
const flushInterval = coalesce(options.interval, Number(DD_PROFILING_UPLOAD_PERIOD) * 1000, 65 * 1000)
63-
const uploadTimeout = coalesce(options.uploadTimeout, Number(DD_PROFILING_UPLOAD_TIMEOUT), 60 * 1000)
61+
const flushInterval = options.interval ?? (Number(DD_PROFILING_UPLOAD_PERIOD) * 1000 || 65 * 1000)
62+
const uploadTimeout = options.uploadTimeout ?? (Number(DD_PROFILING_UPLOAD_TIMEOUT) || 60 * 1000)
6463
const sourceMap = options.sourceMap ?? DD_PROFILING_SOURCE_MAP ?? true
6564
const pprofPrefix = options.pprofPrefix ?? DD_PROFILING_PPROF_PREFIX ?? ''
6665

@@ -134,10 +133,10 @@ class Config {
134133
DD_PROFILING_EXPERIMENTAL_OOM_MONITORING_ENABLED ?? oomMonitoringSupported)
135134
checkOptionAllowed(oomMonitoringEnabled, 'OOM monitoring', oomMonitoringSupported)
136135

137-
const heapLimitExtensionSize = coalesce(options.oomHeapLimitExtensionSize,
138-
Number(DD_PROFILING_EXPERIMENTAL_OOM_HEAP_LIMIT_EXTENSION_SIZE), 0)
139-
const maxHeapExtensionCount = coalesce(options.oomMaxHeapExtensionCount,
140-
Number(DD_PROFILING_EXPERIMENTAL_OOM_MAX_HEAP_EXTENSION_COUNT), 0)
136+
const heapLimitExtensionSize = options.oomHeapLimitExtensionSize ??
137+
(Number(DD_PROFILING_EXPERIMENTAL_OOM_HEAP_LIMIT_EXTENSION_SIZE) || 0)
138+
const maxHeapExtensionCount = options.oomMaxHeapExtensionCount ??
139+
(Number(DD_PROFILING_EXPERIMENTAL_OOM_MAX_HEAP_EXTENSION_COUNT) || 0)
141140
const exportStrategies = oomMonitoringEnabled
142141
? ensureOOMExportStrategies(options.oomExportStrategies ?? DD_PROFILING_EXPERIMENTAL_OOM_EXPORT_STRATEGIES ??
143142
[oomExportStrategies.PROCESS], this)
@@ -175,10 +174,10 @@ class Config {
175174
)
176175
checkOptionWithSamplingContextAllowed(this.cpuProfilingEnabled, 'CPU profiling')
177176

178-
this.samplingInterval = coalesce(options.samplingInterval, 1e3 / 99) // 99hz in millis
177+
this.samplingInterval = options.samplingInterval || 1e3 / 99 // 99hz in millis
179178

180-
this.heapSamplingInterval = coalesce(options.heapSamplingInterval,
181-
Number(DD_PROFILING_HEAP_SAMPLING_INTERVAL))
179+
this.heapSamplingInterval = options.heapSamplingInterval ??
180+
(Number(DD_PROFILING_HEAP_SAMPLING_INTERVAL) || 512 * 1024)
182181
const uploadCompression0 = options.uploadCompression ?? DD_PROFILING_DEBUG_UPLOAD_COMPRESSION ?? 'on'
183182
let [uploadCompression, level0] = uploadCompression0.split('-')
184183
if (!['on', 'off', 'gzip', 'zstd'].includes(uploadCompression)) {
@@ -222,8 +221,7 @@ class Config {
222221

223222
const hasExecArg = (arg) => process.execArgv.includes(arg) || String(NODE_OPTIONS).includes(arg)
224223

225-
this.asyncContextFrameEnabled = isTrue(options.useAsyncContextFrame ??
226-
DD_PROFILING_ASYNC_CONTEXT_FRAME_ENABLED ?? false)
224+
this.asyncContextFrameEnabled = isTrue(options.useAsyncContextFrame ?? DD_PROFILING_ASYNC_CONTEXT_FRAME_ENABLED)
227225
if (this.asyncContextFrameEnabled) {
228226
if (satisfies(process.versions.node, '>=24.0.0')) {
229227
if (hasExecArg('--no-async-context-frame')) {

packages/dd-trace/src/profiling/profilers/events.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,9 @@ function labelFromStrStr (stringTable, keyStr, valStr) {
4141
return labelFromStr(stringTable, stringTable.dedup(keyStr), valStr)
4242
}
4343

44-
function getSamplingIntervalMillis (options) {
45-
return (options.samplingInterval || 1e3 / 99) // 99Hz
46-
}
47-
4844
function getMaxSamples (options) {
49-
const cpuSamplingInterval = getSamplingIntervalMillis(options)
50-
const flushInterval = options.flushInterval || 65 * 1e3 // 60 seconds
51-
const maxCpuSamples = flushInterval / cpuSamplingInterval
45+
const flushInterval = options.flushInterval || 65 * 1e3 // 65 seconds
46+
const maxCpuSamples = flushInterval / options.samplingInterval
5247

5348
// The lesser of max parallelism and libuv thread pool size, plus one so we can detect
5449
// oversubscription on libuv thread pool, plus another one for GC.
@@ -399,7 +394,7 @@ class EventsProfiler {
399394

400395
const eventHandler = event => this.#eventSerializer.addEvent(event)
401396
const eventFilter = options.timelineSamplingEnabled
402-
? createPoissonProcessSamplingFilter(getSamplingIntervalMillis(options))
397+
? createPoissonProcessSamplingFilter(options.samplingInterval)
403398
: () => true
404399
const filteringEventHandler = event => {
405400
if (eventFilter(event)) {

packages/dd-trace/src/profiling/profilers/space.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class NativeSpaceProfiler {
1313
_started = false
1414

1515
constructor (options = {}) {
16+
// TODO: Remove default value. It is only used in testing.
1617
this._samplingInterval = options.heapSamplingInterval || 512 * 1024
1718
this._stackDepth = options.stackDepth || 64
1819
this._oomMonitoring = options.oomMonitoring || {}

packages/dd-trace/src/profiling/profilers/wall.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ class NativeWallProfiler {
137137
this.#endpointCollectionEnabled = !!options.endpointCollectionEnabled
138138
this.#flushIntervalMillis = options.flushInterval || 60 * 1e3 // 60 seconds
139139
this.#logger = options.logger
140-
this.#samplingIntervalMicros = (options.samplingInterval || 1e3 / 99) * 1000 // 99hz
140+
// TODO: Remove default value. It is only used in testing.
141+
this.#samplingIntervalMicros = (options.samplingInterval || 1e3 / 99) * 1000
141142
this.#telemetryHeartbeatIntervalMillis = options.heartbeatInterval || 60 * 1e3 // 60 seconds
142143
this.#timelineEnabled = !!options.timelineEnabled
143144
this.#v8ProfilerBugWorkaroundEnabled = !!options.v8ProfilerBugWorkaroundEnabled

packages/dd-trace/test/config.spec.js

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require('./setup/core')
1313

1414
const { GRPC_CLIENT_ERROR_STATUSES, GRPC_SERVER_ERROR_STATUSES } = require('../src/constants')
1515
const { getEnvironmentVariable, getEnvironmentVariables } = require('../src/config-helper')
16+
const { assertObjectContains } = require('../../../integration-tests/helpers')
1617

1718
describe('Config', () => {
1819
let Config
@@ -2595,11 +2596,39 @@ describe('Config', () => {
25952596
it('overriding max depth', () => {
25962597
process.env.DD_TRACE_CLOUD_REQUEST_PAYLOAD_TAGGING = 'all'
25972598
process.env.DD_TRACE_CLOUD_RESPONSE_PAYLOAD_TAGGING = 'all'
2598-
process.env.DD_TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH = 7
2599-
const taggingConfig = new Config().cloudPayloadTagging
2600-
expect(taggingConfig).to.have.property('requestsEnabled', true)
2601-
expect(taggingConfig).to.have.property('responsesEnabled', true)
2602-
expect(taggingConfig).to.have.property('maxDepth', 7)
2599+
process.env.DD_TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH = '7'
2600+
2601+
let { cloudPayloadTagging } = new Config()
2602+
assertObjectContains(cloudPayloadTagging, {
2603+
maxDepth: 7,
2604+
requestsEnabled: true,
2605+
responsesEnabled: true
2606+
})
2607+
2608+
delete process.env.DD_TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH
2609+
2610+
;({ cloudPayloadTagging } = new Config({ cloudPayloadTagging: { maxDepth: 7 } }))
2611+
assertObjectContains(cloudPayloadTagging, {
2612+
maxDepth: 7,
2613+
requestsEnabled: true,
2614+
responsesEnabled: true
2615+
})
2616+
})
2617+
2618+
it('use default max depth if max depth is not a number', () => {
2619+
process.env.DD_TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH = 'abc'
2620+
2621+
let { cloudPayloadTagging } = new Config()
2622+
assertObjectContains(cloudPayloadTagging, {
2623+
maxDepth: 10,
2624+
})
2625+
2626+
delete process.env.DD_TRACE_CLOUD_PAYLOAD_TAGGING_MAX_DEPTH
2627+
2628+
;({ cloudPayloadTagging } = new Config({ cloudPayloadTagging: { maxDepth: NaN } }))
2629+
assertObjectContains(cloudPayloadTagging, {
2630+
maxDepth: 10,
2631+
})
26032632
})
26042633
})
26052634

0 commit comments

Comments
 (0)