From ae9ddfad0ecca7fc2bb1d7b8667a4336c0d89c92 Mon Sep 17 00:00:00 2001 From: Quan Tian Date: Mon, 21 Aug 2023 20:39:39 +0800 Subject: [PATCH] Always initialize ovs_meter_packet_dropped_count metrics Otherwise the metric is not showing up if OVS Meter is not supported on the system, causing e2e test failure. Signed-off-by: Quan Tian --- pkg/agent/metrics/prometheus.go | 9 +++++++-- pkg/agent/openflow/client.go | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/agent/metrics/prometheus.go b/pkg/agent/metrics/prometheus.go index b061a31075d..6402fa8d335 100644 --- a/pkg/agent/metrics/prometheus.go +++ b/pkg/agent/metrics/prometheus.go @@ -23,6 +23,9 @@ import ( const ( metricNamespaceAntrea = "antrea" metricSubsystemAgent = "agent" + + LabelPacketInMeterNetworkPolicy = "PacketInMeterNetworkPolicy" + LabelPacketInMeterTraceflow = "PacketInMeterTraceflow" ) var ( @@ -232,12 +235,14 @@ func InitializeOVSMetrics() { } // Initialize OpenFlow operations metrics with label add, modify and delete // since those metrics won't come out until observation. - opsArray := [3]string{"add", "modify", "delete"} - for _, ops := range opsArray { + for _, ops := range []string{"add", "modify", "delete"} { OVSFlowOpsCount.WithLabelValues(ops) OVSFlowOpsErrorCount.WithLabelValues(ops) OVSFlowOpsLatency.WithLabelValues(ops) } + for _, label := range []string{LabelPacketInMeterNetworkPolicy, LabelPacketInMeterTraceflow} { + OVSMeterPacketDroppedCount.WithLabelValues(label) + } } func InitializeConnectionMetrics() { diff --git a/pkg/agent/openflow/client.go b/pkg/agent/openflow/client.go index c341ecdeebd..d3590aeebe0 100644 --- a/pkg/agent/openflow/client.go +++ b/pkg/agent/openflow/client.go @@ -1558,9 +1558,9 @@ func (c *client) getMeterStats() { handleMeterStatsReply := func(meterID int, packetCount int64) { switch meterID { case PacketInMeterIDNP: - metrics.OVSMeterPacketDroppedCount.WithLabelValues("PacketInMeterNetworkPolicy").Set(float64(packetCount)) + metrics.OVSMeterPacketDroppedCount.WithLabelValues(metrics.LabelPacketInMeterNetworkPolicy).Set(float64(packetCount)) case PacketInMeterIDTF: - metrics.OVSMeterPacketDroppedCount.WithLabelValues("PacketInMeterTraceflow").Set(float64(packetCount)) + metrics.OVSMeterPacketDroppedCount.WithLabelValues(metrics.LabelPacketInMeterTraceflow).Set(float64(packetCount)) default: klog.V(4).InfoS("Received unexpected meterID", "meterID", meterID) }