Skip to content

Commit ace4c4c

Browse files
Merge pull request redhat-cne#87 from jzding/source-type
Add source in event
2 parents 1b6d2a8 + 27a7dbd commit ace4c4c

File tree

17 files changed

+85
-47
lines changed

17 files changed

+85
-47
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ run-consumer:
7878
go run examples/consumer/main.go
7979

8080
test:
81-
go test ./... -coverprofile=cover.out
81+
go test ./... --tags=unittests -coverprofile=cover.out
8282

8383
functests:
8484
SUITE=./test/cne hack/run-functests.sh

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ require (
99
github.com/onsi/ginkgo v1.16.5
1010
github.com/onsi/gomega v1.17.0
1111
github.com/prometheus/client_golang v1.11.0
12-
github.com/redhat-cne/rest-api v0.1.1-0.20211206194632-bc3eb46ad9d0
13-
github.com/redhat-cne/sdk-go v0.1.1-0.20211206194140-5b52c616af2b
12+
github.com/redhat-cne/rest-api v0.1.1-0.20220105171308-cc511366a079
13+
github.com/redhat-cne/sdk-go v0.1.1-0.20220105170230-b17827c91503
1414
github.com/sirupsen/logrus v1.8.1
1515
github.com/stretchr/testify v1.7.0
1616
github.com/valyala/fasthttp v1.29.0

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,10 @@ github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4O
381381
github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4=
382382
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
383383
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
384-
github.com/redhat-cne/rest-api v0.1.1-0.20211206194632-bc3eb46ad9d0 h1:dtm5GyMpu17/En+GmS7ojvRsEuG2e719MXH8CI8JXSY=
385-
github.com/redhat-cne/rest-api v0.1.1-0.20211206194632-bc3eb46ad9d0/go.mod h1:sGK4icx3lVW0vDFRIx2m/lRMwW/axcmADh7o0Y3ZiVE=
386-
github.com/redhat-cne/sdk-go v0.1.1-0.20211206194140-5b52c616af2b h1:Z7Y2QrpCyLiAWTGz0yyJtxOu3T7f9GCXAD/sYHdpcVk=
387-
github.com/redhat-cne/sdk-go v0.1.1-0.20211206194140-5b52c616af2b/go.mod h1:1FXE/O2PhDnazeCidsAIJJ5lLaaWHBXNP5HxaJ1hf0U=
384+
github.com/redhat-cne/rest-api v0.1.1-0.20220105171308-cc511366a079 h1:Qb9+5k3gES0qQfxLWfsEuzFpCkFMcV3LcTTE2p/ZtG0=
385+
github.com/redhat-cne/rest-api v0.1.1-0.20220105171308-cc511366a079/go.mod h1:vb1QG25ojKDcT4KMboBP2QRWZG7SNH9senqSsS4Khhk=
386+
github.com/redhat-cne/sdk-go v0.1.1-0.20220105170230-b17827c91503 h1:gfwZqJ0xiWF6eDrtQuYhzRblG7LBHYUbskUl0A+IANs=
387+
github.com/redhat-cne/sdk-go v0.1.1-0.20220105170230-b17827c91503/go.mod h1:1FXE/O2PhDnazeCidsAIJJ5lLaaWHBXNP5HxaJ1hf0U=
388388
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
389389
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
390390
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=

pkg/common/common.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func CreateSubscription(config *SCConfiguration, subscription pubsub.PubSub) (su
132132
}
133133

134134
// CreateEvent create an event
135-
func CreateEvent(pubSubID, eventType string, data ceevent.Data) (ceevent.Event, error) {
135+
func CreateEvent(pubSubID, eventType, source string, data ceevent.Data) (ceevent.Event, error) {
136136
// create an event
137137
if pubSubID == "" {
138138
return ceevent.Event{}, fmt.Errorf("id is a required field")
@@ -143,6 +143,7 @@ func CreateEvent(pubSubID, eventType string, data ceevent.Data) (ceevent.Event,
143143
event := v1event.CloudNativeEvent()
144144
event.ID = pubSubID
145145
event.Type = eventType
146+
event.SetSource(source)
146147
event.SetTime(types.Timestamp{Time: time.Now().UTC()}.Time)
147148
event.SetDataContentType(ceevent.ApplicationJSON)
148149
event.SetData(data)

plugins/mock/mock_plugin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,19 @@ func createMockEvent(pub pubsub.PubSub) (ceEvent.Event, error) {
113113
data := ceEvent.Data{
114114
Version: "v1",
115115
Values: []ceEvent.DataValue{{
116-
Resource: pub.Resource,
116+
Resource: string(ptp.SyncStatusState),
117117
DataType: ceEvent.NOTIFICATION,
118118
ValueType: ceEvent.ENUMERATION,
119119
Value: ptp.ACQUIRING_SYNC,
120120
},
121121
{
122-
Resource: pub.Resource,
122+
Resource: string(ptp.SyncStatusState),
123123
DataType: ceEvent.METRIC,
124124
ValueType: ceEvent.DECIMAL,
125125
Value: "99.6",
126126
},
127127
},
128128
}
129-
e, err := common.CreateEvent(pub.ID, string(ptp.PtpStateChange), data)
129+
e, err := common.CreateEvent(pub.ID, pub.Resource, string(ptp.PtpStateChange), data)
130130
return e, err
131131
}

plugins/ptp_operator/metrics/metrics.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,22 +544,23 @@ func (p *PTPEventManager) PublishEvent(state ptp.SyncState, ptpOffset int64, ifa
544544
if state == "" {
545545
return
546546
}
547+
source := fmt.Sprintf("/cluster/%s/ptp/interface/%s", p.nodeName, iface)
547548
data := ceevent.Data{
548549
Version: "v1",
549550
Values: []ceevent.DataValue{{
550-
Resource: fmt.Sprintf("/cluster/%s/ptp/interface/%s", p.nodeName, iface),
551+
Resource: string(ptp.SyncStatusState),
551552
DataType: ceevent.NOTIFICATION,
552553
ValueType: ceevent.ENUMERATION,
553554
Value: state,
554555
}, {
555-
Resource: fmt.Sprintf("/cluster/%s/ptp/interface/%s", p.nodeName, iface),
556+
Resource: string(ptp.SyncStatusState),
556557
DataType: ceevent.METRIC,
557558
ValueType: ceevent.DECIMAL,
558559
Value: float64(ptpOffset),
559560
},
560561
},
561562
}
562-
e, err := common.CreateEvent(p.publisherID, string(eventType), data)
563+
e, err := common.CreateEvent(p.publisherID, string(eventType), source, data)
563564
if err != nil {
564565
log.Errorf("failed to create ptp event, %s", err)
565566
return

vendor/github.com/redhat-cne/sdk-go/pkg/event/event.go

Lines changed: 6 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/redhat-cne/sdk-go/pkg/event/event_ce.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/redhat-cne/sdk-go/pkg/event/event_data.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/redhat-cne/sdk-go/pkg/event/event_marshal.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/redhat-cne/sdk-go/pkg/event/event_reader.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/redhat-cne/sdk-go/pkg/event/event_unmarshal.go

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/redhat-cne/sdk-go/pkg/event/event_writer.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/redhat-cne/sdk-go/pkg/event/ptp/source.go renamed to vendor/github.com/redhat-cne/sdk-go/pkg/event/ptp/resource.go

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/redhat-cne/sdk-go/pkg/event/redfish/resource.go

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/redhat-cne/sdk-go/v1/event/event.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,11 @@ github.com/prometheus/common/model
167167
github.com/prometheus/procfs
168168
github.com/prometheus/procfs/internal/fs
169169
github.com/prometheus/procfs/internal/util
170-
# github.com/redhat-cne/rest-api v0.1.1-0.20211206194632-bc3eb46ad9d0
170+
# github.com/redhat-cne/rest-api v0.1.1-0.20220105171308-cc511366a079
171171
## explicit; go 1.17
172172
github.com/redhat-cne/rest-api
173173
github.com/redhat-cne/rest-api/pkg/localmetrics
174-
# github.com/redhat-cne/sdk-go v0.1.1-0.20211206194140-5b52c616af2b
174+
# github.com/redhat-cne/sdk-go v0.1.1-0.20220105170230-b17827c91503
175175
## explicit; go 1.17
176176
github.com/redhat-cne/sdk-go/pkg/channel
177177
github.com/redhat-cne/sdk-go/pkg/errorhandler

0 commit comments

Comments
 (0)