Skip to content

Commit

Permalink
Merge pull request ovn-kubernetes#2538 from martinkennelly/egress_fir…
Browse files Browse the repository at this point in the history
…ewall_rules

Metric: Add egress firewall rules metric
  • Loading branch information
alexanderConstantinescu authored Oct 26, 2021
2 parents c255962 + e361173 commit 6b1f8e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions go-controller/pkg/metrics/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ var metricEgressIPCount = prometheus.NewGauge(prometheus.GaugeOpts{
Help: "The number of defined egress IP addresses",
})

var metricEgressFirewallRuleCount = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: MetricOvnNamespace,
Subsystem: MetricOvnkubeSubsystemMaster,
Name: "num_egress_firewall_rules",
Help: "The number of egress firewall rules defined"},
)

var registerMasterMetricsOnce sync.Once
var startE2ETimeStampUpdaterOnce sync.Once

Expand Down Expand Up @@ -238,6 +245,7 @@ func RegisterMasterMetrics(nbClient, sbClient goovn.Client) {
prometheus.MustRegister(metricV4AllocatedHostSubnetCount)
prometheus.MustRegister(metricV6AllocatedHostSubnetCount)
prometheus.MustRegister(metricEgressIPCount)
prometheus.MustRegister(metricEgressFirewallRuleCount)
registerWorkqueueMetrics(MetricOvnkubeNamespace, MetricOvnkubeSubsystemMaster)
})
}
Expand Down Expand Up @@ -314,3 +322,8 @@ func RecordSubnetCount(v4SubnetCount, v6SubnetCount float64) {
func RecordEgressIPCount(count float64) {
metricEgressIPCount.Set(count)
}

// UpdateEgressFirewallRuleCount records the number of Egress firewall rules.
func UpdateEgressFirewallRuleCount(count float64) {
metricEgressFirewallRuleCount.Add(count)
}
3 changes: 3 additions & 0 deletions go-controller/pkg/ovn/ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ func (oc *Controller) WatchEgressFirewall() *factory.Handler {
if err != nil {
klog.Error(err)
}
metrics.UpdateEgressFirewallRuleCount(float64(len(egressFirewall.Spec.Egress)))
},
UpdateFunc: func(old, newer interface{}) {
newEgressFirewall := newer.(*egressfirewall.EgressFirewall).DeepCopy()
Expand All @@ -777,6 +778,7 @@ func (oc *Controller) WatchEgressFirewall() *factory.Handler {
if err != nil {
klog.Error(err)
}
metrics.UpdateEgressFirewallRuleCount(float64(len(newEgressFirewall.Spec.Egress) - len(oldEgressFirewall.Spec.Egress)))
}
},
DeleteFunc: func(obj interface{}) {
Expand All @@ -791,6 +793,7 @@ func (oc *Controller) WatchEgressFirewall() *factory.Handler {
if err != nil {
klog.Errorf("Failed to commit db changes for egressFirewall in namespace %s stdout: %q, stderr: %q, err: %+v", egressFirewall.Namespace, stdout, stderr, err)
}
metrics.UpdateEgressFirewallRuleCount(float64(-len(egressFirewall.Spec.Egress)))
},
}, oc.syncEgressFirewall)
}
Expand Down

0 comments on commit 6b1f8e8

Please sign in to comment.