Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
watson committed Aug 28, 2024
1 parent fddb5f7 commit 61476fc
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
5 changes: 3 additions & 2 deletions packages/dd-trace/src/appsec/remote_config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ function enable (config, appsec) {
rc.updateCapabilities(RemoteConfigCapabilities.ASM_API_SECURITY_SAMPLE_RATE, true)
}

rc.on('ASM_FEATURES', (action, rcConfig) => {
rc.on('ASM_FEATURES', (action, rcConfig, id, ack) => {
ack()
if (!rcConfig) return

if (activation === Activation.ONECLICK) {
Expand Down Expand Up @@ -106,7 +107,7 @@ function disableWafUpdate () {
}
}

function noop () {}
function noop (a, b, c, ack) { ack() }

module.exports = {
enable,
Expand Down
13 changes: 8 additions & 5 deletions packages/dd-trace/src/appsec/remote_config/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,14 @@ class RemoteConfigManager extends EventEmitter {
if (item.apply_state === UNACKNOWLEDGED || action === 'unapply') {
try {
// TODO: do we want to pass old and new config ?
const hadListeners = this.emit(item.product, action, item.file, item.id)

if (hadListeners) {
item.apply_state = ACKNOWLEDGED
}
this.emit(item.product, action, item.file, item.id, (err) => {
if (err) {
item.apply_state = ERROR
item.apply_error = err.toString()
} else {
item.apply_state = ACKNOWLEDGED
}
})
} catch (err) {
item.apply_state = ERROR
item.apply_error = err.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ let sessionStarted = false
// sampling: { snapshotsPerSecond: 5000 },
// evaluateAt: 'EXIT' // only used for method probes
// }
rcPort.on('message', async ({ action, conf: probe }) => {
rcPort.on('message', async ({ action, conf: probe, ackId }) => {
try {
await processMsg(action, probe)
rcPort.postMessage({ ackId })
} catch (err) {
rcPort.postMessage({ ackId, error: err })
ackError(err, probe)
}
})
Expand Down
16 changes: 12 additions & 4 deletions packages/dd-trace/src/debugger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@ function start (config, rc) {

log.debug('Starting Dynamic Instrumentation client...')

rc.on('LIVE_DEBUGGING', (action, conf) => {
rcChannel.port2.postMessage({ action, conf })
})

const rcAckCallbacks = new Map()
const rcChannel = new MessageChannel()
configChannel = new MessageChannel()

rc.on('LIVE_DEBUGGING', (action, conf, id, ack) => {
const ackId = `${id}-${conf.version}`
rcAckCallbacks.set(ackId, ack)
rcChannel.port2.postMessage({ action, conf, ackId })
})

rcChannel.port2.on('message', ({ ackId, error }) => {
rcAckCallbacks.get(ackId)(error)
rcAckCallbacks.delete(ackId)
})

worker = new Worker(
join(__dirname, 'devtools_client', 'index.js'),
{
Expand Down
9 changes: 6 additions & 3 deletions packages/dd-trace/src/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class Tracer extends NoopProxy {
if (config.remoteConfig.enabled && !config.isCiVisibility) {
const rc = remoteConfig.enable(config, this._modules.appsec)

rc.on('APM_TRACING', (action, conf) => {
rc.on('APM_TRACING', (action, conf, id, ack) => {
ack()
if (action === 'unapply') {
config.configure({}, true)
} else {
Expand All @@ -93,7 +94,8 @@ class Tracer extends NoopProxy {
this._enableOrDisableTracing(config)
})

rc.on('AGENT_CONFIG', (action, conf) => {
rc.on('AGENT_CONFIG', (action, conf, id, ack) => {
ack()
if (!conf?.name?.startsWith('flare-log-level.')) return

if (action === 'unapply') {
Expand All @@ -104,7 +106,8 @@ class Tracer extends NoopProxy {
}
})

rc.on('AGENT_TASK', (action, conf) => {
rc.on('AGENT_TASK', (action, conf, id, ack) => {
ack()
if (action === 'unapply' || !conf) return
if (conf.task_type !== 'tracer_flare' || !conf.args) return

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const Capabilities = require('../../../src/appsec/remote_config/capabilities')
const { UNACKNOWLEDGED, ACKNOWLEDGED, ERROR } = require('../../../src/appsec/remote_config/apply_states')

const noop = () => {}
const noop = (a, b, c, ack) => { ack() }

describe('RemoteConfigManager', () => {
let uuid
Expand Down

0 comments on commit 61476fc

Please sign in to comment.