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

Initialize metrics with labels #2162

Merged
merged 28 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
269a1cc
metrics: Add comments about metrics naming
lambdanis Feb 23, 2024
af88716
errormetrics: Define error types as integers not strings
lambdanis Feb 23, 2024
d2724f8
errormetrics: Use ops.OpCode type instead of basic ints
lambdanis Feb 24, 2024
187592b
api/ops: Define OpCodeStrings map with opcode string values
lambdanis Feb 26, 2024
fea557c
api/ops: Add missing OpCode values
lambdanis Feb 26, 2024
623c564
errormetrics, observer: Define error_type label values
lambdanis Feb 26, 2024
75ab0f9
errormetrics: Initialize metrics with labels
lambdanis Feb 23, 2024
e53dc6c
eventcachemetrics: Define entry_type label values
lambdanis Feb 23, 2024
93bcbfc
eventcachemetrics: Use tetragon.EventType as event_type label
lambdanis Feb 26, 2024
decdb63
eventcachemetrics: Add event_type label to errors metric
lambdanis Feb 26, 2024
fbacf4b
eventcachemetrics: Define error label values
lambdanis Feb 26, 2024
a7918f1
eventcachemetrics: Initialize metrics with labels
lambdanis Feb 23, 2024
2e6e219
reader/exec: Define FlagStrings map with flag string values
lambdanis Feb 26, 2024
546bf72
eventmetrics: Initialize metrics with labels
lambdanis Feb 28, 2024
6e55729
kprobemetrics: Define curr_type and prev_type labels values
lambdanis Feb 26, 2024
d90fc84
opcodemetrics: Use ops.OpCode type instead of basic ints
lambdanis Feb 26, 2024
efe5cd7
opcodemetrics: Initialize metrics with labels
lambdanis Feb 26, 2024
07580f3
policyfiltermetrics: Define subsys label values
lambdanis Feb 27, 2024
3f0f378
policyfiltermetrics: Define op label values
lambdanis Feb 27, 2024
4262ed8
policyfiltermetrics: Remove error label
lambdanis Feb 27, 2024
37739a5
policyfiltermetrics: Initialize metrics with labels
lambdanis Feb 27, 2024
d2f5d01
Remove pkg/metrics/processexecmetrics
lambdanis Feb 27, 2024
20cfea2
watchermetrics: Define watcher label values
lambdanis Feb 27, 2024
4f29532
watchermetrics: Initialize metrics with labels
lambdanis Feb 27, 2024
5cdc9b4
observer: Define op as integers not strings
lambdanis Feb 28, 2024
415e68e
observer: Initialize metrics with labels
lambdanis Feb 27, 2024
f5f9629
tracing: Initialize metrics with labels
lambdanis Feb 27, 2024
b24e3f1
api/ops: Make OpCode.String() more informative for unknown opcodes
lambdanis Feb 29, 2024
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ require (
github.com/mennanov/fieldmask-utils v1.1.0
github.com/opencontainers/runtime-spec v1.2.0
github.com/pelletier/go-toml v1.9.5
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.19.0
github.com/prometheus/client_model v0.6.0
github.com/sirupsen/logrus v1.9.3
Expand Down Expand Up @@ -149,6 +148,7 @@ require (
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/prometheus/common v0.48.0 // indirect
Expand Down
9 changes: 2 additions & 7 deletions pkg/metrics/policyfiltermetrics/policyfiltermetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
package policyfiltermetrics

import (
"fmt"
"strings"

"github.com/cilium/tetragon/pkg/metrics/consts"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -54,7 +50,7 @@ var (
Name: "policyfilter_metrics_total",
Help: "Policy filter metrics. For internal use only.",
ConstLabels: nil,
}, []string{"subsys", "op", "error_type"})
}, []string{"subsys", "op"})
)

func InitMetrics(registry *prometheus.Registry) {
Expand All @@ -66,9 +62,8 @@ func InitMetrics(registry *prometheus.Registry) {
// * Rename policyfilter_metrics_total to get rid of _metrics?
}

func OpInc(subsys Subsys, op Operation, err error) {
func OpInc(subsys Subsys, op Operation) {
PolicyFilterOpMetrics.WithLabelValues(
subsys.String(), op.String(),
strings.ReplaceAll(fmt.Sprintf("%T", errors.Cause(err)), "*", ""),
kkourt marked this conversation as resolved.
Show resolved Hide resolved
).Inc()
}
2 changes: 1 addition & 1 deletion pkg/policyfilter/rthooks/rthooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func createContainerHook(_ context.Context, arg *rthooks.CreateContainerArg) err
if err := pfState.AddPodContainer(policyfilter.PodID(podID), namespace, pod.Labels, containerID, cgid); err != nil {
log.WithError(err).Warn("failed to update policy filter, aborting hook.")
}
policyfiltermetrics.OpInc(policyfiltermetrics.RTHooksSubsys, policyfiltermetrics.AddContainerOperation, err)
policyfiltermetrics.OpInc(policyfiltermetrics.RTHooksSubsys, policyfiltermetrics.AddContainerOperation)

return nil
}
14 changes: 7 additions & 7 deletions pkg/policyfilter/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func (m *state) updatePodHandler(pod *v1.Pod) error {
"pod-id": podID,
"container-ids": containerIDs,
"namespace": namespace,
}).Warn("policyfilter, add pod-handler: AddPodContainer failed")
}).Warn("policyfilter: UpdatePod failed")
return err
}

Expand All @@ -299,17 +299,17 @@ func (m *state) getPodEventHandlers() cache.ResourceEventHandlerFuncs {
logger.GetLogger().Warn("policyfilter, add-pod handler: unexpected object type: %T", pod)
return
}
err := m.updatePodHandler(pod)
policyfiltermetrics.OpInc(policyfiltermetrics.PodHandlersSubsys, policyfiltermetrics.AddPodOperation, err)
m.updatePodHandler(pod)
policyfiltermetrics.OpInc(policyfiltermetrics.PodHandlersSubsys, policyfiltermetrics.AddPodOperation)
},
UpdateFunc: func(_, newObj interface{}) {
pod, ok := newObj.(*v1.Pod)
if !ok {
logger.GetLogger().Warn("policyfilter, update-pod: unexpected object type(s): new:%T", pod)
logger.GetLogger().Warn("policyfilter, update-pod handler: unexpected object type(s): new:%T", pod)
return
}
err := m.updatePodHandler(pod)
policyfiltermetrics.OpInc(policyfiltermetrics.PodHandlersSubsys, policyfiltermetrics.UpdatePodOperation, err)
m.updatePodHandler(pod)
policyfiltermetrics.OpInc(policyfiltermetrics.PodHandlersSubsys, policyfiltermetrics.UpdatePodOperation)
},
DeleteFunc: func(obj interface{}) {
// Remove all containers for this pod
Expand All @@ -332,7 +332,7 @@ func (m *state) getPodEventHandlers() cache.ResourceEventHandlerFuncs {
"namespace": namespace,
}).Warn("policyfilter, delete-pod handler: DelPod failed")
}
policyfiltermetrics.OpInc(policyfiltermetrics.PodHandlersSubsys, policyfiltermetrics.DeletePodOperation, err)
policyfiltermetrics.OpInc(policyfiltermetrics.PodHandlersSubsys, policyfiltermetrics.DeletePodOperation)
},
}
}
Expand Down