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

Refactored Subscription model #429

Merged
merged 9 commits into from
May 25, 2018
Merged

Refactored Subscription model #429

merged 9 commits into from
May 25, 2018

Conversation

mthenw
Copy link
Contributor

@mthenw mthenw commented May 22, 2018

How did you implement it:

New subscription model is the first part of refactoring that will simplify subscription, and in the same time make them more powerful.

This PR adds type filed in the subscription model. Subscription can be async or sync. event field has been renamed to eventType. http event type is replaced with http.request event type.

Todos:

  • Write tests
  • Write documentation
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification commands / resources
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES
Is it a breaking change?: YES

@mthenw mthenw requested a review from RaeesBhatti May 22, 2018 09:12
@codecov
Copy link

codecov bot commented May 22, 2018

Codecov Report

Merging #429 into master will decrease coverage by 0.59%.
The diff coverage is 84.21%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #429     +/-   ##
=========================================
- Coverage   64.49%   63.89%   -0.6%     
=========================================
  Files          30       29      -1     
  Lines        1639     1601     -38     
=========================================
- Hits         1057     1023     -34     
+ Misses        538      536      -2     
+ Partials       44       42      -2
Impacted Files Coverage Δ
event/event.go 77.41% <100%> (ø) ⬆️
internal/cache/subscription_cache.go 86.15% <100%> (ø) ⬆️
router/router.go 55.83% <100%> (ø) ⬆️
httpapi/httpapi.go 53.39% <66.66%> (-0.89%) ⬇️
libkv/subscription.go 87.87% <83.6%> (+0.24%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d710407...f5194b9. Read the comment docs.

@@ -203,8 +203,9 @@ curl --request POST \
--url http://localhost:4001/v1/spaces/default/subscriptions \
--header 'content-type: application/json' \
--data '{
"type": "async",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to something like "sync": "false". ATM, is easy to confuse type and eventType i think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that from UX perspective it's better to have it like that because it's more explicit what type the subscription is. It's easier to immediately understand what it actually do. Also it allows introducing more types in the future. @alexdebrie @plfx any thoughts?

In general we should discuss things like that on design phase.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with type as originally designed


`http` event is a built-in type of event occurring for HTTP requests on paths defined in HTTP subscriptions. The
`data` field of an `http` event has the following structure:
`http.request` event is a built-in type of event occurring for HTTP requests on paths defined in HTTP subscriptions. The
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about request.http so that we can use the same pattern in other types potentially, e.g. webhook.com.github.push

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that http.request actually follows the pattern proposed by the spec. Otherwise you would have push.github.com.

@@ -135,7 +137,8 @@ func TestIntegration_HTTPSubscription(t *testing.T) {

postSubscription(testAPIServer.URL+"/v1/spaces/default/subscriptions", &subscription.Subscription{
FunctionID: function.ID("httpresponse"),
Event: "http",
Type: subscription.TypeSync,
EventType: event.Type("http"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean event.Type("http.request") or event.TypeHTTPRequest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Gonna fix that.

Copy link
Contributor

@RaeesBhatti RaeesBhatti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -119,18 +107,7 @@ func (service Service) DeleteSubscription(space string, id subscription.ID) erro
return &subscription.ErrSubscriptionNotFound{ID: sub.ID}
}

if sub.Event == event.TypeHTTP {
err = service.deleteEndpoint(space, sub.Method, sub.Path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some some time ago there was a concept of endpoints in EG. We removed it from Config API but it was still in the logic to prevent creating conflicting HTTP endpoint. Right now I migrated that logic to use subscriptions (which we need regardless) and this model and storing this in etcd is useless.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

@mthenw mthenw merged commit e4360c6 into master May 25, 2018
@mthenw mthenw deleted the new-flow branch May 25, 2018 08:16
@ganeshvlrk ganeshvlrk added this to the 0.8 -- Events API updates milestone Jun 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants