-
Notifications
You must be signed in to change notification settings - Fork 97
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
CloudEvents integration #404
Conversation
Codecov Report
@@ Coverage Diff @@
## master #404 +/- ##
==========================================
- Coverage 65.13% 64.19% -0.94%
==========================================
Files 26 29 +3
Lines 1592 1648 +56
==========================================
+ Hits 1037 1058 +21
- Misses 512 547 +35
Partials 43 43
Continue to review full report at Codecov.
|
@mthenw @elsteelbrain I don't see any tests that validate the event format. What are the plans to add the same |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First review of changes based on shifting CloudEvents spec.
event/event.go
Outdated
ReceivedAt uint64 `json:"receivedAt"` | ||
Data interface{} `json:"data"` | ||
DataType string `json:"dataType"` | ||
Namespace string `json:"namespace"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updates from today's CloudEvents meeting: Namespace
was removed as a property.
event/event.go
Outdated
Source struct { | ||
SourceType string `json:"source-type"` | ||
SourceID string `json:"source-id"` | ||
} `json:"source"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updates from today's CloudEvents meeting: The source
object was changed to a string that's a URI.
event/event.go
Outdated
SourceID string `json:"source-id"` | ||
} `json:"source"` | ||
EventID string `json:"event-id"` | ||
EventTime uint64 `json:"event-time"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
event-time
needs to be in an RFC3339 format. I wonder if it's better to store as a time.Time
instance? cc @mthenw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, it should be time.Time. time.Time marshals to RFC 3339 by default.
event/event.go
Outdated
} `json:"source"` | ||
EventID string `json:"event-id"` | ||
EventTime uint64 `json:"event-time"` | ||
ContentType string `json:"content-type"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a schema-url
property that's been added to the spec. It's optional and must be a URI.
event/event.go
Outdated
EventType: eventType, | ||
EventID: uuid.NewV4().String(), | ||
EventTime: uint64(time.Now().UnixNano() / int64(time.Millisecond)), | ||
ContentType: mime, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New()
should include a value for cloud-events-version
(0.1
) and source
(TBD),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few things that are missing:
- update readme with info that we now use Cloud Events format.
- add integration test (tests package) that checks the CloudEvents format.
- update source for http and custom event.
@alexdebrie What would be the value for the |
@elsteelbrain Hmm, I'm not sure. The new spec requires a URI, and one example shows @mthenw @ganeshvlrk Any ideas on what would be a good value for Full description:
|
Based on the definition, I am not sure we can provide sane ootb values here except for cases where we eventually configure the event sources. Should we consider leaving this empty for now? |
docs/api.md
Outdated
* `receivedAt` - `number` - the time (milliseconds) when the Event was received by the Event Gateway (provided by the event gateway) | ||
* `data` - type depends on `dataType` - the event payload | ||
* `dataType` - `string` - the mime type of `data` payload | ||
* `event-type` - `string` - the event name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove list of fields from here and leave only example and link to original spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want me to remove the example too or just this list of fields?
docs/api.md
Outdated
@@ -16,23 +16,27 @@ for invoking function. By default Events API runs on `:4000` port. | |||
|
|||
### Event Definition | |||
|
|||
All data that passes through the Event Gateway is formatted as an Event, based on our default Event schema: | |||
All data that passes through the Event Gateway is formatted as an CloudEvent, based on CloudEvent schema: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"as a CloudEvent"
docs/api.md
Outdated
@@ -16,23 +16,27 @@ for invoking function. By default Events API runs on `:4000` port. | |||
|
|||
### Event Definition | |||
|
|||
All data that passes through the Event Gateway is formatted as an Event, based on our default Event schema: | |||
All data that passes through the Event Gateway is formatted as an CloudEvent, based on CloudEvent schema: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please specify spec version here.
internal/zap/strings.go
Outdated
|
||
// Strings is a string array that implements MarshalLogArray. | ||
type Strings []string | ||
|
||
// MapStringInterface is a map that implements MarshalLogObject. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move it under MarshalLogArray
function
Updated as requested
event/event.go
Outdated
EventTypeVersion string `json:"eventTypeVersion"` | ||
CloudEventsVersion string `json:"cloudEventsVersion" validate:"required"` | ||
Source string `json:"source" validate:"url,required"` | ||
EventID string `json:"eventId" validate:"required"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eventID, not eventId
event/event.go
Outdated
event.Extensions = zap.MapStringInterface{ | ||
"eventgateway": map[string]interface{}{ | ||
"transformed": true, | ||
"transformation-version": "0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.1 string is used in few places, please defined it as const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TransformationVersion
router/event.go
Outdated
event.Data = string(body) | ||
} | ||
var sourceURL string | ||
if r.TLS != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking more about this one I think it won't work in all cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not?
event/event.go
Outdated
event := &Event{ | ||
EventType: eventType, | ||
CloudEventsVersion: "0.1", | ||
Source: source + "#transformationVersion=0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"https://serverless.com/event-gateway#transformationVersion=" + TransformationVersion
event/event.go
Outdated
event.Extensions = zap.MapStringInterface{ | ||
"eventgateway": map[string]interface{}{ | ||
"transformed": true, | ||
"transformation-version": "0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TransformationVersion
* `receivedAt` - `number` - the time (milliseconds) when the Event was received by the Event Gateway (provided by the event gateway) | ||
* `data` - type depends on `dataType` - the event payload | ||
* `dataType` - `string` - the mime type of `data` payload | ||
All data that passes through the Event Gateway is formatted as a CloudEvent, based on [CloudEvents v0.1 schema](https://github.com/cloudevents/spec/blob/master/spec.md): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexdebrie can you talk a final look here. Should we add something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mthenw @elsteelbrain Docs are fine by me
docs/api.md
Outdated
"eventType": "myapp.user.created", | ||
"eventID": "66dfc31d-6844-42fd-b1a7-a489a49f65f3", | ||
"cloudEventsVersion": "0.1", | ||
"source": "https://slsgateway.com/", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elsteelbrain please update the example
event := &Event{ | ||
EventType: eventType, | ||
CloudEventsVersion: "0.1", | ||
Source: "https://serverless.com/event-gateway/#transformationVersion=" + TransformationVersion, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://serverless.com/event-gateway
without trailing /
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The correct address for the page is https://serverless.com/event-gateway/
with the slash.
event/event.go
Outdated
mimeJSON = "application/json" | ||
mimeFormMultipart = "multipart/form-data" | ||
mimeFormURLEncoded = "application/x-www-form-urlencoded" | ||
TransformationVersion = "0.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's define it outside of this mime const, under Type consts.
event/event_test.go
Outdated
eventpkg.Event{ | ||
EventType: eventpkg.Type("user.created"), | ||
CloudEventsVersion: eventpkg.TransformationVersion, | ||
Source: "https://slsgateway.com#transformationVersion=0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests have to be updated.
No description provided.