Skip to content

Commit

Permalink
Merge pull request #397 from xmidt-org/denopink/patch/bad-legacy-even…
Browse files Browse the repository at this point in the history
…t-type

patch: bad legacy event type
  • Loading branch information
denopink authored Mar 5, 2024
2 parents 35b5e7a + cdb0b7f commit 4c3bf6a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions deviceStatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func newOnlineMessage(source string, d device.Interface) (string, *wrp.Message)
}
updateTimestampMetadata(m, t)

return eventType, m
return m.FindEventStringSubMatch(), m
}

func offlinePayload(t time.Time, d device.Interface) []byte {
Expand Down Expand Up @@ -108,7 +108,7 @@ func newOfflineMessage(source string, d device.Interface) (string, *wrp.Message)
}
updateTimestampMetadata(m, t)

return eventType, m
return m.FindEventStringSubMatch(), m
}

func updateTimestampMetadata(m *wrp.Message, t time.Time) {
Expand Down
7 changes: 4 additions & 3 deletions eventDispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ func (d *eventDispatcher) OnDeviceEvent(event *device.Event) {
d.logger.Error("Error dispatching event", zap.Any("eventType", eventType), zap.Any("destination", destination), zap.Error(err))
}
} else if strings.HasPrefix(destination, DNSPrefix) {
eventType = event.Type.String()
unfilteredURL := destination[len(DNSPrefix):]
url, err = d.dispatchTo(unfilteredURL, contentType, event.Contents)
url, err = d.dispatchTo(unfilteredURL, contentType, event.Contents, eventType)
if err != nil {
d.logger.Error("Error dispatching to endpoint", zap.Any("destination", destination), zap.Error(err))
}
Expand Down Expand Up @@ -261,7 +262,7 @@ func (d *eventDispatcher) encodeAndDispatchEvent(eventType string, format wrp.Fo
return url, nil
}

func (d *eventDispatcher) dispatchTo(unfiltered string, contentType string, contents []byte) (string, error) {
func (d *eventDispatcher) dispatchTo(unfiltered string, contentType string, contents []byte, eventType string) (string, error) {
var (
err error
url = unfiltered
Expand All @@ -278,7 +279,7 @@ func (d *eventDispatcher) dispatchTo(unfiltered string, contentType string, cont
}

return request.URL.String(), d.send(
context.WithValue(context.Background(), eventTypeContextKey{}, DNSPrefix),
context.WithValue(context.Background(), eventTypeContextKey{}, eventType),
request,
)
}
Expand Down

0 comments on commit 4c3bf6a

Please sign in to comment.