Skip to content

Commit e3b9e95

Browse files
uurienwconti27
authored andcommitted
Remove appsec distribution metrics (#5534)
1 parent dfe0a13 commit e3b9e95

File tree

5 files changed

+2
-159
lines changed

5 files changed

+2
-159
lines changed

packages/dd-trace/src/appsec/telemetry/rasp.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,6 @@ function trackRaspMetrics (store, metrics, raspRule) {
5555

5656
appsecMetrics.count('rasp.rule.eval', tags).inc(1)
5757

58-
if (metrics.duration) {
59-
appsecMetrics.distribution('rasp.rule.duration', tags).track(metrics.duration)
60-
61-
const raspDuration = telemetryMetrics.raspDuration
62-
appsecMetrics.distribution('rasp.duration', versionsTags).track(raspDuration)
63-
}
64-
65-
if (metrics.durationExt) {
66-
const raspDurationExt = telemetryMetrics.raspDurationExt
67-
appsecMetrics.distribution('rasp.duration_ext', versionsTags).track(raspDurationExt)
68-
}
69-
7058
if (metrics.errorCode) {
7159
const errorTags = { ...tags, waf_error: metrics.errorCode }
7260

packages/dd-trace/src/appsec/telemetry/waf.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,9 @@ function addWafRequestMetrics (store, { duration, durationExt, wafTimeout, error
3333
}
3434
}
3535

36-
function trackWafDurations ({ duration, durationExt }, versionsTags) {
37-
if (duration) {
38-
appsecMetrics.distribution('waf.duration', versionsTags).track(duration)
39-
}
40-
41-
if (durationExt) {
42-
appsecMetrics.distribution('waf.duration_ext', versionsTags).track(durationExt)
43-
}
44-
}
45-
4636
function trackWafMetrics (store, metrics) {
4737
const versionsTags = getVersionsTags(metrics.wafVersion, metrics.rulesVersion)
4838

49-
trackWafDurations(metrics, versionsTags)
50-
5139
const metricTags = getOrCreateMetricTags(store, versionsTags)
5240

5341
if (metrics.blockFailed) {
@@ -134,24 +122,6 @@ function incrementWafRequests (store) {
134122
function incrementTruncatedMetrics (metrics, truncationReason) {
135123
const truncationTags = { truncation_reason: truncationReason }
136124
appsecMetrics.count('waf.input_truncated', truncationTags).inc(1)
137-
138-
if (metrics?.maxTruncatedString) {
139-
appsecMetrics.distribution('waf.truncated_value_size', {
140-
truncation_reason: TRUNCATION_FLAGS.STRING
141-
}).track(metrics.maxTruncatedString)
142-
}
143-
144-
if (metrics?.maxTruncatedContainerSize) {
145-
appsecMetrics.distribution('waf.truncated_value_size', {
146-
truncation_reason: TRUNCATION_FLAGS.CONTAINER_SIZE
147-
}).track(metrics.maxTruncatedContainerSize)
148-
}
149-
150-
if (metrics?.maxTruncatedContainerDepth) {
151-
appsecMetrics.distribution('waf.truncated_value_size', {
152-
truncation_reason: TRUNCATION_FLAGS.CONTAINER_DEPTH
153-
}).track(metrics.maxTruncatedContainerDepth)
154-
}
155125
}
156126

157127
function getTruncationReason ({ maxTruncatedString, maxTruncatedContainerSize, maxTruncatedContainerDepth }) {

packages/dd-trace/test/appsec/telemetry/rasp.spec.js

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('Appsec Rasp Telemetry metrics', () => {
99
const wafVersion = '0.0.1'
1010
const rulesVersion = '0.0.2'
1111

12-
let count, inc, req, distribution, track
12+
let count, inc, req
1313

1414
beforeEach(() => {
1515
req = {}
@@ -19,13 +19,7 @@ describe('Appsec Rasp Telemetry metrics', () => {
1919
inc
2020
})
2121

22-
track = sinon.spy()
23-
distribution = sinon.stub(appsecNamespace, 'distribution').returns({
24-
track
25-
})
26-
2722
appsecNamespace.metrics.clear()
28-
appsecNamespace.distributions.clear()
2923
})
3024

3125
afterEach(sinon.restore)
@@ -84,62 +78,6 @@ describe('Appsec Rasp Telemetry metrics', () => {
8478
expect(inc).to.have.been.calledTwice
8579
})
8680

87-
it('should track rasp.duration and rasp.rule.duration metrics', () => {
88-
appsecTelemetry.updateRaspRequestsMetricTags({
89-
duration: 42,
90-
wafVersion: '1.0.0',
91-
rulesVersion: '2.0.0'
92-
}, req, { type: 'rule-type' })
93-
94-
expect(distribution).to.have.been.calledWith('rasp.rule.duration', {
95-
rule_type: 'rule-type',
96-
waf_version: '1.0.0',
97-
event_rules_version: '2.0.0'
98-
})
99-
expect(track.firstCall).to.have.been.calledWith(42)
100-
101-
expect(distribution).to.have.been.calledWith('rasp.duration', {
102-
waf_version: '1.0.0',
103-
event_rules_version: '2.0.0'
104-
})
105-
expect(track.secondCall).to.have.been.calledWith(42)
106-
107-
track.resetHistory()
108-
109-
appsecTelemetry.updateRaspRequestsMetricTags({
110-
duration: 35,
111-
wafVersion: '1.0.0',
112-
rulesVersion: '2.0.0'
113-
}, req, { type: 'rule-type' })
114-
115-
expect(distribution).to.have.been.calledWith('rasp.rule.duration', {
116-
rule_type: 'rule-type',
117-
waf_version: '1.0.0',
118-
event_rules_version: '2.0.0'
119-
})
120-
expect(track.firstCall).to.have.been.calledWith(35)
121-
122-
expect(distribution).to.have.been.calledWith('rasp.duration', {
123-
waf_version: '1.0.0',
124-
event_rules_version: '2.0.0'
125-
})
126-
expect(track.secondCall).to.have.been.calledWith(77)
127-
})
128-
129-
it('should track rasp.duration_ext', () => {
130-
appsecTelemetry.updateRaspRequestsMetricTags({
131-
durationExt: 42,
132-
wafVersion: '1.0.0',
133-
rulesVersion: '2.0.0'
134-
}, req, { type: 'rule-type' })
135-
136-
expect(distribution).to.have.been.calledWith('rasp.duration_ext', {
137-
waf_version: '1.0.0',
138-
event_rules_version: '2.0.0'
139-
})
140-
expect(track).to.have.been.calledWith(42)
141-
})
142-
14381
it('should track rasp.error', () => {
14482
appsecTelemetry.updateRaspRequestsMetricTags({
14583
errorCode: -127,

packages/dd-trace/test/appsec/telemetry/waf.spec.js

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -147,25 +147,6 @@ describe('Appsec Waf Telemetry metrics', () => {
147147
})
148148
})
149149

150-
it('should call trackWafDurations', () => {
151-
appsecTelemetry.updateWafRequestsMetricTags({
152-
duration: 42,
153-
durationExt: 52,
154-
...metrics
155-
}, req)
156-
157-
expect(distribution).to.have.been.calledTwice
158-
159-
const tag = {
160-
waf_version: wafVersion,
161-
event_rules_version: rulesVersion
162-
}
163-
expect(distribution.firstCall.args).to.be.deep.eq(['waf.duration', tag])
164-
expect(distribution.secondCall.args).to.be.deep.eq(['waf.duration_ext', tag])
165-
166-
expect(track).to.have.been.calledTwice
167-
})
168-
169150
it('should sum waf.duration metrics', () => {
170151
appsecTelemetry.updateWafRequestsMetricTags({
171152
duration: 42,
@@ -365,9 +346,6 @@ describe('Appsec Waf Telemetry metrics', () => {
365346

366347
expect(count).to.have.been.calledWith('waf.input_truncated', { truncation_reason: 1 })
367348
expect(inc).to.have.been.calledWith(1)
368-
369-
expect(distribution).to.have.been.calledWith('waf.truncated_value_size', { truncation_reason: 1 })
370-
expect(track).to.have.been.calledWith(5000)
371349
})
372350

373351
it('should report truncated container size metrics', () => {
@@ -376,9 +354,6 @@ describe('Appsec Waf Telemetry metrics', () => {
376354

377355
expect(count).to.have.been.calledWith('waf.input_truncated', { truncation_reason: 2 })
378356
expect(inc).to.have.been.calledWith(1)
379-
380-
expect(distribution).to.have.been.calledWith('waf.truncated_value_size', { truncation_reason: 2 })
381-
expect(track).to.have.been.calledWith(300)
382357
})
383358

384359
it('should report truncated container depth metrics', () => {
@@ -387,9 +362,6 @@ describe('Appsec Waf Telemetry metrics', () => {
387362

388363
expect(count).to.have.been.calledWith('waf.input_truncated', { truncation_reason: 4 })
389364
expect(inc).to.have.been.calledWith(1)
390-
391-
expect(distribution).to.have.been.calledWith('waf.truncated_value_size', { truncation_reason: 4 })
392-
expect(track).to.have.been.calledWith(20)
393365
})
394366

395367
it('should combine truncation reasons when multiple truncations occur', () => {
@@ -401,9 +373,6 @@ describe('Appsec Waf Telemetry metrics', () => {
401373
expect(result).to.have.property('input_truncated', true)
402374

403375
expect(count).to.have.been.calledWith('waf.input_truncated', { truncation_reason: 7 })
404-
expect(distribution).to.have.been.calledWith('waf.truncated_value_size', { truncation_reason: 1 })
405-
expect(distribution).to.have.been.calledWith('waf.truncated_value_size', { truncation_reason: 2 })
406-
expect(distribution).to.have.been.calledWith('waf.truncated_value_size', { truncation_reason: 4 })
407376
})
408377

409378
it('should not report truncation metrics when no truncation occurs', () => {

packages/dd-trace/test/appsec/waf-metrics.integration.spec.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ describe('WAF Metrics', () => {
174174

175175
it('should report truncation metrics', async () => {
176176
let appsecTelemetryMetricsReceived = false
177-
let appsecTelemetryDistributionsReceived = false
178177

179178
const complexPayload = createComplexPayload()
180179
await axios.post('/', { complexPayload })
@@ -204,29 +203,8 @@ describe('WAF Metrics', () => {
204203
}
205204
}, 30_000, 'generate-metrics', 2)
206205

207-
const checkTelemetryDistributions = agent.assertTelemetryReceived(({ payload }) => {
208-
const namespace = payload.payload.namespace
209-
210-
if (namespace === 'appsec') {
211-
appsecTelemetryDistributionsReceived = true
212-
const series = payload.payload.series
213-
const wafDuration = series.find(s => s.metric === 'waf.duration')
214-
const wafDurationExt = series.find(s => s.metric === 'waf.duration_ext')
215-
const wafTuncated = series.filter(s => s.metric === 'waf.truncated_value_size')
216-
217-
assert.exists(wafDuration, 'waf duration serie should exist')
218-
assert.exists(wafDurationExt, 'waf duration ext serie should exist')
219-
220-
assert.equal(wafTuncated.length, 3)
221-
assert.include(wafTuncated[0].tags, 'truncation_reason:1')
222-
assert.include(wafTuncated[1].tags, 'truncation_reason:2')
223-
assert.include(wafTuncated[2].tags, 'truncation_reason:4')
224-
}
225-
}, 30_000, 'distributions', 1)
226-
227-
return Promise.all([checkMessages, checkTelemetryMetrics, checkTelemetryDistributions]).then(() => {
206+
return Promise.all([checkMessages, checkTelemetryMetrics]).then(() => {
228207
assert.equal(appsecTelemetryMetricsReceived, true)
229-
assert.equal(appsecTelemetryDistributionsReceived, true)
230208

231209
return true
232210
})

0 commit comments

Comments
 (0)