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

policyfiltermetrics: Refactor and rename metrics #2784

Merged
merged 2 commits into from
Aug 13, 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
3 changes: 2 additions & 1 deletion contrib/upgrade-notes/latest.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ tetragon:

#### Metrics

* TBD
* `tetragon_policyfilter_metrics_total` metric is renamed to `tetragon_policyfilter_operations_total`, and its `op`
label is renamed to `operation`.
6 changes: 3 additions & 3 deletions docs/content/en/docs/reference/metrics.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ require (
github.com/vishvananda/netlink v1.2.1-beta.2.0.20240524165444-4d4ba1473f21
go.uber.org/atomic v1.11.0
go.uber.org/multierr v1.11.0
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb
golang.org/x/sync v0.8.0
golang.org/x/sys v0.22.0
golang.org/x/time v0.6.0
Expand Down Expand Up @@ -177,7 +178,6 @@ require (
go.uber.org/dig v1.17.1 // indirect
go.uber.org/zap v1.26.0 // indirect
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
Expand Down
41 changes: 22 additions & 19 deletions pkg/metrics/policyfiltermetrics/policyfiltermetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package policyfiltermetrics

import (
"golang.org/x/exp/maps"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a note (that we will forget) maps.Values will be moved into the standard library for 1.23.


"github.com/cilium/tetragon/pkg/metrics"
"github.com/cilium/tetragon/pkg/metrics/consts"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -64,15 +66,29 @@ func (s OperationErr) String() string {
}

var (
PolicyFilterOpMetrics = prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: consts.MetricsNamespace,
Name: "policyfilter_metrics_total",
Help: "Policy filter metrics. For internal use only.",
ConstLabels: nil,
}, []string{"subsys", "op", "error"})
subsysLabel = metrics.ConstrainedLabel{
Name: "subsys",
Values: maps.Values(subsysLabelValues),
}

operationLabel = metrics.ConstrainedLabel{
Name: "operation",
Values: maps.Values(operationLabelValues),
}

errorLabel = metrics.ConstrainedLabel{
Name: "error",
Values: maps.Values(operationErrLabels),
}
)

var (
PolicyFilterOpMetrics = metrics.MustNewCounter(metrics.NewOpts(
consts.MetricsNamespace, "", "policyfilter_operations_total",
"Number of policy filter operations.",
nil, []metrics.ConstrainedLabel{subsysLabel, operationLabel, errorLabel}, nil,
), nil)

PolicyFilterHookContainerNameMissingMetrics = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: consts.MetricsNamespace,
Name: "policyfilter_hook_container_name_missing_total",
Expand All @@ -85,19 +101,6 @@ func RegisterMetrics(group metrics.Group) {
group.MustRegister(PolicyFilterOpMetrics, PolicyFilterHookContainerNameMissingMetrics)
}

func InitMetrics() {
// Initialize metrics with labels
for _, subsys := range subsysLabelValues {
for _, op := range operationLabelValues {
for _, err := range operationErrLabels {
PolicyFilterOpMetrics.WithLabelValues(
subsys, op, err,
).Add(0)
}
}
}
}

func OpInc(subsys Subsys, op Operation, err string) {
PolicyFilterOpMetrics.WithLabelValues(subsys.String(), op.String(), err).Inc()
}
Expand Down
1 change: 0 additions & 1 deletion pkg/metricsconfig/healthmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func registerHealthMetrics(group metrics.Group) {
group.ExtendInit(opcodemetrics.InitMetrics)
// policy filter metrics
policyfiltermetrics.RegisterMetrics(group)
group.ExtendInit(policyfiltermetrics.InitMetrics)
// process metrics
process.RegisterMetrics(group)
// ringbuf metrics
Expand Down
Loading