Skip to content

Commit 5cc9c97

Browse files
Read alias from ptp4l config instead of socket
1 parent 9930cda commit 5cc9c97

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

plugins/ptp_operator/metrics/metrics.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ var (
1919
// NodeName from the env
2020
ptpNodeName = ""
2121
masterOffsetSource = ""
22-
23-
aliasRegex = regexp.MustCompile(`ALIAS:\s*(?P<interface>[\w|-|_]+)\s+->\s(?P<alias>[\w|-|_]+)`)
2422
)
2523

2624
const (
@@ -92,12 +90,6 @@ func (p *PTPEventManager) ExtractMetrics(msg string) {
9290
log.Errorf("failed to extract %s", msg)
9391
}
9492
}()
95-
96-
if match := aliasRegex.FindStringSubmatch(msg); len(match) >= 3 {
97-
utils.Aliases.SetAlias(match[1], match[2])
98-
return
99-
}
100-
10193
replacer := strings.NewReplacer("[", " ", "]", " ", ":", " ")
10294
output := replacer.Replace(msg)
10395
fields := strings.Fields(output)

plugins/ptp_operator/metrics/registry.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"sync"
66

77
"github.com/redhat-cne/cloud-event-proxy/plugins/ptp_operator/stats"
8+
"github.com/redhat-cne/cloud-event-proxy/plugins/ptp_operator/utils"
89

910
log "github.com/sirupsen/logrus"
1011

@@ -85,7 +86,7 @@ var (
8586
Subsystem: ptpSubsystem,
8687
Name: "interface_role",
8788
Help: "0 = PASSIVE, 1 = SLAVE, 2 = MASTER, 3 = FAULTY, 4 = UNKNOWN, 5 = LISTENING",
88-
}, []string{"process", "node", "iface"})
89+
}, []string{"process", "node", "iface", "alias"})
8990

9091
// ClockClassMetrics metrics to show current clock class for the node
9192
ClockClassMetrics = prometheus.NewGaugeVec(
@@ -249,7 +250,7 @@ func UpdatePTPHaMetrics(profile string, status int64) {
249250
// UpdateInterfaceRoleMetrics ... update interface role metrics
250251
func UpdateInterfaceRoleMetrics(process, ptpInterface string, role types.PtpPortRole) {
251252
InterfaceRole.With(prometheus.Labels{
252-
"process": process, "node": ptpNodeName, "iface": ptpInterface}).Set(float64(role))
253+
"process": process, "node": ptpNodeName, "iface": ptpInterface, "alias": utils.GetAlias(ptpInterface)}).Set(float64(role))
253254
}
254255

255256
// DeleteInterfaceRoleMetrics ... delete interface role metrics

plugins/ptp_operator/ptp4lconf/ptp4lConfig.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var (
3434
ptpSyncE4lConfigFileRegEx = regexp.MustCompile(`synce4l.[0-9]*.config`)
3535
sectionHead = regexp.MustCompile(`\[([^\[\]]*)\]`)
3636
profileRegEx = regexp.MustCompile(`profile: \s*([\w-_]+)`)
37+
aliasRegEx = regexp.MustCompile(`#\s*alias:\s*(.*)\s*`)
3738
fileNameRegEx = regexp.MustCompile("([^/]+$)")
3839
)
3940

@@ -101,7 +102,14 @@ func (p *PtpConfigUpdate) GetAllSections() map[string]map[string]string {
101102
line := strings.TrimSpace(scanner.Text())
102103

103104
// Skip empty lines and comments
104-
if line == "" || strings.HasPrefix(line, "#") {
105+
if line == "" || (strings.HasPrefix(line, "#") && !aliasRegEx.MatchString(line)) {
106+
continue
107+
}
108+
109+
if match := aliasRegEx.FindStringSubmatch(line); len(match) >= 2 {
110+
if match[1] != "" {
111+
utils.Aliases.SetAlias(currentSection, match[1])
112+
}
105113
continue
106114
}
107115

0 commit comments

Comments
 (0)