Skip to content

Commit

Permalink
Merge pull request #246 from aneeshkp/delete-metrics-for-process
Browse files Browse the repository at this point in the history
[release-4.12] OCPBUGS-12361: PTP metrics - Unexpected metrics for old phc2sys appears in metrics after modify ptpconfigs
  • Loading branch information
openshift-merge-robot authored Apr 27, 2023
2 parents 414390a + 38cfd26 commit ce7a22d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
11 changes: 10 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,16 @@ func ProcessOutChannel(wg *sync.WaitGroup, scConfig *common.SCConfiguration) {
localmetrics.UpdateStatusAckCount(d.Address, localmetrics.FAILED)
}
} else if d.Type == channel.SUBSCRIBER {
log.Infof("subscriber processed for %s", d.Address)
if d.Status == channel.SUCCESS {
log.Infof("subscriber processed for %s", d.Address)
} else if d.Status == channel.DELETE {
scConfig.EventInCh <- &channel.DataChan{
ClientID: d.ClientID,
Data: d.Data,
Status: channel.DELETE,
Type: channel.SUBSCRIBER,
}
}
}
case <-scConfig.CloseCh:
return
Expand Down
5 changes: 5 additions & 0 deletions plugins/ptp_operator/metrics/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,8 @@ func (p *PTPEventManager) GenPTPEvent(ptpProfileName string, oStats *stats.Stats
oStats.SetLastOffset(ptpOffset)
}
}

// NodeName ...
func (p *PTPEventManager) NodeName() string {
return p.nodeName
}
29 changes: 27 additions & 2 deletions plugins/ptp_operator/metrics/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,11 @@ func UpdateInterfaceRoleMetrics(process, ptpInterface string, role types.PtpPort

// DeleteInterfaceRoleMetrics ... delete interface role metrics
func DeleteInterfaceRoleMetrics(process, ptpInterface string) {
InterfaceRole.Delete(prometheus.Labels{
"process": process, "node": ptpNodeName, "iface": ptpInterface})
if process != "" {
InterfaceRole.Delete(prometheus.Labels{"process": process, "iface": ptpInterface, "node": ptpNodeName})
} else {
InterfaceRole.Delete(prometheus.Labels{"iface": ptpInterface, "node": ptpNodeName})
}
}

// UpdateProcessStatusMetrics -- update process status metrics
Expand All @@ -207,3 +210,25 @@ func UpdateProcessStatusMetrics(process, cfgName string, status int64) {
"process": process, "node": ptpNodeName, "config": cfgName}).Inc()
}
}

// DeleteProcessStatusMetricsForConfig ...
func DeleteProcessStatusMetricsForConfig(node string, cfgName string, process ...string) {
labels := prometheus.Labels{}
if node != "" {
labels["node"] = node
}
if cfgName != "" {
labels["config"] = cfgName
}
if len(process) == 0 {
ProcessStatus.Delete(labels)
ProcessReStartCount.Delete(labels)
}
for _, p := range process {
if p != "" {
labels["process"] = p
ProcessStatus.Delete(labels)
ProcessReStartCount.Delete(labels)
}
}
}
16 changes: 16 additions & 0 deletions plugins/ptp_operator/ptp_operator_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ func Start(wg *sync.WaitGroup, configuration *common.SCConfiguration, fn func(e
for _, pConfig := range eventManager.Ptp4lConfigInterfaces {
ptpMetrics.DeleteThresholdMetrics(pConfig.Profile)
}
// delete all metrics related to process
ptpMetrics.DeleteProcessStatusMetricsForConfig(nodeName, "", "")
} else {
// updates
eventManager.PtpConfigMapUpdates.UpdatePTPProcessOptions()
Expand Down Expand Up @@ -306,6 +308,18 @@ func processPtp4lConfigFileUpdates() {
}
// add to eventManager
eventManager.AddPTPConfig(ptpConfigFileName, ptp4lConfig)
// clean up process metrics
for cName, opts := range eventManager.PtpConfigMapUpdates.PtpProcessOpts {
var process []string
if !opts.Ptp4lEnabled() {
process = append(process, ptp4lProcessName)
}
if !opts.Phc2SysEnabled() {
process = append(process, phc2sysProcessName)
}
ptpMetrics.DeleteProcessStatusMetricsForConfig(eventManager.NodeName(), cName,
process...)
}
case true: // ptp4l.X.conf is deleted
// delete metrics, ptp4l config is removed
ptpConfigFileName := ptpTypes.ConfigName(*ptpConfigEvent.Name)
Expand Down Expand Up @@ -336,6 +350,8 @@ func processPtp4lConfigFileUpdates() {
}
eventManager.DeleteStatsConfig(ptpConfigFileName)
eventManager.DeletePTPConfig(ptpConfigFileName)
// clean up process metrics
ptpMetrics.DeleteProcessStatusMetricsForConfig(eventManager.NodeName(), string(ptpConfigFileName), ptp4lProcessName, phc2sysProcessName)
}
case <-config.CloseCh:
fileWatcher.Close()
Expand Down

0 comments on commit ce7a22d

Please sign in to comment.