Skip to content

Commit

Permalink
tetragon: Add size histograms for data events
Browse files Browse the repository at this point in the history
Adding good/bad histograms to keep track of data events sizes.

It's enabled with new --enable-data-events-size-metric option.

Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri committed Jul 16, 2023
1 parent bcf1d8f commit e9cd5dc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/tetragon/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const (
keyEnablePidSetFilter = "enable-pid-set-filter"

keyEnableMsgHandlingLatency = "enable-msg-handling-latency"

keyEnableDataEventsSizeMetric = "enable-data-events-size-metric"
)

func readAndSetFlags() {
Expand Down Expand Up @@ -134,6 +136,7 @@ func readAndSetFlags() {
option.Config.EnablePolicyFilter = viper.GetBool(keyEnablePolicyFilter)
option.Config.EnablePolicyFilterDebug = viper.GetBool(keyEnablePolicyFilterDebug)
option.Config.EnableMsgHandlingLatency = viper.GetBool(keyEnableMsgHandlingLatency)
option.Config.EnableDataEventsSizeMetric = viper.GetBool(keyEnableDataEventsSizeMetric)

option.Config.EnablePidSetFilter = viper.GetBool(keyEnablePidSetFilter)

Expand Down
2 changes: 2 additions & 0 deletions cmd/tetragon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,8 @@ func execute() error {

flags.Bool(keyEnableMsgHandlingLatency, false, "Enable metrics for message handling latency")

flags.Bool(keyEnableDataEventsSizeMetric, false, "Enable metrics for data events size")

viper.BindPFlags(flags)
return rootCmd.Execute()
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/observer/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ func DataGet(desc dataapi.DataEventDesc) ([]byte, error) {
// make sure we did not loose anything on the way through ring buffer
if len(data) != int(desc.Size-desc.Leftover) {
DataEventMetricInc(DataEventBad)
DataEventMetricSizeBad(desc.Size)
return nil, fmt.Errorf("failed to get correct data for id: %v", desc.Id)
}

DataEventMetricSizeOk(desc.Size)

dataMap.Remove(desc.Id)
logger.GetLogger().WithFields(nil).Tracef("Data message used id %v, data len %v", desc.Id, len(data))
DataEventMetricInc(DataEventMatched)
Expand Down
23 changes: 23 additions & 0 deletions pkg/observer/data_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package observer

import (
"github.com/cilium/tetragon/pkg/metrics/consts"
"github.com/cilium/tetragon/pkg/option"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
Expand All @@ -14,6 +15,14 @@ var (
Help: "Data event statistics. For internal use only.",
ConstLabels: nil,
}, []string{"event"})

DataEventSizeHist = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: consts.MetricsNamespace,
Name: "data_event_stats_size",
Help: "The size of received data events.",
Buckets: prometheus.LinearBuckets(1000, 2000, 20),
ConstLabels: nil,
}, []string{"op"})
)

type DataEventType int
Expand All @@ -40,3 +49,17 @@ var DataEventTypeStrings = map[DataEventType]string{
func DataEventMetricInc(event DataEventType) {
DataEventStats.WithLabelValues(DataEventTypeStrings[event]).Inc()
}

func addSize(op string, size uint32) {
if option.Config.EnableDataEventsSizeMetric {
DataEventSizeHist.WithLabelValues(op).Observe(float64(size))
}
}

func DataEventMetricSizeOk(size uint32) {
addSize("ok", size)
}

func DataEventMetricSizeBad(size uint32) {
addSize("bad", size)
}
2 changes: 2 additions & 0 deletions pkg/option/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ type config struct {
EnablePidSetFilter bool

EnableMsgHandlingLatency bool

EnableDataEventsSizeMetric bool
}

var (
Expand Down

0 comments on commit e9cd5dc

Please sign in to comment.