Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Julio Guerra <julio@datadog.com>
  • Loading branch information
Hellzy and Julio-Guerra committed Apr 7, 2022
1 parent f7ee85c commit 06f0d21
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/appsec/waf.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
eventRulesFailedTag = "_dd.appsec.event_rules.error_count"
wafDurationTag = "_dd.appsec.waf.duration"
wafDurationExtTag = "_dd.appsec.waf.duration_ext"
wafTimeoutTag = "_dd.appsec.waf.timeouts"
)

// Register the WAF event listener.
Expand Down Expand Up @@ -144,9 +145,10 @@ func newHTTPWAFEventListener(handle *waf.Handle, addresses []string, timeout tim
overallWAFRunDuration := time.Since(wafRunStartTime)

// Log WAF metrics.
op.AddTag("_dd.appsec.waf.timeouts", float64(wafCtx.TotalTimeouts()))
op.AddTag(wafTimeoutTag, float64(wafCtx.TotalTimeouts()))
// time.Duration.Microseconds() is only as of go1.13, so we do it manually here
addWAFDurationTags(&op.TagsHolder, float64(wafCtx.TotalRuntime()), float64(overallWAFRunDuration.Nanoseconds()))
// Log the following metrics once per instantiation of a WAF handle
once.Do(func() {
addRulesetInfoTags(&op.TagsHolder, handle.RulesetInfo())
op.AddTag(ext.ManualKeep, samplernames.AppSec)
Expand Down Expand Up @@ -230,8 +232,9 @@ func newGRPCWAFEventListener(handle *waf.Handle, _ []string, timeout time.Durati
mu.Unlock()
}))
op.On(grpcsec.OnHandlerOperationFinish(func(op *grpcsec.HandlerOperation, _ grpcsec.HandlerOperationRes) {
op.AddTag("_dd.appsec.waf.timeouts", float64(wafTimeouts))
op.AddTag(wafTimeoutTag, float64(wafTimeouts))
addWAFDurationTags(&op.TagsHolder, float64(wafRunDuration), float64(wafBindingsRunDuration))
// Log the following metrics once per instantiation of a WAF handle
metricsOnce.Do(func() {
addRulesetInfoTags(&op.TagsHolder, handle.RulesetInfo())
op.AddTag(ext.ManualKeep, samplernames.AppSec)
Expand Down

0 comments on commit 06f0d21

Please sign in to comment.