Skip to content

Commit 6629f7e

Browse files
committed
examples: add CloudWatch Logs mountebank example
Signed-off-by: Matthew Fala <[email protected]>
1 parent 305db75 commit 6629f7e

File tree

7 files changed

+601
-0
lines changed

7 files changed

+601
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"component": "fluent-bit-executor",
3+
"config": {
4+
"fluentConfigFile": "./examples/mocks/mountebank/mountebank-fluent-bit.conf",
5+
"codeSource": {
6+
"base": {
7+
"name": "1.9.9",
8+
"repository": "https://github.com/fluent/fluent-bit.git",
9+
"branch": "1.9",
10+
"commit": "5c03b2e555a4fe1933707c5e1d119f481e28e616"
11+
},
12+
"cherryPicks": [
13+
{
14+
"name": "tls-options",
15+
"repository": "https://github.com/matthewfala/fluent-bit.git",
16+
"branch": "immutable-cwl-net-options",
17+
"commit": "5d9692f00b5295728bf0340d332896a7cc450a7e"
18+
}
19+
]
20+
},
21+
"outputFolder": "mountebank"
22+
},
23+
"child": {
24+
"generator": {
25+
"name": "basic",
26+
"config": {
27+
"logKey": "log",
28+
"contentLength": 20,
29+
"contentType": "uniform",
30+
"batchSize": 1,
31+
"contentUniformValue": "🦄"
32+
}
33+
},
34+
"datajet": {
35+
"name": "tcp",
36+
"config": {
37+
"port": 5170,
38+
"batchSize": 1,
39+
"addNewline": true,
40+
"maxRetries": 2,
41+
"tcpBufferLimit": 100000000,
42+
"logKey": "log"
43+
}
44+
},
45+
"stage": {
46+
"batchRate": 1,
47+
"timeLimit": 20
48+
}
49+
}
50+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[INPUT]
2+
# Listen for Application Logs on an Unused Port. Avoid Parsing Json for Performance.
3+
Name tcp
4+
Tag ApplicationLogs
5+
Listen 0.0.0.0
6+
Port 5170
7+
Format none
8+
Chunk_Size 64
9+
Buffer_Size 1024
10+
Mem_Buf_Limit 100MB
11+
Alias ApplicationLogsTCP
12+
log_level debug
13+
14+
[OUTPUT]
15+
Name cloudwatch_logs
16+
Match *
17+
log_stream_prefix CWL_0
18+
log_group_name montebank-test-{{{managed.testUUID}}}
19+
auto_create_group true
20+
region us-west-2
21+
workers 1
22+
net.keepalive on
23+
net.connect_timeout 10
24+
net.keepalive_max_recycle 2000
25+
net.keepalive_idle_timeout 30
26+
tls.verify false
27+
port 4545
28+
endpoint 127.0.0.1
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"port": 4545,
3+
"protocol": "https",
4+
"stubs": [
5+
{
6+
"predicates": [{
7+
"and": [
8+
{
9+
"equals": {
10+
"path": "/",
11+
"method": "POST",
12+
"headers": {
13+
"Content-Type": "application/x-amz-json-1.1",
14+
"X-Amz-Target": "Logs_20140328.PutLogEvents"
15+
}
16+
}
17+
}
18+
]
19+
}],
20+
"responses": [
21+
{
22+
"is": {
23+
"statusCode": 200,
24+
"headers": {
25+
"x-amzn-RequestId": "d35a6920-52e1-4f3a-bf8f-46016f474463",
26+
"Connection": "keep-alive",
27+
"Keep-Alive": "timeout=5",
28+
"Content-Type": "application/x-amz-json-1.1",
29+
"Content-Length": "80"
30+
},
31+
"body": "{\"nextSequenceToken\":\"49637338213634440402126044667090232594261646769605574882\"}",
32+
"repeat": 5
33+
}
34+
},
35+
{
36+
"is": {
37+
"statusCode": 400,
38+
"body": {
39+
"__type": "ServiceUnavailableException",
40+
"message": "The service cannot complete the request."
41+
}
42+
}
43+
}
44+
]
45+
},
46+
{
47+
"responses": [
48+
{
49+
"is": {
50+
"statusCode": 200,
51+
"headers": {
52+
"x-amzn-RequestId": "d35a6920-52e1-4f3a-bf8f-46016f474463",
53+
"Connection": "keep-alive",
54+
"Content-Type": "application/x-amz-json-1.1",
55+
"Content-Length": 0,
56+
"Date": "Mon, 13 Mar 2023 23:09:24 GMT",
57+
"Keep-Alive": "timeout=5"
58+
}
59+
}
60+
}
61+
],
62+
"predicates": [{
63+
"and": [
64+
{
65+
"equals": {
66+
"path": "/",
67+
"method": "POST",
68+
"headers": {
69+
"Content-Type": "application/x-amz-json-1.1",
70+
"X-Amz-Target": "Logs_20140328.CreateLogGroup"
71+
}
72+
}
73+
},
74+
{
75+
"not": {
76+
"contains": { "body": "requiredField" },
77+
"caseSensitive": true
78+
}
79+
}
80+
]
81+
}]
82+
},
83+
{
84+
"responses": [
85+
{
86+
"is": {
87+
"statusCode": 200,
88+
"headers": {
89+
"x-amzn-RequestId": "d35a6920-52e1-4f3a-bf8f-46016f474463",
90+
"Connection": "keep-alive",
91+
"Content-Type": "application/x-amz-json-1.1",
92+
"Content-Length": 0,
93+
"Date": "Mon, 13 Mar 2023 23:09:24 GMT",
94+
"Keep-Alive": "timeout=5"
95+
},
96+
"body": {
97+
"logGroups": [
98+
{
99+
"arn": "arn:aws:logs:us-east-1:123456789012:log-group:monitoring-logGroup-1234:*",
100+
"creationTime": 1393545600000,
101+
"logGroupName": "monitoring-logGroup-1234"
102+
}
103+
]
104+
}
105+
}
106+
}
107+
],
108+
"predicates": [{
109+
"and": [
110+
{
111+
"equals": {
112+
"path": "/",
113+
"method": "POST",
114+
"headers": {
115+
"Content-Type": "application/x-amz-json-1.1",
116+
"X-Amz-Target": "Logs_20140328.DescribeLogGroups"
117+
}
118+
}
119+
},
120+
{
121+
"not": {
122+
"contains": { "body": "requiredField" },
123+
"caseSensitive": true
124+
}
125+
}
126+
]
127+
}]
128+
}
129+
]
130+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
{
2+
"port": 4545,
3+
"protocol": "https",
4+
"stubs": [
5+
{
6+
"predicates": [{
7+
"and": [
8+
{
9+
"equals": {
10+
"path": "/",
11+
"method": "POST",
12+
"headers": {
13+
"Content-Type": "application/x-amz-json-1.1",
14+
"X-Amz-Target": "Logs_20140328.PutLogEvents"
15+
}
16+
}
17+
}
18+
]
19+
}],
20+
"responses": [
21+
{
22+
"is": {
23+
"statusCode": 200,
24+
"headers": {
25+
"x-amzn-RequestId": "d35a6920-52e1-4f3a-bf8f-46016f474463",
26+
"Connection": "keep-alive",
27+
"Keep-Alive": "timeout=5",
28+
"Content-Type": "application/x-amz-json-1.1",
29+
"Content-Length": "80"
30+
},
31+
"body": "{\"nextSequenceToken\":\"49637338213634440402126044667090232594261646769605574882\"}",
32+
"repeat": 5
33+
}
34+
}
35+
]
36+
},
37+
{
38+
"responses": [
39+
{
40+
"is": {
41+
"statusCode": 200,
42+
"headers": {
43+
"x-amzn-RequestId": "d35a6920-52e1-4f3a-bf8f-46016f474463",
44+
"Connection": "keep-alive",
45+
"Content-Type": "application/x-amz-json-1.1",
46+
"Content-Length": 0,
47+
"Date": "Mon, 13 Mar 2023 23:09:24 GMT",
48+
"Keep-Alive": "timeout=5"
49+
}
50+
}
51+
}
52+
],
53+
"predicates": [{
54+
"and": [
55+
{
56+
"equals": {
57+
"path": "/",
58+
"method": "POST",
59+
"headers": {
60+
"Content-Type": "application/x-amz-json-1.1",
61+
"X-Amz-Target": "Logs_20140328.CreateLogGroup"
62+
}
63+
}
64+
},
65+
{
66+
"not": {
67+
"contains": { "body": "requiredField" },
68+
"caseSensitive": true
69+
}
70+
}
71+
]
72+
}]
73+
},
74+
{
75+
"responses": [
76+
{
77+
"is": {
78+
"statusCode": 200,
79+
"headers": {
80+
"x-amzn-RequestId": "d35a6920-52e1-4f3a-bf8f-46016f474463",
81+
"Connection": "keep-alive",
82+
"Content-Type": "application/x-amz-json-1.1",
83+
"Content-Length": 0,
84+
"Date": "Mon, 13 Mar 2023 23:09:24 GMT",
85+
"Keep-Alive": "timeout=5"
86+
},
87+
"body": {
88+
"logGroups": [
89+
{
90+
"arn": "arn:aws:logs:us-east-1:123456789012:log-group:monitoring-logGroup-1234:*",
91+
"creationTime": 1393545600000,
92+
"logGroupName": "monitoring-logGroup-1234"
93+
}
94+
]
95+
}
96+
}
97+
}
98+
],
99+
"predicates": [{
100+
"and": [
101+
{
102+
"equals": {
103+
"path": "/",
104+
"method": "POST",
105+
"headers": {
106+
"Content-Type": "application/x-amz-json-1.1",
107+
"X-Amz-Target": "Logs_20140328.DescribeLogGroups"
108+
}
109+
}
110+
},
111+
{
112+
"not": {
113+
"contains": { "body": "requiredField" },
114+
"caseSensitive": true
115+
}
116+
}
117+
]
118+
}]
119+
}
120+
]
121+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## Mountebank Mock API Instructions
2+
3+
This is a prototype of a mock CloudWatch API server via Mountebank. See the configuration file for the mock in mountebank.json
4+
5+
To run a test, run the mock mountebank CloudWatch API server via:
6+
```
7+
bash ./examples/mocks/mountebank/start_cloudwatch_mock.sh
8+
```
9+
10+
Then start your Fluent Bit tests.
11+
12+
Fluent Bit CloudWatch will need to be configured with the following settings:
13+
14+
```
15+
[OUTPUT]
16+
Name cloudwatch_logs
17+
Match dummy
18+
log_stream_prefix TCP_A_3
19+
log_group_name segfault_tcp_cloudwatch_3
20+
auto_create_group true
21+
region us-west-2
22+
workers 1
23+
tls.verify false
24+
port 4545
25+
endpoint 127.0.0.1
26+
```
27+
28+
Notably the following are set:
29+
```
30+
tls.verify false
31+
port 4545
32+
endpoint 127.0.0.1
33+
```
34+
35+
These options are enabled by the following cherrypicked commit:
36+
```
37+
https://github.com/matthewfala/fluent-bit.git immutable-cwl-net-options 5d9692f00b5295728bf0340d332896a7cc450a7e
38+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
2+
3+
_term() {
4+
echo "Caught SIGTERM signal!"
5+
kill -TERM "$child" 2>/dev/null
6+
}
7+
8+
trap _term SIGTERM
9+
10+
# Start the mock API
11+
docker pull bbyars/mountebank:2.8.2
12+
docker run --rm --privileged -p 4430:4430 -p 2525:2525 -p 4545:4545 -p 5555:5555 bbyars/mountebank:2.8.2 start &
13+
14+
# docker run --privileged --network host --rm -p 2525:2525 -p 4545:4545 -p 5555:5555 bbyars/mountebank:2.8.2 start &
15+
child=$!
16+
17+
sleep 1
18+
19+
config=`cat $SCRIPT_DIR/mountebank.json`
20+
echo $config
21+
curl -i -X POST -H 'Content-Type: application/json' http://localhost:2525/imposters --data "$config"
22+
23+
wait "$child"

0 commit comments

Comments
 (0)