forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds metrics support. (envoyproxy#29)
Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>
- Loading branch information
Showing
10 changed files
with
130 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright The OWASP Coraza contributors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/tetratelabs/proxy-wasm-go-sdk/proxywasm" | ||
) | ||
|
||
type wafMetrics struct { | ||
counters map[string]proxywasm.MetricCounter | ||
} | ||
|
||
func NewWAFMetrics() *wafMetrics { | ||
return &wafMetrics{ | ||
counters: make(map[string]proxywasm.MetricCounter), | ||
} | ||
} | ||
|
||
func (m *wafMetrics) incrementCounter(fqn string) { | ||
// TODO(jcchavezs): figure out if we are OK with dynamic creation of metrics | ||
// or we generate the metrics on before hand. | ||
counter, ok := m.counters[fqn] | ||
if !ok { | ||
counter = proxywasm.DefineCounterMetric(fqn) | ||
m.counters[fqn] = counter | ||
} | ||
counter.Increment(1) | ||
} | ||
|
||
func (m *wafMetrics) CountTX() { | ||
// This metric is processed as: waf_filter_tx_total | ||
m.incrementCounter("waf_filter.tx.total") | ||
} | ||
|
||
func (m *wafMetrics) CountTXInterruption(phase string, ruleID int) { | ||
// This metric is processed as: waf_filter_tx_interruption{phase="http_request_body",rule_id="100"}. | ||
// The extraction rule is defined in envoy.yaml as a bootstrap configuration. | ||
// See https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/metrics/v3/stats.proto#config-metrics-v3-statsconfig. | ||
fqn := fmt.Sprintf("waf_filter.tx.interruptions_ruleid=%d_phase=%s", ruleID, phase) | ||
m.incrementCounter(fqn) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters