Skip to content

Commit

Permalink
Merge pull request #286 from aneeshkp/fix-log-severity
Browse files Browse the repository at this point in the history
OCPBUGS-31422: PTP container logs lack severity information
  • Loading branch information
openshift-merge-bot[bot] committed Mar 26, 2024
2 parents b1c50d3 + a1db2c5 commit 00bc142
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
31 changes: 24 additions & 7 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ const (
PTP_HA_IDENTIFIER = "haProfiles"
HAInDomainIndicator = "as domain source clock"
HAOutOfDomainIndicator = "as out-of-domain source"
MessageTagSuffixSeperator = ":"
)

var (
haInDomainRegEx = regexp.MustCompile("selecting ([\\w\\-]+) as domain source clock")
haOutDomainRegEx = regexp.MustCompile("selecting ([\\w\\-]+) as out-of-domain source clock")
haInDomainRegEx = regexp.MustCompile("selecting ([\\w\\-]+) as domain source clock")
haOutDomainRegEx = regexp.MustCompile("selecting ([\\w\\-]+) as out-of-domain source clock")
MessagTagSuffixRegEx = regexp.MustCompile(`([a-zA-Z0-9]+\.[a-zA-Z0-9]+\.config):[a-zA-Z0-9]+(:[a-zA-Z0-9]+)?`)
)

// ProcessManager manages a set of ptpProcess
Expand Down Expand Up @@ -433,15 +435,15 @@ func (dn *Daemon) applyNodePtpProfile(runID int, nodeProfile *ptpv1.PtpProfile)
socketPath = fmt.Sprintf("/var/run/ptp4l.%d.socket", runID)
configFile = fmt.Sprintf("ptp4l.%d.config", runID)
configPath = fmt.Sprintf("/var/run/%s", configFile)
messageTag = fmt.Sprintf("[ptp4l.%d.config]", runID)
messageTag = fmt.Sprintf("[ptp4l.%d.config:{level}]", runID)
case phc2sysProcessName:
configInput = nodeProfile.Phc2sysConf
configOpts = nodeProfile.Phc2sysOpts
if !ptpHAEnabled {
socketPath = fmt.Sprintf("/var/run/ptp4l.%d.socket", runID)
messageTag = fmt.Sprintf("[ptp4l.%d.config]", runID)
messageTag = fmt.Sprintf("[ptp4l.%d.config:{level}]", runID)
} else { // when ptp ha enabled it has its own valid config
messageTag = fmt.Sprintf("[phc2sys.%d.config]", runID)
messageTag = fmt.Sprintf("[phc2sys.%d.config:{level}]", runID)
}
configFile = fmt.Sprintf("phc2sys.%d.config", runID)
configPath = fmt.Sprintf("/var/run/%s", configFile)
Expand All @@ -451,7 +453,7 @@ func (dn *Daemon) applyNodePtpProfile(runID int, nodeProfile *ptpv1.PtpProfile)
socketPath = fmt.Sprintf("/var/run/ptp4l.%d.socket", runID)
configFile = fmt.Sprintf("ts2phc.%d.config", runID)
configPath = fmt.Sprintf("/var/run/%s", configFile)
messageTag = fmt.Sprintf("[ts2phc.%d.config]", runID)
messageTag = fmt.Sprintf("[ts2phc.%d.config:{level}]", runID)
}

if configOpts == nil || *configOpts == "" {
Expand Down Expand Up @@ -682,6 +684,9 @@ func addScheduling(nodeProfile *ptpv1.PtpProfile, cmdLine string) string {

func processStatus(c *net.Conn, processName, messageTag string, status int64) {
cfgName := strings.Replace(strings.Replace(messageTag, "]", "", 1), "[", "", 1)
if cfgName != "" {
cfgName = strings.Split(cfgName, MessageTagSuffixSeperator)[0]
}
// ptp4l[5196819.100]: [ptp4l.0.config] PTP_PROCESS_STOPPED:0/1
deadProcessMsg := fmt.Sprintf("%s[%d]:[%s] PTP_PROCESS_STATUS:%d\n", processName, time.Now().Unix(), cfgName, status)
UpdateProcessStatusMetrics(processName, cfgName, status)
Expand Down Expand Up @@ -823,7 +828,7 @@ func (p *ptpProcess) cmdRun(stdoutToSocket bool) {
} else if p.name == phc2sysProcessName && len(p.haProfile) > 0 {
p.announceHAFailOver(&c, output) // do not use go routine since order of execution is important here
}
_, err2 := c.Write([]byte(out))
_, err2 := c.Write([]byte(removeMessageSuffix(out)))
if err2 != nil {
glog.Errorf("Write %s error %s:", out, err2)
goto connect
Expand Down Expand Up @@ -1096,3 +1101,15 @@ func failOverIndicator(output string, count int) (int64, int64) {
}
return 0, 0
}

func removeMessageSuffix(input string) (output string) {
// container log output "ptp4l[2464681.628]: [phc2sys.1.config:7] master offset -4 s2 freq -26835 path delay 525"
// make sure non-supported version can handle suffix tags
// clear {} from unparsed template
//"ptp4l[2464681.628]: [phc2sys.1.config:{level}] master offset -4 s2 freq -26835 path delay 525"
replacer := strings.NewReplacer("{", "", "}", "")
output = replacer.Replace(input)
// Replace matching parts in the input string
output = MessagTagSuffixRegEx.ReplaceAllString(output, "$1")
return output
}
4 changes: 4 additions & 0 deletions pkg/daemon/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ func updatePTPMetrics(from, process, iface string, ptpOffset, maxPtpOffset, freq
// extractMetrics ...
func extractMetrics(messageTag string, processName string, ifaces []config.Iface, output string) (configName, source string, offset float64, state string, iface string) {
configName = strings.Replace(strings.Replace(messageTag, "]", "", 1), "[", "", 1)
if configName != "" {
configName = strings.Split(configName, MessageTagSuffixSeperator)[0] // remove any suffix added to the configName
}
output = removeMessageSuffix(output)
if strings.Contains(output, " max ") {
ifaceName, ptpOffset, maxPtpOffset, frequencyAdjustment, delay := extractSummaryMetrics(configName, processName, output)
if ifaceName != "" {
Expand Down

0 comments on commit 00bc142

Please sign in to comment.