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.15] OCPBUGS-41946: fix double / in ResourceAddress #356

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 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 @@ -208,7 +209,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: "v1",
Values: []ceevent.DataValue{},
Expand Down Expand Up @@ -237,7 +238,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 @@ -265,15 +266,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
5 changes: 3 additions & 2 deletions plugins/ptp_operator/ptp_operator_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"net"
"os"
"path"
"strings"
"sync"

Expand Down Expand Up @@ -62,7 +63,7 @@ const (
)

var (
resourcePrefix = "/cluster/node/%s%s"
resourcePrefix = "/cluster/node"
publishers = map[ptp.EventType]*ptpTypes.EventPublisherType{}
config *common.SCConfiguration
eventManager *ptpMetrics.PTPEventManager
Expand All @@ -88,7 +89,7 @@ func Start(wg *sync.WaitGroup, configuration *common.SCConfiguration, fn func(e
var err error
for _, publisherType := range publishers {
var pub pubsub.PubSub
if pub, err = createPublisher(fmt.Sprintf(resourcePrefix, nodeName, string(publisherType.Resource))); err != nil {
if pub, err = createPublisher(path.Join(resourcePrefix, nodeName, string(publisherType.Resource))); err != nil {
log.Errorf("failed to create a publisher %v", err)
return err
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/ptp_operator/ptp_operator_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"log"
"os"
"path"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -228,7 +229,7 @@ func Test_StartWithHTTP(t *testing.T) {
//CLIENT SUBSCRIPTION: create a subscription to consume events
endpointURL := fmt.Sprintf("%s%s", scConfig.BaseURL, "dummy")
for _, pTypes := range pubsubTypes {
sub := v1pubsub.NewPubSub(types.ParseURI(endpointURL), fmt.Sprintf(resourcePrefix, "test_node", string(pTypes.Resource)))
sub := v1pubsub.NewPubSub(types.ParseURI(endpointURL), path.Join(resourcePrefix, "test_node", string(pTypes.Resource)))
sub, _ = common.CreateSubscription(scConfig, sub)
assert.NotEmpty(t, sub.ID)
assert.NotEmpty(t, sub.URILocation)
Expand Down
Loading