Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-4.12] OCPBUGS-7561: Fix SLAVE port going to master or listening state #200

Merged
merged 2 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ KUSTOMIZE=$(shell which kustomize)
endif

deps-update:
go get github.com/redhat-cne/sdk-go@$(branch) && \
go get github.com/redhat-cne/rest-api@$(branch) && \
go mod tidy && \
go mod vendor

Expand Down
3 changes: 3 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ func main() {
transportHost = strings.Replace(transportHost, "NODE_IP", nodeIP, 1)
log.Infof("transport host path is set to %s", transportHost)
}
nodeName := os.Getenv("NODE_NAME")
transportHost = common.SanitizeTransportHost(transportHost, nodeIP, nodeName)

parsedTransportHost := &common.TransportHost{URL: transportHost}

parsedTransportHost.ParseTransportHost()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/onsi/gomega v1.22.1
github.com/prometheus/client_golang v1.13.0
github.com/redhat-cne/rest-api v0.1.1-0.20230119134700-82a3aab383a7
github.com/redhat-cne/sdk-go v0.1.1-0.20230119124426-1ed827004687
github.com/redhat-cne/sdk-go v0.1.1-0.20230215223206-506ca9294ab3
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.1
golang.org/x/net v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0ua
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/redhat-cne/rest-api v0.1.1-0.20230119134700-82a3aab383a7 h1:6100R/UA9xDGIosY5yhgxDfYUNMWYHUXToEqF1PcSxY=
github.com/redhat-cne/rest-api v0.1.1-0.20230119134700-82a3aab383a7/go.mod h1:H0Vjdn9EB+d/0gFyHumJxCRWz4DMb6P9zzX/n230Ajg=
github.com/redhat-cne/sdk-go v0.1.1-0.20230119124426-1ed827004687 h1:XVm+cCf2C2n4VnlQd+oCKj88FcmLfq5m4Nco8cFY+J8=
github.com/redhat-cne/sdk-go v0.1.1-0.20230119124426-1ed827004687/go.mod h1:kKOXU8uyHbpwXCKrjzH4WVLq2/RZ5pchiI2LLvmFi5E=
github.com/redhat-cne/sdk-go v0.1.1-0.20230215223206-506ca9294ab3 h1:ZaLouUiiopXnjSVmHDNhVA5sJy6niaAmmQNGKT7SrA4=
github.com/redhat-cne/sdk-go v0.1.1-0.20230215223206-506ca9294ab3/go.mod h1:kKOXU8uyHbpwXCKrjzH4WVLq2/RZ5pchiI2LLvmFi5E=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down
20 changes: 20 additions & 0 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,26 @@ func (t *TransportHost) String() string {
return s.String()
}

// SanitizeTransportHost ... Replace string modifiers
func SanitizeTransportHost(transportHost, nodeIP, nodeName string) string {
if nodeIP != "" {
transportHost = strings.Replace(transportHost, "NODE_IP", nodeIP, 1)
log.Infof("transport host path is set to %s", transportHost)
} else if strings.Contains(transportHost, "NODE_NAME") { // allow overriding transport host
if nodeName != "" {
if strings.Contains(nodeName, ".") {
transportHost = strings.Replace(transportHost, "NODE_NAME", strings.Split(nodeName, ".")[0], 1)
} else {
transportHost = strings.Replace(transportHost, "NODE_NAME", nodeName, 1)
}
log.Infof("transport host path is set to %s", transportHost)
} else {
log.Info("NODE_NAME env is not set")
}
}
return transportHost
}

// ParseTransportHost ... prase the url to identify type
func (t *TransportHost) ParseTransportHost() {
var (
Expand Down
2 changes: 1 addition & 1 deletion plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ openshift_ptp_delay_ns{from="master",iface="ens2fx",node="NODE_NAME",process="pt
# HELP openshift_ptp_frequency_adjustment_ns
# TYPE openshift_ptp_frequency_adjustment_ns gauge
openshift_ptp_frequency_adjustment_ns{from="master",iface="ens2fx",node="NODE_NAME",process="ptp4l"} -15705
# HELP openshift_ptp_interface_role 0 = PASSIVE, 1 = SLAVE, 2 = MASTER, 3 = FAULTY, 4 = UNKNOWN
# HELP openshift_ptp_interface_role 0 = PASSIVE, 1 = SLAVE, 2 = MASTER, 3 = FAULTY, 4 = UNKNOWN, 5 = LISTENING
# TYPE openshift_ptp_interface_role gauge
openshift_ptp_interface_role{iface="ens2f0",node="NODE_NAME",process="ptp4l"} 1
# HELP openshift_ptp_max_offset_ns
Expand Down
17 changes: 14 additions & 3 deletions plugins/ptp_operator/metrics/logparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,27 @@ func extractPTP4lEventState(output string) (portID int, role types.PtpPortRole,
}

clockState = ptp.FREERUN
if strings.Contains(output, "UNCALIBRATED to SLAVE") {
if strings.Contains(output, "UNCALIBRATED to SLAVE") ||
strings.Contains(output, "LISTENING to SLAVE") {
role = types.SLAVE
} else if strings.Contains(output, "UNCALIBRATED to PASSIVE") || strings.Contains(output, "MASTER to PASSIVE") ||
strings.Contains(output, "SLAVE to PASSIVE") || strings.Contains(output, "LISTENING to PASSIVE") {
role = types.PASSIVE
} else if strings.Contains(output, "UNCALIBRATED to MASTER") || strings.Contains(output, "LISTENING to MASTER") {
} else if strings.Contains(output, "UNCALIBRATED to MASTER") ||
strings.Contains(output, "LISTENING to MASTER") {
role = types.MASTER
} else if strings.Contains(output, "FAULT_DETECTED") || strings.Contains(output, "SYNCHRONIZATION_FAULT") {
} else if strings.Contains(output, "FAULT_DETECTED") ||
strings.Contains(output, "SYNCHRONIZATION_FAULT") ||
strings.Contains(output, "SLAVE to UNCALIBRATED") {
role = types.FAULTY
clockState = ptp.HOLDOVER
} else if strings.Contains(output, "SLAVE to MASTER") ||
strings.Contains(output, "SLAVE to GRAND_MASTER") {
role = types.MASTER
clockState = ptp.HOLDOVER
} else if strings.Contains(output, "SLAVE to LISTENING") {
role = types.LISTENING
clockState = ptp.HOLDOVER
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/ptp_operator/metrics/ptp4lParse.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (p *PTPEventManager) ParsePTP4l(processName, configName, profileName, outpu
// make any slave interface master offset to FREERUN
if syncState != "" && syncState != ptpStats[master].LastSyncState() && syncState == ptp.HOLDOVER {
// Put master in HOLDOVER state
ptpStats[master].SetRole(role) // update slave port as faulty
ptpStats[master].SetRole(types.FAULTY) // update slave port as faulty
alias := ptpStats[master].Alias()
masterResource := fmt.Sprintf("%s/%s", alias, MasterClockType)
p.PublishEvent(syncState, ptpStats[master].LastOffset(), masterResource, ptp.PtpStateChange)
Expand Down
2 changes: 1 addition & 1 deletion plugins/ptp_operator/metrics/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var (
Namespace: ptpNamespace,
Subsystem: ptpSubsystem,
Name: "interface_role",
Help: "0 = PASSIVE, 1 = SLAVE, 2 = MASTER, 3 = FAULTY, 4 = UNKNOWN",
Help: "0 = PASSIVE, 1 = SLAVE, 2 = MASTER, 3 = FAULTY, 4 = UNKNOWN, 5 = LISTENING",
}, []string{"process", "node", "iface"})

// ClockClassMetrics metrics to show current clock class for the node
Expand Down
15 changes: 10 additions & 5 deletions plugins/ptp_operator/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ const (
FAULTY
// UNKNOWN role
UNKNOWN
// LISTENING ...
LISTENING = 5
)

// PtpRoleMappings ... set ptp role mapping
var PtpRoleMappings = map[string]PtpPortRole{
"PASSIVE": PASSIVE,
"SLAVE": SLAVE,
"MASTER": MASTER,
"FAULTY": FAULTY,
"UNKNOWN": UNKNOWN,
"PASSIVE": PASSIVE,
"SLAVE": SLAVE,
"MASTER": MASTER,
"FAULTY": FAULTY,
"UNKNOWN": UNKNOWN,
"LISTENING": LISTENING,
}

func (r PtpPortRole) String() string {
Expand All @@ -52,6 +55,8 @@ func (r PtpPortRole) String() string {
return "FAULTY"
case UNKNOWN:
return "UNKNOWN"
case LISTENING:
return "LISTENING"
default:
return fmt.Sprintf("%d", int(r))
}
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/redhat-cne/sdk-go/pkg/channel/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions vendor/github.com/redhat-cne/sdk-go/pkg/channel/pipeline.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/github.com/redhat-cne/sdk-go/pkg/channel/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 23 additions & 21 deletions vendor/github.com/redhat-cne/sdk-go/pkg/event/event.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/redhat-cne/sdk-go/pkg/event/event_ce.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.