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

feat(conntrack-metrics): legacy control plane basic mode #1253

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 28 additions & 0 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,34 @@ func InitializeMetrics() {
utils.InterfaceName,
)

ConntrackPacketsForward = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.ConntrackPacketsForwardGaugeName,
ConntrackPacketForwardDescription,
utils.ConntrackGaugeLabels...,
)

ConntrackPacketsReply = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.ConntrackPacketsReplyGaugeName,
ConntrackPacketReplyDescription,
utils.ConntrackGaugeLabels...,
)

ConntrackBytesForward = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.ConntrackBytesForwardGaugeName,
ConntrackBytesForwardDescription,
utils.ConntrackGaugeLabels...,
)

ConntrackBytesReply = exporter.CreatePrometheusGaugeVecForMetric(
exporter.DefaultRegistry,
utils.ConntrackBytesReplyGaugeName,
ConntrackBytesReplyDescription,
utils.ConntrackGaugeLabels...,
)

isInitialized = true
metricsLogger.Info("Metrics initialized")
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/metrics/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ const (
// Control plane metrics
pluginManagerFailedToReconcileCounterDescription = "Number of times the plugin manager failed to reconcile the plugins"
lostEventsCounterDescription = "Number of events lost in control plane"

// Conntrack metrics
ConntrackPacketForwardDescription = "Number of forward packets"
ConntrackPacketReplyDescription = "Number of reply packets"
ConntrackBytesForwardDescription = "Number of forward bytes"
ConntrackBytesReplyDescription = "Number of reply bytes"
)

// Metric Counters
Expand Down Expand Up @@ -89,6 +95,12 @@ var (

InfinibandStatsGauge GaugeVec
InfinibandStatusParamsGauge GaugeVec

// Conntrack
ConntrackPacketsForward GaugeVec
ConntrackPacketsReply GaugeVec
ConntrackBytesForward GaugeVec
ConntrackBytesReply GaugeVec
)

func ToPrometheusType(metric interface{}) prometheus.Collector {
Expand Down
23 changes: 23 additions & 0 deletions pkg/plugin/packetparser/packetparser_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,19 @@ func (p *packetParser) processRecord(ctx context.Context, id int) {
p.enricher.Write(ev)
}

// Add conntrack metrics.
SRodi marked this conversation as resolved.
Show resolved Hide resolved
if p.cfg.EnableConntrackMetrics {
labels := []string{
protoToString(bpfEvent.Proto),
fl.GetTrafficDirection().String(),
}
// Basic metrics, node-level
metrics.ConntrackPacketsForward.WithLabelValues(labels...).Set(float64(bpfEvent.ConntrackMetadata.PacketsForwardCount))
metrics.ConntrackBytesForward.WithLabelValues(labels...).Set(float64(bpfEvent.ConntrackMetadata.BytesForwardCount))
metrics.ConntrackPacketsReply.WithLabelValues(labels...).Set(float64(bpfEvent.ConntrackMetadata.PacketsReplyCount))
metrics.ConntrackBytesReply.WithLabelValues(labels...).Set(float64(bpfEvent.ConntrackMetadata.BytesReplyCount))
}

// Write the event to the external channel.
if p.externalChannel != nil {
select {
Expand Down Expand Up @@ -704,3 +717,13 @@ func absPath() (string, error) {
dir := path.Dir(filename)
return dir, nil
}

func protoToString(bpfEventProto uint8) string {
var proto string
if bpfEventProto == 6 {
proto = "tcp"
} else if bpfEventProto == 17 {
proto = "udp"
}
return proto
}
3 changes: 3 additions & 0 deletions pkg/utils/attr_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ var (
// DNS labels.
DNSRequestLabels = []string{"query_type", "query"}
DNSResponseLabels = []string{"return_code", "query_type", "query", "response", "num_response"}

// Flow labels.
ConntrackGaugeLabels = []string{"protocol", "traffic_direction"}
)

func GetPluginEventAttributes(attrs []attribute.KeyValue, pluginName, eventName, timestamp string) []attribute.KeyValue {
Expand Down
6 changes: 6 additions & 0 deletions pkg/utils/metric_names.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ const (
// Common Gauges across os distributions
NodeConnectivityStatusName = "node_connectivity_status"
NodeConnectivityLatencySecondsName = "node_connectivity_latency_seconds"

// Conntrack
ConntrackPacketsForwardGaugeName = "conntrack_packets_forward"
ConntrackPacketsReplyGaugeName = "conntrack_packets_reply"
ConntrackBytesForwardGaugeName = "conntrack_bytes_forward"
ConntrackBytesReplyGaugeName = "conntrack_bytes_reply"
)

// IsAdvancedMetric is a helper function to determine if a name is an advanced metric
Expand Down
Loading