Skip to content

Commit

Permalink
Merge pull request #365 from aneeshkp/reduce-event-noise
Browse files Browse the repository at this point in the history
OCPBUGS-43643: PTP Events Generating Redundant Noise for Repeated FREERUN State Transitions
  • Loading branch information
openshift-merge-bot[bot] authored Oct 22, 2024
2 parents 8f61fa8 + 0eb7275 commit 6aefbbe
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
2 changes: 0 additions & 2 deletions plugins/ptp_operator/metrics/logparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,13 @@ func (p *PTPEventManager) ParseGMLogs(processName, configName, output string, fi
SyncState.With(map[string]string{"process": processName, "node": ptpNodeName, "iface": alias}).Set(GetSyncStateID(syncState))
// status metrics
ptpStats[masterType].SetPtpDependentEventState(clockState, ptpStats.HasMetrics(processName), ptpStats.HasMetricHelp(processName))
ptpStats[masterType].SetLastSyncState(clockState.State)
ptpStats[masterType].SetAlias(alias)

// If GM is locked/Freerun/Holdover then ptp state change event
masterResource := fmt.Sprintf("%s/%s", alias, MasterClockType)

// When GM is enabled there is only event happening at GM level for now
p.GenPTPEvent(processName, ptpStats[masterType], masterResource, 0, clockState.State, ptp.PtpStateChange)
ptpStats[masterType].SetLastSyncState(clockState.State)
UpdateSyncStateMetrics(processName, alias, ptpStats[masterType].LastSyncState())
}

Expand Down
24 changes: 14 additions & 10 deletions plugins/ptp_operator/metrics/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,10 +405,12 @@ func (p *PTPEventManager) GenPTPEvent(ptpProfileName string, oStats *stats.Stats
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
default: // not yet used states
log.Warnf("%s sync state %s, last ptp state is unknown: %s", eventResourceName, clockState, lastClockState)
if !isOffsetInRange(ptpOffset, threshold.MaxOffsetThreshold, threshold.MinOffsetThreshold) {
clockState = ptp.FREERUN
clockState = ptp.FREERUN
if isOffsetInRange(ptpOffset, threshold.MaxOffsetThreshold, threshold.MinOffsetThreshold) {
clockState = ptp.LOCKED
}
log.Warnf("%s sync state %s, last ptp state is unknown, setting to %s", eventResourceName, lastClockState, clockState)

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) // change to unknown
Expand All @@ -419,19 +421,21 @@ func (p *PTPEventManager) GenPTPEvent(ptpProfileName string, oStats *stats.Stats
return // do nothing for holdover
case ptp.FREERUN:
if lastClockState != ptp.HOLDOVER {
// within range
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) // change to locked
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 )",
ptpProfileName, eventResourceName, oStats.LastSyncState(), clockState, ptpOffset, threshold.MaxOffsetThreshold, threshold.MinOffsetThreshold)
p.PublishEvent(clockState, ptpOffset, eventResourceName, eventType)
}
oStats.SetLastSyncState(clockState)
oStats.SetLastOffset(ptpOffset)
oStats.AddValue(ptpOffset)
}
default:
log.Warnf("%s unknown current ptp state %s", eventResourceName, clockState)
if !isOffsetInRange(ptpOffset, threshold.MaxOffsetThreshold, threshold.MinOffsetThreshold) {
clockState = ptp.FREERUN
clockState = ptp.FREERUN
if isOffsetInRange(ptpOffset, threshold.MaxOffsetThreshold, threshold.MinOffsetThreshold) {
clockState = ptp.LOCKED
}
log.Warnf("%s unknown current ptp state, setting to %s", eventResourceName, clockState)
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, ptp.PtpStateChange) // change to unknown state
Expand Down
2 changes: 0 additions & 2 deletions plugins/ptp_operator/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ var testCases = []TestCase{
from: "master",
process: "dpll",
iface: "ens7fx",
lastSyncState: ptp.FREERUN,
expectedPtpOffset: SKIP,
expectedPtpMaxOffset: SKIP,
expectedPtpFrequencyAdjustment: SKIP,
Expand Down Expand Up @@ -333,7 +332,6 @@ var testCases = []TestCase{
from: "phc",
process: "phc2sys",
iface: metrics.ClockRealTime,
lastSyncState: ptp.FREERUN,
expectedPtpOffset: -62,
expectedPtpMaxOffset: SKIP,
expectedPtpFrequencyAdjustment: -78368,
Expand Down
2 changes: 1 addition & 1 deletion plugins/ptp_operator/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func (s *Stats) GetStateState(processName string, iface *string) (ptp.SyncState,
}
}
}
return ptp.FREERUN, fmt.Errorf("sync state not found %s", processName)
return "", fmt.Errorf("sync state not found %s", processName)
}

// GetDependsOnValueState ... get value offset and state
Expand Down
5 changes: 5 additions & 0 deletions plugins/ptp_operator/stats/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ func TestStats_SetPtpDependentEventState(t *testing.T) {
}, nil, nil)
assert.Equal(t, ptp.FREERUN, s.PtpDependentEventState().CurrentPTPStateEvent)
}

func TestNewStats_EmptyState(t *testing.T) {
s := stats.NewStats("testCfg")
assert.NotEqual(t, ptp.FREERUN, s.LastSyncState())
}

0 comments on commit 6aefbbe

Please sign in to comment.