Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve the name of the prometheus metrics #995

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"log"
"net/http"
"sort"
"strconv"
"strings"
"text/template"
"time"
Expand Down Expand Up @@ -156,7 +157,14 @@ func newFalcoPayload(payload io.Reader) (types.FalcoPayload, error) {

nullClient.CountMetric("falco.accepted", 1, []string{"priority:" + falcopayload.Priority.String()})
stats.Falco.Add(strings.ToLower(falcopayload.Priority.String()), 1)
promLabels := map[string]string{"rule": falcopayload.Rule, "priority": falcopayload.Priority.String(), "source": falcopayload.Source, "k8s_ns_name": kn, "k8s_pod_name": kp}
promLabels := map[string]string{
"rule": falcopayload.Rule,
"priority_raw": strings.ToLower(falcopayload.Priority.String()),
"priority": strconv.Itoa(int(falcopayload.Priority)),
"source": falcopayload.Source,
"k8s_ns_name": kn,
"k8s_pod_name": kp,
}
if falcopayload.Hostname != "" {
promLabels["hostname"] = falcopayload.Hostname
} else {
Expand Down
2 changes: 1 addition & 1 deletion outputs/awssecuritylake.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (c *Client) StartSecurityLakeWorker() {
continue
}

time.Sleep(time.Duration(c.Config.AWS.SecurityLake.Interval) * time.Minute)
time.Sleep(time.Duration(c.Config.AWS.SecurityLake.Interval) * time.Minute) //nolint:gosec // disable G115
}
}

Expand Down
2 changes: 1 addition & 1 deletion outputs/policyreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func newResult(falcopayload types.FalcoPayload) *wgpolicy.PolicyReportResult {
Rule: falcopayload.Rule,
Category: "SI - System and Information Integrity",
Source: policyReportSource,
Timestamp: metav1.Timestamp{Seconds: int64(falcopayload.Time.Second()), Nanos: int32(falcopayload.Time.Nanosecond())},
Timestamp: metav1.Timestamp{Seconds: int64(falcopayload.Time.Second()), Nanos: int32(falcopayload.Time.Nanosecond())}, //nolint:gosec // disable G115
Severity: mapSeverity(falcopayload),
Result: mapResult(falcopayload),
Description: falcopayload.Output,
Expand Down
2 changes: 1 addition & 1 deletion outputs/spyderbat.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func newSpyderbatPayload(falcopayload types.FalcoPayload) (spyderbatPayload, err
MonotonicTime: time.Now().Nanosecond(),
OrcTime: nowTime,
Time: eventTime,
PID: int32(pid),
PID: int32(pid), //nolint:gosec // disable G115
Level: level,
Message: message,
Arguments: arguments,
Expand Down
9 changes: 6 additions & 3 deletions stats_prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/falcosecurity/falcosidekick/types"
)

const metricPrefix string = "falcosecurity_falcosidekick_"

func getInitPromStats(config *types.Configuration) *types.PromStatistics {
promStats = &types.PromStatistics{
Falco: getFalcoNewCounterVec(config),
Expand All @@ -25,7 +27,7 @@ func getInitPromStats(config *types.Configuration) *types.PromStatistics {
func getInputNewCounterVec() *prometheus.CounterVec {
return promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "falcosidekick_inputs",
Name: metricPrefix + "inputs_total",
},
[]string{"source", "status"},
)
Expand All @@ -34,7 +36,7 @@ func getInputNewCounterVec() *prometheus.CounterVec {
func getOutputNewCounterVec() *prometheus.CounterVec {
return promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "falcosidekick_outputs",
Name: metricPrefix + "outputs_total",
},
[]string{"destination", "status"},
)
Expand All @@ -46,6 +48,7 @@ func getFalcoNewCounterVec(config *types.Configuration) *prometheus.CounterVec {
"hostname",
"rule",
"priority",
"priority_raw",
"source",
"k8s_ns_name",
"k8s_pod_name",
Expand All @@ -66,7 +69,7 @@ func getFalcoNewCounterVec(config *types.Configuration) *prometheus.CounterVec {
}
return promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "falco_events",
Name: metricPrefix + "falco_events_total",
},
labelnames,
)
Expand Down
4 changes: 2 additions & 2 deletions stats_prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ func TestFalcoNewCounterVec(t *testing.T) {
c.Customfields["should*fail"] = "bar"

cv := getFalcoNewCounterVec(c)
shouldbe := []string{"hostname", "rule", "priority", "source", "k8s_ns_name", "k8s_pod_name", "test"}
shouldbe := []string{"hostname", "rule", "priority", "priority_raw", "source", "k8s_ns_name", "k8s_pod_name", "test"}
mm, err := cv.GetMetricWithLabelValues(shouldbe...)
if err != nil {
t.Errorf("Error getting Metrics from promauto")
}
metricDescString := mm.Desc().String()
require.Equal(t, metricDescString, "Desc{fqName: \"falco_events\", help: \"\", constLabels: {}, variableLabels: {hostname,rule,priority,source,k8s_ns_name,k8s_pod_name,test}}")
require.Equal(t, metricDescString, "Desc{fqName: \"falcosecurity_falcosidekick_falco_events_total\", help: \"\", constLabels: {}, variableLabels: {hostname,rule,priority,priority_raw,source,k8s_ns_name,k8s_pod_name,test}}")
}