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

[v1.13] Author Backport of 28382 (Metrics associated with a deleted node should not be reported) #28932

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions pkg/metrics/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ type CounterVec interface {
}

type GaugeVec interface {
deletableVec

WithLabelValues(lvls ...string) prometheus.Gauge
prometheus.Collector
}

type deletableVec interface {
Delete(ll prometheus.Labels) bool
DeleteLabelValues(lvs ...string) bool
DeletePartialMatch(labels prometheus.Labels) int
Reset()
}

var (
NoOpMetric prometheus.Metric = &metric{}
NoOpCollector prometheus.Collector = &collector{}
Expand Down Expand Up @@ -130,6 +139,16 @@ type gaugeVec struct {
prometheus.Collector
}

func (*gaugeVec) Delete(ll prometheus.Labels) bool {
return false
}
func (*gaugeVec) DeleteLabelValues(lvs ...string) bool {
return false
}
func (*gaugeVec) DeletePartialMatch(labels prometheus.Labels) int {
return 0
}
func (*gaugeVec) Reset() {}
func (gv *gaugeVec) WithLabelValues(lvls ...string) prometheus.Gauge {
return NoOpGauge
}
23 changes: 23 additions & 0 deletions pkg/node/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ func (m *Manager) NodeDeleted(n nodeTypes.Node) {
}

m.metricNumNodes.Dec()
processNodeDeletion(n.Cluster, n.Name)

entry.mutex.Lock()
delete(m.nodes, nodeIdentity)
Expand All @@ -673,6 +674,28 @@ func (m *Manager) NodeDeleted(n nodeTypes.Node) {
entry.mutex.Unlock()
}

func processNodeDeletion(clusterName, nodeName string) {
// Removes all connectivity status associated with the deleted node.
_ = metrics.NodeConnectivityStatus.DeletePartialMatch(prometheus.Labels{
metrics.LabelSourceCluster: clusterName,
metrics.LabelSourceNodeName: nodeName,
})
_ = metrics.NodeConnectivityStatus.DeletePartialMatch(prometheus.Labels{
metrics.LabelTargetCluster: clusterName,
metrics.LabelTargetNodeName: nodeName,
})

// Removes all connectivity latency associated with the deleted node.
_ = metrics.NodeConnectivityLatency.DeletePartialMatch(prometheus.Labels{
metrics.LabelSourceCluster: clusterName,
metrics.LabelSourceNodeName: nodeName,
})
_ = metrics.NodeConnectivityLatency.DeletePartialMatch(prometheus.Labels{
metrics.LabelTargetCluster: clusterName,
metrics.LabelTargetNodeName: nodeName,
})
}

// GetNodeIdentities returns a list of all node identities store in node
// manager.
func (m *Manager) GetNodeIdentities() []nodeTypes.Identity {
Expand Down