Skip to content

Commit 41059e9

Browse files
authored
fix: sync names for telemetry (#117)
- [x] Fix truncation names according to https://docs.google.com/document/d/1D4hkC0jwwUyeo0hEQgyKP54kM1LZU98GL8MaP60tQrA/edit?tab=t.0#heading=h.1d7dno3x9isj - [x] Fix rasp timeout that should not have a 's' ........ - [x] Add helper function to get a waf error code from go error Signed-off-by: Eliott Bouhana <[email protected]>
1 parent 18a51e3 commit 41059e9

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

encoder.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ const (
6060
func (reason TruncationReason) String() string {
6161
switch reason {
6262
case ObjectTooDeep:
63-
return "depth"
63+
return "container_depth"
6464
case ContainerTooLarge:
65-
return "container-size"
65+
return "container_size"
6666
case StringTooLong:
67-
return "string-size"
67+
return "string_length"
6868
default:
6969
return fmt.Sprintf("TruncationReason(%v)", int(reason))
7070
}

errors/waf.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ func (e RunError) Error() string {
5252
return description
5353
}
5454

55+
// ToWafErrorCode converts an error to a WAF error code, returns zero if the error is not a WAF run error.
56+
func ToWafErrorCode(in error) int {
57+
var runError RunError
58+
if !errors.As(in, &runError) {
59+
return 0
60+
}
61+
return int(runError)
62+
}
63+
5564
// PanicError is an error type wrapping a recovered panic value that happened
5665
// during a function call. Such error must be considered unrecoverable and be
5766
// used to try to gracefully abort. Keeping using this package after such an

metrics.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const (
5858
wafDecodeTag = "decode"
5959
wafTimeoutTag = "timeouts"
6060
wafTruncationTag = "truncations"
61+
raspTimeoutTag = "timeout"
6162
)
6263

6364
func dot(parts ...string) string {
@@ -77,7 +78,7 @@ func (stats Stats) Metrics() map[string]any {
7778
}
7879

7980
if stats.TimeoutRASPCount > 0 {
80-
tags[dot(string(RASPScope), wafTimeoutTag)] = stats.TimeoutRASPCount
81+
tags[dot(string(RASPScope), raspTimeoutTag)] = stats.TimeoutRASPCount
8182
}
8283

8384
for reason, list := range stats.Truncations {

0 commit comments

Comments
 (0)