Skip to content

Commit 2322dae

Browse files
committed
pipeline: processor: add SQL docs
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 618425e commit 2322dae

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
* [Processors](pipeline/processors/README.md)
131131
* [Content Modifier](pipeline/processors/content-modifier.md)
132132
* [Metrics Selector](pipeline/processors/metrics-selector.md)
133+
* [SQL](pipeline/processors/sql.md)
133134
* [Filters](pipeline/filters/README.md)
134135
* [AWS Metadata](pipeline/filters/aws-metadata.md)
135136
* [CheckList](pipeline/filters/checklist.md)

pipeline/processors/sql.md

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Structured Query Language (SQL)
2+
3+
The **sql** processor provides a simple interface to select content from Logs by also supporting conditional expressions.
4+
5+
Our SQL processor does not depend on a database or indexing; it runs everything on the fly (this is good). We don't have the concept of tables but you run the query on the STREAM.
6+
7+
Note that this processor differs from the "stream processor interface" that runs after the filters; this one can only be used in the processor's section of the input plugins when using YAML configuration mode.
8+
9+
## Configuration Parameters
10+
11+
| Key | Description |
12+
| :---------- | :--- |
13+
| query | Define the SQL statement to run on top of the Logs stream; it must end with `;` . |
14+
15+
16+
17+
### Simple selection example
18+
19+
The following example generates a sample message with two keys called `key` and `http.url`. By using a simple SQL statement we will select only the key `http.url`.
20+
21+
```yaml
22+
pipeline:
23+
inputs:
24+
- name: dummy
25+
dummy: '{"key1": "123.4", "http.url": "https://fluentbit.io/search?q=docs"}'
26+
27+
processors:
28+
logs:
29+
- name: sql
30+
query: "SELECT http.url FROM STREAM;"
31+
32+
outputs:
33+
- name : stdout
34+
match: '*'
35+
format: json_lines
36+
```
37+
38+
### Extract and select example
39+
40+
Similar to the example above, now we will extract the parts of `http.url` and only select the domain from the value, for that we will use together content-modifier and sql processors together:
41+
42+
```yaml
43+
pipeline:
44+
inputs:
45+
- name: dummy
46+
dummy: '{"key1": "123.4", "http.url": "https://fluentbit.io/search?q=docs"}'
47+
48+
processors:
49+
logs:
50+
- name: content_modifier
51+
action: extract
52+
key: "http.url"
53+
pattern: ^(?<http_protocol>https?):\/\/(?<http_domain>[^\/\?]+)(?<http_path>\/[^?]*)?(?:\?(?<http_query_params>.*))?
54+
55+
- name: sql
56+
query: "SELECT http_domain FROM STREAM;"
57+
58+
outputs:
59+
- name : stdout
60+
match: '*'
61+
format: json_lines
62+
```
63+
64+
the expected output of this pipeline will be something like this:
65+
66+
```json
67+
{
68+
"date": 1711059261.630668,
69+
"http_domain": "fluentbit.io"
70+
}
71+
```
72+

0 commit comments

Comments
 (0)