Skip to content

add support for Subsciption.replyTo property#325

Merged
knative-prow-robot merged 2 commits into
knative:masterfrom
markfisher:chaining-issue216
Aug 14, 2018
Merged

add support for Subsciption.replyTo property#325
knative-prow-robot merged 2 commits into
knative:masterfrom
markfisher:chaining-issue216

Conversation

@markfisher
Copy link
Copy Markdown
Contributor

Fixes #216

Proposed Changes

  • Subscription now accepts an optional "replyTo" property
  • Bus implementations pass the Subscription's replyTo property when delegating to the common dispatcher
  • the dispatcher will forward a non-empty response body as a new request to the destination specified by the replyTo if present
  • headers will be propagated, including a correlation ID header if provided in the request

@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 6, 2018
@markfisher
Copy link
Copy Markdown
Contributor Author

/assign @evankanderson
/assign @scothis

@markfisher markfisher changed the title wip add support for Subsciption.replyTo property Aug 6, 2018
@markfisher
Copy link
Copy Markdown
Contributor Author

/test pull-knative-eventing-integration-tests

subscription.Name, subscription.Spec.Channel, subscription.Spec.Subscriber)
message := fromKafkaMessage(msg)
err := d.messageDispatcher.DispatchMessage(subscription.Spec.Subscriber, subscription.Namespace, message)
err := d.messageDispatcher.DispatchMessage(subscription.Spec.Subscriber, subscription.Spec.ReplyTo, subscription.Namespace, message)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These feels like we should wrap the message and replyTo in a struct and then DispatchMessage is (subscriber, event)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should we consider whether subscriber and namespace also belong in the struct? (would be a single "envelope" message parameter if so).

WDYT @scothis? I addressed all of the other comments (so far) besides this one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The message and destination feel fundamental to me. I'd be in favor of something like:

func (d *MessageDispatcher) DispatchMessage(message *Message, destination string, opts *DispatchOpts) error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I went with a DispatchDefaults struct. RFAL @n3wscott @scothis. Thanks!

Comment thread pkg/buses/message_dispatcher.go Outdated
if err != nil {
return fmt.Errorf("Unable to complete request %v", err)
}
if replyTo != "" && res != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wrap this in executeReply?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

after refactoring so that executeRequest returns a Message (based on the suggestion by @scothis below), this will be reduced to a single call to executeRequest for the reply Message

Copy link
Copy Markdown
Contributor

@scothis scothis left a comment

Choose a reason for hiding this comment

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

I really like the direction, a few nits inline

Comment thread pkg/buses/message_dispatcher.go Outdated
return nil
}

func (d *MessageDispatcher) executeRequest(destination string, defaultNamespace string, message *Message) (*http.Response, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

executeRequest should return a Message rather than an http response so that the http transport remains encapsulated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment thread pkg/buses/message_dispatcher.go Outdated
// The destination and replyTo are DNS names. For names with a single label,
// the default namespace is used to expand it into a fully qualified name
// within the cluster.
func (d *MessageDispatcher) DispatchMessage(destination string, replyTo string, defaultNamespace string, message *Message) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

perhaps rename replyTo to defaultReplyTo to indicate in the future there may be other sources of metadata to configure replies.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment thread pkg/buses/message_dispatcher.go Outdated
return fmt.Errorf("Unable to read response %v", err)
}
replyMessage := Message{headers, payload}
d.executeRequest(replyTo, defaultNamespace, &replyMessage)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should an error sending the reply be returned instead of suppressed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes

Comment thread pkg/buses/message.go Outdated

var forwardPrefixes = []string{
// knative
"x-knative-",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe just knative- since the x- prefix is generally discouraged

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

@markfisher markfisher force-pushed the chaining-issue216 branch 2 times, most recently from 0fb1607 to bbe2fb6 Compare August 8, 2018 13:50
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 8, 2018
Subscriber string `json:"subscriber"`

// Target service DNS name for replies returned by the subscriber.
ReplyTo string `json:"replyTo"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think replyTo is optional, so the json annotation should be json:"replyTo,omitempty"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

indeed, good catch!

@n3wscott
Copy link
Copy Markdown
Contributor

n3wscott commented Aug 8, 2018

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 8, 2018
Copy link
Copy Markdown
Contributor

@scothis scothis left a comment

Choose a reason for hiding this comment

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

/lgtm

Comment thread pkg/buses/gcppubsub/bus.go Outdated
Payload: pubsubMessage.Data,
}
err := b.messageDispatcher.DispatchMessage(subscriber, namespace, message)
defaults := buses.DispatchDefaults{Namespace: sub.Namespace, ReplyTo: sub.Spec.ReplyTo}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: put each property on a dedicated line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Comment thread pkg/buses/message_dispatcher.go Outdated
headers := d.fromHTTPHeaders(res.Header)
// TODO: add configurable whitelisting of propagated headers/prefixes (configmap?)
correlationID := message.Headers[correlationIDHeaderName]
if correlationID != "" {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this can be combined with the previous line:

if correlationID, ok := message.Headers[correlationIDHeaderName]; ok {
    headers[correlationIDHeaderName] = correlationID
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks, changed

@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Aug 9, 2018
@markfisher
Copy link
Copy Markdown
Contributor Author

@n3wscott @scothis I addressed the latest round of review comments; please re-lgtm if you're ok with it

@n3wscott
Copy link
Copy Markdown
Contributor

n3wscott commented Aug 9, 2018

/lgtm

/test pull-knative-eventing-integration-tests

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 9, 2018
@scothis
Copy link
Copy Markdown
Contributor

scothis commented Aug 9, 2018

/lgtm
@evankanderson PTAL

In the future, we should be smarter about when we create a reply message. Generally, I'd only expect a reply to be created for a 2xx status codes that also has a non-empty body.

@markfisher
Copy link
Copy Markdown
Contributor Author

please have a look when you can @evankanderson

thanks!

@evankanderson
Copy link
Copy Markdown
Member

Sorry about that, this fell off my radar.

I'm okay experimenting with this approach, but I have a few concerns:

  1. How will this fit with an eventual Composer/Function Workflows type environment. In particular, I think @bbrowning or @csantanapr may have mentioned that OpenWhisk uses something more like a "mailbox/cubbyhole" for tracking message responses to particular events.
  2. It seems like this doesn't do much for request/response type abstractions; if you deliver an event to a channel, there's no easy way to get the response back. (It will go to N places specified by N subscriptions.)
  3. I suspect we want a URL rather than a DNS name.
  4. It seems like this introduces a correlation ID without documenting or motivating it.

At this point, I'm willing to approve this PR as long as we all agree that we aren't too attached to this implementation yet, and that's it's more of a "spike" than a designed and accepted pattern.

We should probably have a discussion over the next few weeks about how to enable this sort of experimentation to proceed without confusing the overall repo between code that we're trying to raise to production quality and experimental forays that aren't part of our roadmap at this point.

Maybe annotations and/or PoC branches would be a good way to manage this?

@evankanderson
Copy link
Copy Markdown
Member

/approve

but I'd really like to see us focus on raising the coverage numbers for pkg/controller/channel, pkg/controller/bus, and pkg/buses before adding more features.

@knative-prow-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: evankanderson, markfisher, n3wscott

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 13, 2018
@knative-prow-robot knative-prow-robot merged commit 0195820 into knative:master Aug 14, 2018
@markfisher
Copy link
Copy Markdown
Contributor Author

@evankanderson I completely agree this should be treated as just an initial spike from which we can experiment... for example I have this rough PoC for request/reply correlation (your point 2, also makes use of the correlation-id you mention in point 4) and I'll start working on something similar for the "activation claim check" pattern (what you referred to as "mailbox/cubbyhole" in point 1). The key is that this initial layer of "chaining" can be a common foundation for both approaches (and likely others). Thanks for the approval. Looking forward to the next steps!

n3wscott pushed a commit to n3wscott/eventing that referenced this pull request Aug 14, 2018
* add support for Subsciption.replyTo property

fixes knative#216

* addressing review comments
scothis added a commit to scothis/eventing that referenced this pull request Sep 11, 2018
From [ROLES.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/ROLES.md#approver):

> Reviewer of the codebase for at least 3 months or 50% of project lifetime, whichever is shorter

- [First Issue](knative#80). Opened 6/11
- [First PR](knative#66). Opened 5/31
- [First Review](knative#79 (review)) 6/11

> Primary reviewer for at least 10 substantial PRs to the codebase

- knative#422 (review)
- knative#414 (review)
- knative#325 (review)
- knative#225 (review)
- knative#189 (review)
- knative#168 (review)
- knative#165 (review)
- knative#99 (review)
- knative#79 (review)
- knative#111 (review)

> Reviewed or merged at least 30 PRs to the codebase

- [Reviewed 23 PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+reviewed-by%3Ascothis)
- [Authored 34 merged PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+author%3Ascothis+is%3Amerged)
- [Authored 5 open PRs](https://github.com/knative/eventing/pulls/scothis)

> Nominated by an area lead

From [WORKING_GROUPS.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/WORKING-GROUPS.md#events)

/assign @vaikas-google

> With no objections from other leads

🤞

/cc @evankanderson @grantr @inlined @mattmoor
knative-prow-robot pushed a commit that referenced this pull request Sep 12, 2018
From [ROLES.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/ROLES.md#approver):

> Reviewer of the codebase for at least 3 months or 50% of project lifetime, whichever is shorter

- [First Issue](#80). Opened 6/11
- [First PR](#66). Opened 5/31
- [First Review](#79 (review)) 6/11

> Primary reviewer for at least 10 substantial PRs to the codebase

- #422 (review)
- #414 (review)
- #325 (review)
- #225 (review)
- #189 (review)
- #168 (review)
- #165 (review)
- #99 (review)
- #79 (review)
- #111 (review)

> Reviewed or merged at least 30 PRs to the codebase

- [Reviewed 23 PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+reviewed-by%3Ascothis)
- [Authored 34 merged PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+author%3Ascothis+is%3Amerged)
- [Authored 5 open PRs](https://github.com/knative/eventing/pulls/scothis)

> Nominated by an area lead

From [WORKING_GROUPS.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/WORKING-GROUPS.md#events)

/assign @vaikas-google

> With no objections from other leads

🤞

/cc @evankanderson @grantr @inlined @mattmoor
matzew pushed a commit to matzew/eventing that referenced this pull request Apr 11, 2019
From [ROLES.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/ROLES.md#approver):

> Reviewer of the codebase for at least 3 months or 50% of project lifetime, whichever is shorter

- [First Issue](knative#80). Opened 6/11
- [First PR](knative#66). Opened 5/31
- [First Review](knative#79 (review)) 6/11

> Primary reviewer for at least 10 substantial PRs to the codebase

- knative#422 (review)
- knative#414 (review)
- knative#325 (review)
- knative#225 (review)
- knative#189 (review)
- knative#168 (review)
- knative#165 (review)
- knative#99 (review)
- knative#79 (review)
- knative#111 (review)

> Reviewed or merged at least 30 PRs to the codebase

- [Reviewed 23 PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+reviewed-by%3Ascothis)
- [Authored 34 merged PRs](https://github.com/knative/eventing/pulls?utf8=✓&q=is%3Apr+author%3Ascothis+is%3Amerged)
- [Authored 5 open PRs](https://github.com/knative/eventing/pulls/scothis)

> Nominated by an area lead

From [WORKING_GROUPS.MD](https://github.com/knative/docs/blob/dfc53c67c8e80d30b8863353c9e9b4ad00c41fa0/community/WORKING-GROUPS.md#events)

/assign @vaikas-google

> With no objections from other leads

🤞

/cc @evankanderson @grantr @inlined @mattmoor
matzew pushed a commit to matzew/eventing that referenced this pull request Oct 12, 2023
Co-authored-by: pierDipi <pierDipi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants