From 0eb7275b5fe04e67f8d34cc13d62f350996a6319 Mon Sep 17 00:00:00 2001 From: Aneesh Puttur Date: Mon, 21 Oct 2024 17:00:37 -0400 Subject: [PATCH] PTP Events Generating Redundant Noise for Repeated FREERUN State Transitions Signed-off-by: Aneesh Puttur --- plugins/ptp_operator/metrics/logparser.go | 2 -- plugins/ptp_operator/metrics/manager.go | 24 ++++++++++++-------- plugins/ptp_operator/metrics/metrics_test.go | 2 -- plugins/ptp_operator/stats/stats.go | 2 +- plugins/ptp_operator/stats/stats_test.go | 5 ++++ 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/plugins/ptp_operator/metrics/logparser.go b/plugins/ptp_operator/metrics/logparser.go index 669c08c8..0450cff8 100644 --- a/plugins/ptp_operator/metrics/logparser.go +++ b/plugins/ptp_operator/metrics/logparser.go @@ -377,7 +377,6 @@ 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 @@ -385,7 +384,6 @@ func (p *PTPEventManager) ParseGMLogs(processName, configName, output string, fi // 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()) } diff --git a/plugins/ptp_operator/metrics/manager.go b/plugins/ptp_operator/metrics/manager.go index 2074a6eb..43ec6aa2 100644 --- a/plugins/ptp_operator/metrics/manager.go +++ b/plugins/ptp_operator/metrics/manager.go @@ -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 @@ -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 diff --git a/plugins/ptp_operator/metrics/metrics_test.go b/plugins/ptp_operator/metrics/metrics_test.go index 481e9241..b321306e 100644 --- a/plugins/ptp_operator/metrics/metrics_test.go +++ b/plugins/ptp_operator/metrics/metrics_test.go @@ -196,7 +196,6 @@ var testCases = []TestCase{ from: "master", process: "dpll", iface: "ens7fx", - lastSyncState: ptp.FREERUN, expectedPtpOffset: SKIP, expectedPtpMaxOffset: SKIP, expectedPtpFrequencyAdjustment: SKIP, @@ -333,7 +332,6 @@ var testCases = []TestCase{ from: "phc", process: "phc2sys", iface: metrics.ClockRealTime, - lastSyncState: ptp.FREERUN, expectedPtpOffset: -62, expectedPtpMaxOffset: SKIP, expectedPtpFrequencyAdjustment: -78368, diff --git a/plugins/ptp_operator/stats/stats.go b/plugins/ptp_operator/stats/stats.go index 3d1e7588..70930fc2 100644 --- a/plugins/ptp_operator/stats/stats.go +++ b/plugins/ptp_operator/stats/stats.go @@ -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 diff --git a/plugins/ptp_operator/stats/stats_test.go b/plugins/ptp_operator/stats/stats_test.go index 793e2e90..a59c3c55 100644 --- a/plugins/ptp_operator/stats/stats_test.go +++ b/plugins/ptp_operator/stats/stats_test.go @@ -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()) +}