-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add docs / samples for Sequence #1481
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
Changes from all commits
5b12a23
ac46e8a
298db19
6702e40
b5edd8f
c36d981
bb5c7c0
2ad2d1a
39b6f04
bdf7d93
a45d70e
1f9ba7f
ab11ab0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,197 @@ | ||||||
| --- | ||||||
| title: "Sequence Wired to event-display" | ||||||
| weight: 20 | ||||||
| type: "docs" | ||||||
| --- | ||||||
|
|
||||||
| # Using Sequences in series | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we can come up with a title that explicitly states the value of doing this -- what do you get from using sequences in a series? What use-case is this ideal for? (This is the first time I've seen the term "Sequence" in the context of Eventing; could be really helpful to add links out to more info if this is a new object we've added.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes, add a link to the sequence page you created further down in this PR :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could add a backpointer to it, however, my thinking was that the landing page will be sequence.md and then the links point to specific examples like this.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vaikas-google It's very hard to guarantee a particular reading path (thanks to Google search, people sharing links in Slack, people's own preferences when browsing, etc.) so it's best to add links to related content so that people can find the information no matter where they land. I would be in favor of moving "Overview" up before "Prerequisites" and adding a link to the sequence page there.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||||||
|
|
||||||
| ## Overview | ||||||
|
|
||||||
| We are going to create the following logical configuration. We create a CronJobSource, | ||||||
| feeding events to a (`Sequence`)[../../../sequence.md], then taking the output of that `Sequence` and | ||||||
| displaying the resulting output. | ||||||
|
|
||||||
|  | ||||||
|
|
||||||
| ## Prerequisites | ||||||
|
|
||||||
| For this example, we'll assume you have set up an `InMemoryChannel` | ||||||
| as well as Knative Serving (for our functions). The examples use `default` | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| namespace, again, if you want to deploy to another Namespace, you will need | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| to modify the examples to reflect this. | ||||||
|
|
||||||
| If you want to use different type of `Channel`, you will have to modify the | ||||||
vaikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| `Sequence.Spec.ChannelTemplate` to create the appropriate Channel resources. | ||||||
|
|
||||||
|
|
||||||
| ## Setup | ||||||
|
|
||||||
| ### Create the Knative Services | ||||||
|
|
||||||
| Change `default` below to create the steps in the Namespace where you want resources | ||||||
| created. | ||||||
|
|
||||||
| ```yaml | ||||||
| apiVersion: serving.knative.dev/v1beta1 | ||||||
| kind: Service | ||||||
| metadata: | ||||||
| name: first | ||||||
| spec: | ||||||
| template: | ||||||
| spec: | ||||||
| containers: | ||||||
| - image: us.gcr.io/probable-summer-223122/cmd-03315b715ae8f3e08e3a9378df706fbb@sha256:2656f39a7fcb6afd9fc79e7a4e215d14d651dc674f38020d1d18c6f04b220700 | ||||||
| env: | ||||||
| - name: STEP | ||||||
| value: "0" | ||||||
|
|
||||||
| --- | ||||||
| apiVersion: serving.knative.dev/v1beta1 | ||||||
| kind: Service | ||||||
| metadata: | ||||||
| name: second | ||||||
| spec: | ||||||
| template: | ||||||
| spec: | ||||||
| containers: | ||||||
| - image: us.gcr.io/probable-summer-223122/cmd-03315b715ae8f3e08e3a9378df706fbb@sha256:2656f39a7fcb6afd9fc79e7a4e215d14d651dc674f38020d1d18c6f04b220700 | ||||||
| env: | ||||||
| - name: STEP | ||||||
| value: "1" | ||||||
| --- | ||||||
| apiVersion: serving.knative.dev/v1beta1 | ||||||
| kind: Service | ||||||
| metadata: | ||||||
| name: third | ||||||
| spec: | ||||||
| template: | ||||||
| spec: | ||||||
| containers: | ||||||
| - image: us.gcr.io/probable-summer-223122/cmd-03315b715ae8f3e08e3a9378df706fbb@sha256:2656f39a7fcb6afd9fc79e7a4e215d14d651dc674f38020d1d18c6f04b220700 | ||||||
| env: | ||||||
| - name: STEP | ||||||
| value: "2" | ||||||
| --- | ||||||
| ``` | ||||||
|
|
||||||
|
|
||||||
| ```shell | ||||||
| kubectl -n default create -f ./steps.yaml | ||||||
| ``` | ||||||
|
|
||||||
| ### Create the Sequence | ||||||
|
|
||||||
| The `sequence.yaml` file contains the specifications for creating the Sequence. If you are using a different type of Channel, you need to change the | ||||||
| spec.channelTemplate to point to your desired Channel. | ||||||
|
|
||||||
| ```yaml | ||||||
| apiVersion: messaging.knative.dev/v1alpha1 | ||||||
| kind: Sequence | ||||||
| metadata: | ||||||
| name: sequence | ||||||
| spec: | ||||||
| channelTemplate: | ||||||
| apiVersion: messaging.knative.dev/v1alpha1 | ||||||
| kind: InMemoryChannel | ||||||
| steps: | ||||||
| - ref: | ||||||
| apiVersion: serving.knative.dev/v1beta1 | ||||||
| kind: Service | ||||||
| name: first | ||||||
| - ref: | ||||||
| apiVersion: serving.knative.dev/v1beta1 | ||||||
| kind: Service | ||||||
| name: second | ||||||
| - ref: | ||||||
| apiVersion: serving.knative.dev/v1beta1 | ||||||
| kind: Service | ||||||
| name: third | ||||||
| reply: | ||||||
| kind: Service | ||||||
| apiVersion: serving.knative.dev/v1beta1 | ||||||
| name: event-display | ||||||
| ``` | ||||||
|
|
||||||
| Change `default` below to create the `Sequence` in the Namespace where you want the | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| resources to be created. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete line 117 ("resources to be created.") to align with previous suggested edit. |
||||||
| ```shell | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add line: |
||||||
| kubectl -n default create -f ./sequence.yaml | ||||||
| ``` | ||||||
|
|
||||||
|
|
||||||
| ### Create the Service displaying the events created by Sequence | ||||||
|
|
||||||
| ```yaml | ||||||
| apiVersion: serving.knative.dev/v1beta1 | ||||||
| kind: Service | ||||||
| metadata: | ||||||
| name: event-display | ||||||
| spec: | ||||||
| template: | ||||||
| spec: | ||||||
| containers: | ||||||
| - image: gcr.io/knative-releases/github.com/knative/eventing-sources/cmd/event_display | ||||||
| ``` | ||||||
|
|
||||||
| Change `default` below to create the `Sequence` in the Namespace where you want your resources | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete line 137, since we said above that "default" will have to be changed in all following commands for users not using the default namespace. |
||||||
| to be created. | ||||||
|
|
||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add line: |
||||||
| ```shell | ||||||
| kubectl -n default create -f ./event-display.yaml | ||||||
| ``` | ||||||
|
|
||||||
| ### Create the CronJobSource targeting the Sequence | ||||||
|
|
||||||
vaikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| This will create a CronJobSource which will send a CloudEvent with {"message": "Hello world!"} as | ||||||
| the data payload every 2 minutes. | ||||||
|
|
||||||
| ```yaml | ||||||
| apiVersion: sources.eventing.knative.dev/v1alpha1 | ||||||
| kind: CronJobSource | ||||||
| metadata: | ||||||
| name: cronjob-source | ||||||
| spec: | ||||||
| schedule: "*/2 * * * *" | ||||||
| data: '{"message": "Hello world!"}' | ||||||
| sink: | ||||||
| apiVersion: messaging.knative.dev/v1alpha1 | ||||||
| kind: Sequence | ||||||
| name: sequence | ||||||
| ``` | ||||||
|
|
||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add line: |
||||||
| ```shell | ||||||
| kubectl -n default create -f ./cron-source.yaml | ||||||
| ``` | ||||||
|
|
||||||
| ### Inspecting the results | ||||||
|
|
||||||
| You can now see the final output by inspecting the logs of the event-display pods. | ||||||
|
|
||||||
| ```shell | ||||||
| kubectl -n default get pods | ||||||
| ``` | ||||||
|
|
||||||
| Then look at the logs for the event-display pod: | ||||||
|
|
||||||
|
|
||||||
| ```shell | ||||||
| kubectl -n default logs -l serving.knative.dev/service=event-display -c user-container | ||||||
| ☁️ cloudevents.Event | ||||||
| Validation: valid | ||||||
| Context Attributes, | ||||||
| cloudEventsVersion: 0.1 | ||||||
| eventType: samples.http.mod3 | ||||||
| source: /transformer/2 | ||||||
| eventID: df52b47e-02fd-45b2-8180-dabb572573f5 | ||||||
| eventTime: 2019-06-18T14:18:42.478140635Z | ||||||
| contentType: application/json | ||||||
| Data, | ||||||
| { | ||||||
| "id": 0, | ||||||
| "message": "Hello world! - Handled by 0 - Handled by 1 - Handled by 2" | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| And you can see that the initial Cron Source message ("Hello World!") has been appended to it by each | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'm still a little fuzzy on the takeaway. Can you expand on what we've accomplished here? |
||||||
| of the steps in the Sequence. | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| apiVersion: sources.eventing.knative.dev/v1alpha1 | ||
| kind: CronJobSource | ||
| metadata: | ||
| name: cronjob-source | ||
| spec: | ||
| schedule: "*/2 * * * *" | ||
| data: '{"message": "Hello world!"}' | ||
| sink: | ||
| apiVersion: messaging.knative.dev/v1alpha1 | ||
| kind: Sequence | ||
| name: sequence |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| apiVersion: serving.knative.dev/v1beta1 | ||
| kind: Service | ||
| metadata: | ||
| name: event-display | ||
| spec: | ||
| template: | ||
| spec: | ||
| containers: | ||
| - image: gcr.io/knative-releases/github.com/knative/eventing-sources/cmd/event_display |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| apiVersion: messaging.knative.dev/v1alpha1 | ||
| kind: Sequence | ||
| metadata: | ||
| name: sequence | ||
| spec: | ||
| channelTemplate: | ||
| apiVersion: messaging.knative.dev/v1alpha1 | ||
| kind: InMemoryChannel | ||
| steps: | ||
| - ref: | ||
| apiVersion: serving.knative.dev/v1beta1 | ||
| kind: Service | ||
| name: first | ||
| - ref: | ||
| apiVersion: serving.knative.dev/v1beta1 | ||
| kind: Service | ||
| name: second | ||
| - ref: | ||
| apiVersion: serving.knative.dev/v1beta1 | ||
| kind: Service | ||
| name: third | ||
| reply: | ||
| kind: Service | ||
| apiVersion: serving.knative.dev/v1beta1 | ||
| name: event-display |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| apiVersion: serving.knative.dev/v1alpha1 | ||
| kind: Service | ||
| metadata: | ||
| name: first | ||
| spec: | ||
| template: | ||
| spec: | ||
| containers: | ||
| - image: us.gcr.io/probable-summer-223122/cmd-03315b715ae8f3e08e3a9378df706fbb@sha256:2656f39a7fcb6afd9fc79e7a4e215d14d651dc674f38020d1d18c6f04b220700 | ||
| env: | ||
| - name: STEP | ||
| value: "0" | ||
|
|
||
| --- | ||
| apiVersion: serving.knative.dev/v1alpha1 | ||
| kind: Service | ||
| metadata: | ||
| name: second | ||
| spec: | ||
| template: | ||
| spec: | ||
| containers: | ||
| - image: us.gcr.io/probable-summer-223122/cmd-03315b715ae8f3e08e3a9378df706fbb@sha256:2656f39a7fcb6afd9fc79e7a4e215d14d651dc674f38020d1d18c6f04b220700 | ||
| env: | ||
| - name: STEP | ||
| value: "1" | ||
| --- | ||
| apiVersion: serving.knative.dev/v1alpha1 | ||
| kind: Service | ||
| metadata: | ||
| name: third | ||
| spec: | ||
| template: | ||
| spec: | ||
| containers: | ||
| - image: us.gcr.io/probable-summer-223122/cmd-03315b715ae8f3e08e3a9378df706fbb@sha256:2656f39a7fcb6afd9fc79e7a4e215d14d651dc674f38020d1d18c6f04b220700 | ||
| env: | ||
| - name: STEP | ||
| value: "2" | ||
| --- |
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.
Nice write up, @vaikas-google ! I'll review this later today.
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.
This PR has a lot more than I realized! Here's my first round of edits; still have a little more I'd like to do, but wanted to get these over to you.