Skip to content

Commit

Permalink
fix double / in ResourceAddress
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Ding <jackding@gmail.com>
  • Loading branch information
jzding committed Sep 12, 2024
1 parent 263db54 commit 05a45db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions plugins/ptp_operator/metrics/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metrics

import (
"fmt"
"path"
"strings"
"sync"

Expand Down Expand Up @@ -177,7 +178,7 @@ func (p *PTPEventManager) PublishClockClassEvent(clockClass float64, source stri
return
}
data := p.GetPTPEventsData(ptp.LOCKED, int64(clockClass), source, eventType)
resourceAddress := fmt.Sprintf(p.resourcePrefix, p.nodeName, string(p.publisherTypes[eventType].Resource))
resourceAddress := path.Join(p.resourcePrefix, p.nodeName, string(p.publisherTypes[eventType].Resource))
p.publish(*data, resourceAddress, eventType)
}

Expand All @@ -197,7 +198,7 @@ func (p *PTPEventManager) publishGNSSEvent(state int64, offset float64, syncStat
ValueType: ceevent.DECIMAL,
Value: state,
})
resourceAddress := fmt.Sprintf(p.resourcePrefix, p.nodeName, string(p.publisherTypes[eventType].Resource))
resourceAddress := path.Join(p.resourcePrefix, p.nodeName, string(p.publisherTypes[eventType].Resource))
p.publish(*data, resourceAddress, eventType)
}

Expand All @@ -217,15 +218,15 @@ func (p *PTPEventManager) publishSyncEEvent(syncState ptp.SyncState, source stri
Version: ceevent.APISchemaVersion,
Values: []ceevent.DataValue{},
}
resource := fmt.Sprintf(p.resourcePrefix, p.nodeName, fmt.Sprintf("/%s/%s", source, "Ql"))
resource := path.Join(p.resourcePrefix, p.nodeName, source, "Ql")
if syncState == "" { // clock quality event
data.Values = append(data.Values, ceevent.DataValue{
Resource: resource,
DataType: ceevent.METRIC,
ValueType: ceevent.DECIMAL,
Value: float64(ql),
})
resource = fmt.Sprintf(p.resourcePrefix, p.nodeName, fmt.Sprintf("/%s/%s", source, "extQl"))
resource = path.Join(p.resourcePrefix, p.nodeName, source, "extQl")
if !extendedTvlEnabled { // have the default value for clarity
data.Values = append(data.Values, ceevent.DataValue{
Resource: resource,
Expand All @@ -243,13 +244,13 @@ func (p *PTPEventManager) publishSyncEEvent(syncState ptp.SyncState, source stri
}
} else {
data.Values = append(data.Values, ceevent.DataValue{
Resource: fmt.Sprintf(p.resourcePrefix, p.nodeName, fmt.Sprintf("/%s", source)),
Resource: path.Join(p.resourcePrefix, p.nodeName, source),
DataType: ceevent.METRIC,
ValueType: ceevent.DECIMAL,
Value: syncState,
})
}
resourceAddress := fmt.Sprintf(p.resourcePrefix, p.nodeName, string(p.publisherTypes[eventType].Resource))
resourceAddress := path.Join(p.resourcePrefix, p.nodeName, string(p.publisherTypes[eventType].Resource))
p.publish(*data, resourceAddress, eventType)
}

Expand All @@ -260,7 +261,7 @@ func (p *PTPEventManager) GetPTPEventsData(state ptp.SyncState, ptpOffset int64,
return nil
}
// /cluster/xyz/ptp/CLOCK_REALTIME this is not address the event is published to
eventSource := fmt.Sprintf(p.resourcePrefix, p.nodeName, fmt.Sprintf("/%s", source))
eventSource := path.Join(p.resourcePrefix, p.nodeName, source)
data := ceevent.Data{
Version: ceevent.APISchemaVersion,
Values: []ceevent.DataValue{},
Expand Down Expand Up @@ -289,7 +290,7 @@ func (p *PTPEventManager) GetPTPCloudEvents(data ceevent.Data, eventType ptp.Eve
if pubs, ok := p.publisherTypes[eventType]; ok {
cneEvent, cneErr := common.CreateEvent(
pubs.PubID, string(eventType),
fmt.Sprintf(p.resourcePrefix, p.nodeName, string(p.publisherTypes[eventType].Resource)),
path.Join(p.resourcePrefix, p.nodeName, string(p.publisherTypes[eventType].Resource)),
data)
if cneErr != nil {
return nil, fmt.Errorf("failed to create ptp event, %s", cneErr)
Expand Down Expand Up @@ -317,15 +318,15 @@ func (p *PTPEventManager) PublishEvent(state ptp.SyncState, ptpOffset int64, sou

// /cluster/xyz/ptp/CLOCK_REALTIME this is not address the event is published to
data := p.GetPTPEventsData(state, ptpOffset, source, eventType)
resourceAddress := fmt.Sprintf(p.resourcePrefix, p.nodeName, string(p.publisherTypes[eventType].Resource))
resourceAddress := path.Join(p.resourcePrefix, p.nodeName, string(p.publisherTypes[eventType].Resource))
p.publish(*data, resourceAddress, eventType)
// publish the event again as overall sync state
// SyncStateChange is the overall sync state including PtpStateChange and OsClockSyncStateChange
if eventType == ptp.PtpStateChange || eventType == ptp.OsClockSyncStateChange {
if state != p.lastOverallSyncState {
eventType = ptp.SyncStateChange
data = p.GetPTPEventsData(state, ptpOffset, source, eventType)
resourceAddress = fmt.Sprintf(p.resourcePrefix, p.nodeName, string(p.publisherTypes[eventType].Resource))
resourceAddress = path.Join(p.resourcePrefix, p.nodeName, string(p.publisherTypes[eventType].Resource))
p.publish(*data, resourceAddress, eventType)
p.lastOverallSyncState = state
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/ptp_operator/ptp_operator_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const (
)

var (
resourcePrefix = "/cluster/node/%s%s"
resourcePrefix = "/cluster/node"
publishers = map[ptp.EventType]*ptpTypes.EventPublisherType{}
config *common.SCConfiguration
eventManager *ptpMetrics.PTPEventManager
Expand Down

0 comments on commit 05a45db

Please sign in to comment.