Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit 7d343be

Browse files
author
odacremolbap
committed
add getting started guide
1 parent d1df6d4 commit 7d343be

File tree

5 files changed

+105
-27
lines changed

5 files changed

+105
-27
lines changed

README.md

Lines changed: 78 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ To be able to use the broker we will create a Pod that allow us to send events i
3636
kubectl apply -f https://raw.githubusercontent.com/triggermesh/triggermesh-core/main/docs/getting-started/curl.yaml
3737
```
3838

39-
It is possible now to send events to the broker address by issuing curl commands. The response for ingested events must be an `HTTP 200`.
39+
It is possible now to send events to the broker address by issuing curl commands. The response for ingested events must be an `HTTP 200` which means that the broker has received it and will try to deliver them to configured triggers.
4040

4141
```console
4242
kubectl exec -ti curl -- curl -v http://demo-redisbroker-broker.default.svc.cluster.local:8080/ \
@@ -46,18 +46,18 @@ kubectl exec -ti curl -- curl -v http://demo-redisbroker-broker.default.svc.clus
4646
-H "Ce-Type: demo.type1" \
4747
-H "Ce-Source: curl" \
4848
-H "Content-Type: application/json" \
49-
-d '{"hello":"world"}'
49+
-d '{"test1":"no trigger configured yet"}'
5050
```
5151

52-
Sockeye is a popular CloudEvents consumer that exposes a web interface with the list of events received while the page is open. We will be creating 2 instances of sockeye, one as the target for consumed events and another one for the Dead Letter Sink.
53-
A Dead Letter Sink, abbreviated DLS is a destination that consumes events that a subscription was not able to deliver.
52+
Unfortunately we haven't configured any trigger yet, which means any ingested event will not be delivered. `event_display` is a CloudEvents consumer that logs to console the list of events received. We will be creating 2 instances of `event_display`, one as the target for consumed events and another one for the Dead Letter Sink.
53+
A Dead Letter Sink, abbreviated DLS is a destination that consumes events that a subscription was not able to deliver to the intended target.
5454

5555
```console
5656
# Target service
57-
kubectl apply -f https://raw.githubusercontent.com/triggermesh/triggermesh-core/main/docs/getting-started/sockeye-target.yaml
57+
kubectl apply -f https://raw.githubusercontent.com/triggermesh/triggermesh-core/main/docs/getting-started/display-target.yaml
5858

5959
# DLS service
60-
kubectl apply -f https://raw.githubusercontent.com/triggermesh/triggermesh-core/main/docs/getting-started/sockeye-deadlettersink.yaml
60+
kubectl apply -f https://raw.githubusercontent.com/triggermesh/triggermesh-core/main/docs/getting-started/display-deadlettersink.yaml
6161
```
6262

6363
The Trigger object configures the broker to consume events and send them to a target. The Trigger object can include filters that select which events should be forwarded to the target, and delivery options to configure retries and fallback targets when the event cannot be delivered.
@@ -66,9 +66,9 @@ The Trigger object configures the broker to consume events and send them to a ta
6666
kubectl apply -f https://raw.githubusercontent.com/triggermesh/triggermesh-core/main/docs/getting-started/trigger.yaml
6767
```
6868

69-
The Trigger created above filters by CloudEvents with `type: demo.type1`, if delivery fails it will issue 3 retries and then forward the CloudEvent to the `sokceye-deadlettersink` service.
69+
The Trigger created above filters by CloudEvents containing `type: demo.type1` attribute and delivers them to `display-target` service, if delivery fails it will issue 3 retries and then forward the CloudEvent to the `display-deadlettersink` service.
7070

71-
Using the `curl` Pod again we can send this CloudEvent to the broker, that will pass the filtering and forward the event to the `sockeye-target` service.
71+
Using the `curl` Pod again we can send this CloudEvent to the broker.
7272

7373
```console
7474
kubectl exec -ti curl -- curl -v http://demo-redisbroker-broker.default.svc.cluster.local:8080/ \
@@ -78,7 +78,76 @@ kubectl exec -ti curl -- curl -v http://demo-redisbroker-broker.default.svc.clus
7878
-H "Ce-Type: demo.type1" \
7979
-H "Ce-Source: curl" \
8080
-H "Content-Type: application/json" \
81-
-d '{"hello":"world"}'
81+
-d '{"test 2":"message for display target"}'
82+
```
83+
84+
The target display Pod will show the delivered event.
85+
86+
```console
87+
kubectl logs -l app=display-target --tail 100
88+
89+
☁️ cloudevents.Event
90+
Validation: valid
91+
Context Attributes,
92+
specversion: 1.0
93+
type: demo.type1
94+
source: curl
95+
id: 1234-abcd
96+
datacontenttype: application/json
97+
Extensions,
98+
triggermeshbackendid: 1666613846441-0
99+
Data,
100+
{
101+
"test": "value2"
102+
}
103+
```
104+
105+
To simulate a target failure we will reconfigure the target display service to make it point to a non existing Pod set:
106+
107+
```console
108+
k patch service display-target --patch '{"spec": {"selector":{"app":"foo"}}}'
109+
```
110+
111+
Any event that pass the filter will try to be sent to the target, and upon failing will be delivered to the DLS.
112+
113+
```console
114+
kubectl exec -ti curl -- curl -v http://demo-redisbroker-broker.default.svc.cluster.local:8080/ \
115+
-X POST \
116+
-H "Ce-Id: 1234-abcd" \
117+
-H "Ce-Specversion: 1.0" \
118+
-H "Ce-Type: demo.type1" \
119+
-H "Ce-Source: curl" \
120+
-H "Content-Type: application/json" \
121+
-d '{"test 3":"not delivered, will be sent to DLS"}'
122+
```
123+
124+
```console
125+
kubectl logs -l app=display-deadlettersink --tail 100
126+
127+
☁️ cloudevents.Event
128+
Validation: valid
129+
Context Attributes,
130+
specversion: 1.0
131+
type: demo.type1
132+
source: curl
133+
id: 1234-abcd
134+
datacontenttype: application/json
135+
Extensions,
136+
triggermeshbackendid: 1666613846441-0
137+
Data,
138+
{
139+
"test": "value3"
140+
}
141+
```
142+
143+
To clean up the getting started guide, delete each of the created assets:
144+
145+
```console
146+
kubectl delete -f \
147+
https://raw.githubusercontent.com/triggermesh/triggermesh-core/main/docs/getting-started/trigger.yaml\
148+
https://raw.githubusercontent.com/triggermesh/triggermesh-core/main/docs/getting-started/display-target.yaml\
149+
https://raw.githubusercontent.com/triggermesh/triggermesh-core/main/docs/getting-started/display-deadlettersink.yaml\
150+
https://raw.githubusercontent.com/triggermesh/triggermesh-core/main/docs/getting-started/broker.yaml\
82151
```
83152

84153
## Installation

docs/getting-started/sockeye-deadlettersink.yaml renamed to docs/getting-started/display-deadlettersink.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
apiVersion: apps/v1
22
kind: Deployment
33
metadata:
4-
name: sockeye-deadlettersink
4+
name: display-deadlettersink
55
spec:
66
selector:
77
matchLabels:
8-
app: sockeye-deadlettersink
8+
app: display-deadlettersink
99
template:
1010
metadata:
1111
labels:
12-
app: sockeye-deadlettersink
12+
app: display-deadlettersink
1313
spec:
1414
containers:
15-
- name: sockeye
16-
image: docker.io/n3wscott/sockeye:v0.7.0@sha256:e603d8494eeacce966e57f8f508e4c4f6bebc71d095e3f5a0a1abaf42c5f0e48
15+
- name: display
16+
image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display
1717
ports:
1818
- containerPort: 8080
1919

@@ -22,11 +22,11 @@ spec:
2222
apiVersion: v1
2323
kind: Service
2424
metadata:
25-
name: sockeye-deadlettersink
25+
name: display-deadlettersink
2626
spec:
2727
type: NodePort
2828
selector:
29-
app: sockeye-deadlettersink
29+
app: display-deadlettersink
3030
ports:
3131
- protocol: TCP
3232
port: 8080

docs/getting-started/sockeye-target.yaml renamed to docs/getting-started/display-target.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
apiVersion: apps/v1
22
kind: Deployment
33
metadata:
4-
name: sockeye-target
4+
name: display-target
55
spec:
66
selector:
77
matchLabels:
8-
app: sockeye-target
8+
app: display-target
99
template:
1010
metadata:
1111
labels:
12-
app: sockeye-target
12+
app: display-target
1313
spec:
1414
containers:
15-
- name: sockeye
16-
image: docker.io/n3wscott/sockeye:v0.7.0@sha256:e603d8494eeacce966e57f8f508e4c4f6bebc71d095e3f5a0a1abaf42c5f0e48
15+
- name: display
16+
image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display
1717
ports:
1818
- containerPort: 8080
1919

@@ -22,11 +22,11 @@ spec:
2222
apiVersion: v1
2323
kind: Service
2424
metadata:
25-
name: sockeye-target
25+
name: display-target
2626
spec:
2727
type: NodePort
2828
selector:
29-
app: sockeye-target
29+
app: display-target
3030
ports:
3131
- protocol: TCP
3232
port: 8080

docs/getting-started/trigger.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ spec:
1313
type: demo.type1
1414
target:
1515
ref:
16+
apiVersion: v1
1617
kind: Service
17-
group: v1
18-
name: sockeye-target
18+
name: display-target
1919

2020
delivery:
2121
retry: 3
2222
deadLetterSink:
2323
ref:
2424
kind: Service
25-
group: v1
26-
name: sockeye-deadlettersink
25+
apiVersion: v1
26+
name: display-deadlettersink
27+

pkg/reconciler/trigger/reconciler.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ func (r *Reconciler) resolveTarget(ctx context.Context, t *eventingv1alpha1.Trig
8181
"Failed to get target's URI: %w", err)
8282
}
8383

84+
if targetURI.URL().Port() == "" {
85+
targetURI.Host = targetURI.Host + ":8080"
86+
}
87+
8488
t.Status.TargetURI = targetURI
8589
t.Status.MarkTargetResolvedSucceeded()
8690

@@ -108,6 +112,10 @@ func (r *Reconciler) resolveDLS(ctx context.Context, t *eventingv1alpha1.Trigger
108112
"Failed to get dead letter sink's URI: %w", err)
109113
}
110114

115+
if dlsURI.URL().Port() == "" {
116+
dlsURI.Host = dlsURI.Host + ":8080"
117+
}
118+
111119
t.Status.DeadLetterSinkURI = dlsURI
112120
t.Status.MarkDeadLetterSinkResolvedSucceeded()
113121

0 commit comments

Comments
 (0)