Skip to content

Commit 17329ce

Browse files
committed
merge with master branch
2 parents b6fec42 + 925d764 commit 17329ce

File tree

36 files changed

+587
-62
lines changed

36 files changed

+587
-62
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Support publishing events consumed from [NATS](https://nats.io) topics. See the [documentation](https://accenture.github.io/reactive-interaction-gateway/docs/event-streams.html#nats) for how to get started. [#297](https://github.com/Accenture/reactive-interaction-gateway/issues/297)
1313
- Added validation for reverse proxy configuration. Now it crashes RIG on start when configuration is not valid or returns `400` when using REST API to update configuration. [#277](https://github.com/Accenture/reactive-interaction-gateway/issues/277)
14+
- Added basic distributed tracing support in [W3C Trace Context specification](https://www.w3.org/TR/trace-context/) with Jaeger and Openzipkin exporters. RIG opens a span at the API Gateway and emits trace context in Cloud Events following the [distributed tracing spec](https://github.com/cloudevents/spec/blob/v1.0/extensions/distributed-tracing.md). [#281](https://github.com/Accenture/reactive-interaction-gateway/issues/281)
1415

1516
### Changed
1617

config/config.exs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ config :rig, RIG.AuthorizationCheck.Submission,
122122
# Peerage
123123
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
124124

125-
config :rig, Rig.Discovery,
125+
config :rig, RIG.Discovery,
126126
discovery_type: {:system, "DISCOVERY_TYPE", nil},
127127
dns_name: {:system, "DNS_NAME", "localhost"}
128128

@@ -133,3 +133,14 @@ import_config "rig_inbound_gateway/config.exs"
133133
import_config "rig_metrics/config.exs"
134134
import_config "rig_outbound_gateway/config.exs"
135135
import_config "rig_tests/config.exs"
136+
137+
# --------------------------------------
138+
# Jaeger
139+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
140+
141+
config :rig, RIG.Tracing,
142+
jaeger_host: {:system, :charlist, "JAEGER_HOST", ''},
143+
jaeger_port: {:system, :integer, "JAEGER_PORT", 6831},
144+
jaeger_service_name: {:system, :charlist, "JAEGER_SERVICE_NAME", 'rig'},
145+
zipkin_address: {:system, :charlist, "ZIPKIN_ADDR", ''},
146+
zipkin_service_name: {:system, "ZIPKIN_SERVICE_NAME", "rig"}

config/prod.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ config :rig, Rig.Application, log_level: {:system, :atom, "LOG_LEVEL", :warn}
77
# Peerage
88
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99

10-
config :rig, Rig.Discovery,
10+
config :rig, RIG.Discovery,
1111
discovery_type: {:system, "DISCOVERY_TYPE", nil},
1212
dns_name: {:system, "DNS_NAME", "localhost"}

docs/api-gateway.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ $ docker run -d \
7575
After that we should be able to reach our small demo service through RIG:
7676

7777
```bash
78-
$ curl localhost:4000
78+
$ curl \
79+
-H 'traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01' \
80+
-H 'tracestate: hello=tracing' \
81+
localhost:4000
7982
Hi, I'm a demo service!
8083
```
8184
@@ -93,7 +96,10 @@ $ docker run \
9396
Note that this way we don't need a Docker volume, which might work better in your environment. Again, we should be able to reach the demo service:
9497

9598
```bash
96-
$ curl localhost:4000
99+
$ curl \
100+
-H 'traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01' \
101+
-H 'tracestate: hello=tracing' \
102+
localhost:4000
97103
Hi, I'm a demo service!
98104
```
99105

docs/distributed-tracing.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
id: distributed-tracing
3+
title: Distributed Tracing
4+
sidebar_label: Distributed Tracing
5+
---
6+
7+
RIG is able to process distributed tracing data following the [W3C Trace Contexts](https://www.w3.org/TR/trace-context/). Sometimes RIG expects the trace context to be in the (HTTP) Header, and sometimes in the event payload itself. With events, we always speak of cloudevents following the [distributed tracing extension](https://github.com/cloudevents/spec/blob/v1.0/extensions/distributed-tracing.md).
8+
9+
There is one key rule when RIG expects the trace context either in the header or in the cloudevent:
10+
11+
1. if we talk of messages, then RIG expects the trace context to be in the (HTTP) header
12+
2. if we talk of events (cloudevents), then RIG expects the trace context to be in the cloudevent
13+
14+
In our point of view, the difference of a message to an event is the following:
15+
16+
* a message is a request from one system to another for an action to be taken. The sender expects that the message will get processed somehow
17+
* an event is a notification that data has been processed and some objects’ state has changed
18+
* thus, a message and events have a different correlation between producer and consumer:
19+
* messages have 1-to-1 correlation between a producer and a consumer
20+
* events have a 1-to-n correlation between a producer and (potentially multiple) consumers
21+
22+
As a concrete example how distributed tracing has been implemented, read about it in the [channels-example](../examples/channels-example/README.md#one-word-to-distributed-tracing).
File renamed without changes.
File renamed without changes.

examples/api-gateway/service.js renamed to examples/api-gateway/http/service.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const http = require("http");
22
const port = 3000;
33
const handler = (req, res) => {
44
console.log(`Request URL: ${req.url}`);
5+
console.log(JSON.stringify(req.headers));
56
res.end("Hi, I'm a demo service!\n");
67
}
78
const server = http.createServer(handler);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# API Gateway HTTP <> Kafka
2+
3+
First start Kafka
4+
5+
```shell
6+
docker-compose -f kafka.docker-compose.yml up -d
7+
```
8+
9+
Start RIG locally:
10+
11+
```shell
12+
cd ../../../
13+
export KAFKA_SOURCE_TOPICS=example
14+
export KAFKA_BROKERS=localhost:9092
15+
config=$(cat examples/api-gateway/kafka/config.json)
16+
export PROXY_CONFIG_FILE="$config"
17+
mix run --no-halt
18+
```
19+
20+
[Download some quickstart scripts for Kafka](https://kafka.apache.org/quickstart) and run a consumer (note: there must not be a space in the path of the script):
21+
22+
```shell
23+
/path/to/download/folder/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic example --from-beginning
24+
```
25+
26+
After that we should be able to send events to Kafka through RIG:
27+
28+
```shell
29+
curl -X POST \
30+
-H 'traceparent: 00-9c18b63f316cbfe3854122c20c8c6b23-22d69e0945046f2d-01' \
31+
--data '{"specversion":"0.2","type":"com.github.pull.create","source":"https://github.com/cloudevents/spec/pull","id":"A234-1234-1234","time":"2018-04-05T17:31:00Z","data":"hello"}' \
32+
localhost:4000
33+
```
34+
35+
You should see the message in the Kafka consumer.
36+
37+
> RIG does not yet support forwarding trace context to a Kafka backend. There is an issue that addresses this.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"id": "my-kafka-service",
4+
"version_data": {
5+
"default": {
6+
"endpoints": [{
7+
"id": "my-endpoint",
8+
"method": "POST",
9+
"path": "/",
10+
"target": "kafka",
11+
"topic": "example"
12+
}]
13+
}
14+
}
15+
}
16+
]

0 commit comments

Comments
 (0)