Skip to content

Commit

Permalink
Merge pull request #369 from aneeshkp/add-holdover-event
Browse files Browse the repository at this point in the history
OCPBUGS-44208: Fix Holdover Event Triggering for T-GM and Minimize Redundant Clock Class Events:
  • Loading branch information
openshift-merge-bot[bot] authored Nov 7, 2024
2 parents 8c4d35f + 48c32f6 commit bacea3b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
17 changes: 14 additions & 3 deletions plugins/ptp_operator/metrics/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ func (p *PTPEventManager) GenPTPEvent(ptpProfileName string, oStats *stats.Stats
oStats.SetLastOffset(ptpOffset)
}
case ptp.HOLDOVER:
//FOR OC/BC do nothing, the timeout will switch holdover to FREE-RUN OR LOCKED if it is not within the holdover timeout
// FOR T-GM its handled differently
// previous state was HOLDOVER, now it is in LOCKED state, cancel any HOLDOVER
if isOffsetInRange(ptpOffset, threshold.MaxOffsetThreshold, threshold.MinOffsetThreshold) {
log.Infof("interface %s is in LOCKED state, cancel any holdover states", eventResourceName)
Expand All @@ -403,7 +405,8 @@ func (p *PTPEventManager) GenPTPEvent(ptpProfileName string, oStats *stats.Stats
oStats.SetLastSyncState(clockState)
oStats.SetLastOffset(ptpOffset)
oStats.AddValue(ptpOffset) // update off set when its in locked state and hold over only/ update off set when its in locked state and hold over only
} // else continue to stay in HOLDOVER
} // else continue to stay in HOLDOVER UNTIL its really LOCKED state

default: // not yet used states
clockState = ptp.FREERUN
if isOffsetInRange(ptpOffset, threshold.MaxOffsetThreshold, threshold.MinOffsetThreshold) {
Expand All @@ -418,11 +421,19 @@ func (p *PTPEventManager) GenPTPEvent(ptpProfileName string, oStats *stats.Stats
oStats.SetLastOffset(ptpOffset)
}
case ptp.HOLDOVER:
return // do nothing for holdover
if lastClockState != ptp.HOLDOVER { //send event only once
log.Infof(" publishing event for (profile %s) %s with last state %s and current clock state %s and offset %d )",
ptpProfileName, eventResourceName, oStats.LastSyncState(), clockState, ptpOffset)
p.PublishEvent(clockState, ptpOffset, eventResourceName, eventType)
}
oStats.SetLastSyncState(clockState)
oStats.SetLastOffset(ptpOffset)
oStats.AddValue(ptpOffset)
return
case ptp.FREERUN:
if lastClockState != ptp.HOLDOVER {
if lastClockState != ptp.FREERUN { // don't send event if last event was freerun
log.Infof(" publishing event for (profile %s) %s with last state %s and current clock state %s and offset %d for ( Max/Min Threshold %d/%d )",
log.Infof("publishing event for (profile %s) %s with last state %s and current clock state %s and offset %d for ( Max/Min Threshold %d/%d )",
ptpProfileName, eventResourceName, oStats.LastSyncState(), clockState, ptpOffset, threshold.MaxOffsetThreshold, threshold.MinOffsetThreshold)
p.PublishEvent(clockState, ptpOffset, eventResourceName, eventType)
}
Expand Down
29 changes: 28 additions & 1 deletion plugins/ptp_operator/metrics/manager_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build unittests
// +build unittests

package metrics_test

import (
Expand Down Expand Up @@ -65,7 +68,7 @@ func TestPTPEventManager_GenPTPEvent(t *testing.T) {
eventResourceName: "resource3",
ptpOffset: 500,
lastClockState: ptp.HOLDOVER,
clockState: ptp.FREERUN,
clockState: ptp.FREERUN, // stays in HOLDOVER until times out
eventType: ptp.PtpStateChange,
mock: true,
wantLastSyncState: ptp.HOLDOVER,
Expand All @@ -82,6 +85,30 @@ func TestPTPEventManager_GenPTPEvent(t *testing.T) {
mock: true,
wantLastSyncState: ptp.LOCKED,
},
{
name: "holdover to locked state",
ptpProfileName: "T-GM",
oStats: stats.NewStats("T-GM"),
eventResourceName: "resource3",
ptpOffset: 50,
lastClockState: ptp.LOCKED,
clockState: ptp.HOLDOVER,
eventType: ptp.PtpStateChange,
mock: true,
wantLastSyncState: ptp.HOLDOVER,
},
{
name: "holdover to locked state",
ptpProfileName: "T-GM",
oStats: stats.NewStats("T-GM"),
eventResourceName: "resource3",
ptpOffset: 50,
lastClockState: ptp.HOLDOVER,
clockState: ptp.HOLDOVER,
eventType: ptp.PtpStateChange,
mock: true,
wantLastSyncState: ptp.HOLDOVER,
},
}

for _, tt := range tests {
Expand Down
8 changes: 5 additions & 3 deletions plugins/ptp_operator/metrics/ptp4lParse.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ func (p *PTPEventManager) ParsePTP4l(processName, configName, profileName, outpu
alias, _ = ptp4lCfg.GetUnknownAlias()
}
masterResource := fmt.Sprintf("%s/%s", alias, MasterClockType)
ptpStats[master].SetClockClass(int64(clockClass))

ClockClassMetrics.With(prometheus.Labels{
"process": processName, "node": ptpNodeName}).Set(clockClass)

p.PublishClockClassEvent(clockClass, masterResource, ptp.PtpClockClassChange)
if ptpStats[master].ClockClass() != int64(clockClass) {
ptpStats[master].SetClockClass(int64(clockClass))
p.PublishClockClassEvent(clockClass, masterResource, ptp.PtpClockClassChange)
}
}
} else if strings.Contains(output, " port ") {
portID, role, syncState := extractPTP4lEventState(output)
Expand Down

0 comments on commit bacea3b

Please sign in to comment.