Skip to content

Commit

Permalink
Handle T-GM event when ts2phc process is dead (#332)
Browse files Browse the repository at this point in the history
Signed-off-by: Aneesh Puttur <[email protected]>
Co-authored-by: Aneesh Puttur <[email protected]>
  • Loading branch information
openshift-cherrypick-robot and aneeshkp authored Aug 16, 2024
1 parent f00e57e commit 42dfcf5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
24 changes: 15 additions & 9 deletions plugins/ptp_operator/metrics/logparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,31 +99,37 @@ func extractRegularMetrics(processName, output string) (interfaceName string, pt
// phc2sys[4268818.286]: [ptp4l.0.config] CLOCK_REALTIME phc offset -62 s0 freq -78368 delay 1100
// phc2sys[4268818.287]: [ptp4l.0.config] ens5f1 phc offset -92 s0 freq -890 delay 2464 ( this is down)
// phc2sys[4268818.287]: [ptp4l.0.config] ens5f0 phc offset -47 s2 freq -2047 delay 2438
// ts2phc[82674.465]: [ts2phc.0.cfg] nmea delay: 88403525 ns
// ts2phc[82674.465]: [ts2phc.0.cfg] ens2f1 extts index 0 at 1673031129.000000000 corr 0 src 1673031129.911642976 diff 0
// ts2phc[82674.465]: [ts2phc.0.cfg] ens2f1 master offset 0 s2 freq -0
// ts2phc[82674.465]: [ts2phc.0.config] nmea delay: 88403525 ns
// ts2phc[82674.465]: [ts2phc.0.config] ens2f1 extts index 0 at 1673031129.000000000 corr 0 src 1673031129.911642976 diff 0
// ts2phc[82674.465]: [ts2phc.0.config] ens2f1 master offset 0 s2 freq -0
// ts2phc[521734.693]: [ts2phc.0.config:6] /dev/ptp6 offset 0 s2 freq -0

// 0 1 2 3 4 5 6 7 8 9 10 11
// 1 2 3 4 5 6 7 8 9
// ptp4l 5196819.100 ptp4l.0.config master offset -2162130 s2 freq +22451884 path delay 374976
//
// ts2phc 522946.693 ts2phc.0.config ens7f0 offset 0 s2 freq -0
index := FindInLogForCfgFileIndex(output)
if index == -1 {
log.Errorf("config name is not found in log output %s", output)
return
}

output = strings.Replace(output, "path", "", 1)
replacer := strings.NewReplacer("[", " ", "]", " ", ":", " ", "phc", "", "sys", "")
// ts2phc 522946.693 ts2phc.0.config ens7f0 offset 0 s2 freq -0
// careful ts2phc --> here phc will be replaced so use empty string around the text
replacer := strings.NewReplacer("[", " ", "]", " ", ":", " ", " phc ", " ", " sys ", " ")
output = replacer.Replace(output)

output = output[index:]
fields := strings.Fields(output)

// 0 1 2 3 4 5 6 7 8
// ptp4l.0.config master offset -2162130 s2 freq +22451884 delay 374976
// ts2phc.0.cfg ens2f1 master offset 0 s2 freq -0
// (ts2phc.0.cfg master offset 0 s2 freq -0)
// 0 1 2 3 4 5 6 7 8
// 0 1 2 3 4 5 6 7 8
// ptp4l.0.config master offset -2162130 s2 freq +22451884 delay 374976
// ts2phc.0.config ens2f1 master offset 0 s2 freq -0
// 0 1 2 3 4 5 6
// ts2phc.0.config ens7f0 offset 0 s2 freq -0
// 0 1 2 3 4 5 6 7
// ptp4l.0.config CLOCK_REALTIME offset -62 s0 freq -78368 delay 1100
if len(fields) < 7 {
return
Expand Down
41 changes: 33 additions & 8 deletions plugins/ptp_operator/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ func (p *PTPEventManager) ExtractMetrics(msg string) {
alias := getAlias(interfaceName)
// no event for nmeas status , change in GM will manage ptp events and sync states
UpdateNmeaStatusMetrics(processName, alias, status)
} else if strings.Contains(output, "process_status") &&
processName == ts2phcProcessName {
// do nothing processDown identifier will update metrics and stats
// but prevent further from reading offsets
return
} else if strings.Contains(output, " offset ") { // DPLL has Offset too
// ptp4l[5196819.100]: [ptp4l.0.config] master offset -2162130 s2 freq +22451884 path delay 374976
// phc2sys[4268818.286]: [ptp4l.0.config] CLOCK_REALTIME phc offset -62 s0 freq -78368 delay 1100
Expand Down Expand Up @@ -316,15 +321,35 @@ func (p *PTPEventManager) ExtractMetrics(msg string) {

func (p *PTPEventManager) processDownEvent(profileName, processName string, ptpStats stats.PTPStats) {
// if the process is responsible to set master offset
if masterOffsetSource == processName {
if ptpStats[master].Alias() != "" {
masterResource := fmt.Sprintf("%s/%s", ptpStats[master].Alias(), MasterClockType)
p.GenPTPEvent(profileName, ptpStats[master], masterResource, FreeRunOffsetValue, ptp.FREERUN, ptp.PtpStateChange)
if processName == ts2phcProcessName {
// update metrics for all interface defined by ts2phc
// set ts2phc stats to FREERUN
// this should generate PTP stat as free run by event manager
for iface := range ptpStats {
if iface != ClockRealTime && iface != master {
ptpStats[iface].SetLastOffset(FreeRunOffsetValue)
ptpStats[iface].SetLastSyncState(ptp.FREERUN)
alias := ptpStats[iface].Alias()
if alias == "" {
alias = getAlias(string(iface))
}
// update all ts2phc reported metrics as FREERUN
UpdateSyncStateMetrics(processName, alias, ptpStats[iface].LastSyncState())
UpdatePTPMetrics(master, processName, alias, FreeRunOffsetValue, float64(ptpStats[iface].MaxAbs()),
float64(ptpStats[iface].FrequencyAdjustment()), float64(ptpStats[iface].Delay()))
}
}
}
if s, ok := ptpStats[ClockRealTime]; ok {
if t, ok2 := p.PtpConfigMapUpdates.PtpProcessOpts[profileName]; ok2 && t.Phc2SysEnabled() {
p.GenPTPEvent(profileName, s, ClockRealTime, FreeRunOffsetValue, ptp.FREERUN, ptp.OsClockSyncStateChange)
} else { // other profiles
if masterOffsetSource == processName {
if ptpStats[master].Alias() != "" {
masterResource := fmt.Sprintf("%s/%s", ptpStats[master].Alias(), MasterClockType)
p.GenPTPEvent(profileName, ptpStats[master], masterResource, FreeRunOffsetValue, ptp.FREERUN, ptp.PtpStateChange)
}
}
if s, ok := ptpStats[ClockRealTime]; ok {
if t, ok2 := p.PtpConfigMapUpdates.PtpProcessOpts[profileName]; ok2 && t.Phc2SysEnabled() {
p.GenPTPEvent(profileName, s, ClockRealTime, FreeRunOffsetValue, ptp.FREERUN, ptp.OsClockSyncStateChange)
}
}
}
}
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 @@ -236,7 +236,7 @@ func (s *Stats) GetStateState(processName string, iface *string) (ptp.SyncState,
return d[0].State, nil
}
for _, state := range d {
if *state.IFace == *iface {
if iface != nil && *state.IFace == *iface {
return state.State, nil
}
}
Expand Down

0 comments on commit 42dfcf5

Please sign in to comment.