fluent-plugin-grafana-loki 1.2.11 → 1.2.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +60 -2
- data/lib/fluent/plugin/out_loki.rb +8 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0867dbf084b2c7642c0433421013b062a414cd9965c7e3aa70b3c90522c7b5e5'
|
4
|
+
data.tar.gz: '090334cc38d3b48384e07922157acc368c5b2bb7db706a1f9706f3d19fb463d4'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8571fb5409342a6e68422daadffc7c165be80e52bcd7e6eb7156dda47cbf5271c9d6f8deab85084def1e117d6d46f97e0c55fc803ed0e71314f010155aaeb1bf
|
7
|
+
data.tar.gz: 9a10939c11b479696cab9c245af5168f62a83cb6f138e437c47fc4b90129e2e73eea99228c7e57bf3f3535bcc2c4ca92878a0da7038b8d1ee9d462971938931b
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
#
|
1
|
+
# FluentD output plugin
|
2
2
|
|
3
|
-
[Fluentd](https://fluentd.org/)
|
3
|
+
[Fluentd](https://fluentd.org/) is a data collector for unified logging layer, it can be configured with the Loki output plugin, provided in this folder, to ship logs to Loki.
|
4
|
+
|
5
|
+
See [docs/client/fluentd/README.md](../../docs/clients/fluentd/README.md) for detailed information.
|
4
6
|
|
5
7
|
## Development
|
6
8
|
|
@@ -13,6 +15,62 @@ To create the gem: `gem build fluent-plugin-grafana-loki.gemspec`
|
|
13
15
|
Useful additions:
|
14
16
|
`gem install rubocop`
|
15
17
|
|
18
|
+
## Testing
|
19
|
+
|
20
|
+
Start Loki using:
|
21
|
+
```
|
22
|
+
docker run -it -p 3100:3100 grafana/loki:latest
|
23
|
+
```
|
24
|
+
|
25
|
+
Verify that Loki accept and stores logs:
|
26
|
+
```
|
27
|
+
curl -H "Content-Type: application/json" -XPOST -s "http://localhost:3100/loki/api/v1/push" --data-raw "{\"streams\": [{\"stream\": {\"job\": \"test\"}, \"values\": [[\"$(date +%s)000000000\", \"fizzbuzz\"]]}]}"
|
28
|
+
curl "http://localhost:3100/loki/api/v1/query_range" --data-urlencode 'query={job="test"}' --data-urlencode 'step=300' | jq .data.result
|
29
|
+
```
|
30
|
+
The expected output is:
|
31
|
+
```
|
32
|
+
[
|
33
|
+
{
|
34
|
+
"stream": {
|
35
|
+
"job": "test"
|
36
|
+
},
|
37
|
+
"values": [
|
38
|
+
[
|
39
|
+
"1588337198000000000",
|
40
|
+
"fizzbuzz"
|
41
|
+
]
|
42
|
+
]
|
43
|
+
}
|
44
|
+
]
|
45
|
+
```
|
46
|
+
|
47
|
+
Start FluentBit + FluentD using:
|
48
|
+
```
|
49
|
+
LOKI_URL=http://{{ IP }}:3100 make fluentd-test
|
50
|
+
```
|
51
|
+
|
52
|
+
Verify that syslogs are being feeded into Loki:
|
53
|
+
```
|
54
|
+
curl "http://localhost:3100/loki/api/v1/query_range" --data-urlencode 'query={job="fluentd"}' --data-urlencode 'step=300' | jq .data.result
|
55
|
+
```
|
56
|
+
The expected output is:
|
57
|
+
```
|
58
|
+
[
|
59
|
+
{
|
60
|
+
"stream": {
|
61
|
+
"job": "fluentd"
|
62
|
+
},
|
63
|
+
"values": [
|
64
|
+
[
|
65
|
+
"1588336950379591919",
|
66
|
+
"log=\"May 1 14:42:30 ibuprofen avahi-daemon[859]: New relevant interface vethb503225.IPv6 for mDNS.\""
|
67
|
+
],
|
68
|
+
...
|
69
|
+
]
|
70
|
+
}
|
71
|
+
]
|
72
|
+
```
|
73
|
+
|
16
74
|
## Copyright
|
17
75
|
|
18
76
|
* Copyright(c) 2018- Grafana Labs
|
@@ -133,8 +133,10 @@ module Fluent
|
|
133
133
|
payload = generic_to_loki(chunk)
|
134
134
|
body = { 'streams' => payload }
|
135
135
|
|
136
|
+
tenant = extract_placeholders(@tenant, chunk) if @tenant
|
137
|
+
|
136
138
|
# add ingest path to loki url
|
137
|
-
res = loki_http_request(body)
|
139
|
+
res = loki_http_request(body, tenant)
|
138
140
|
|
139
141
|
return if res.is_a?(Net::HTTPSuccess)
|
140
142
|
|
@@ -176,18 +178,20 @@ module Fluent
|
|
176
178
|
|
177
179
|
private
|
178
180
|
|
179
|
-
def loki_http_request(body)
|
181
|
+
def loki_http_request(body, tenant)
|
180
182
|
req = Net::HTTP::Post.new(
|
181
183
|
@uri.request_uri
|
182
184
|
)
|
183
185
|
req.add_field('Content-Type', 'application/json')
|
184
|
-
req.add_field('X-Scope-OrgID',
|
186
|
+
req.add_field('X-Scope-OrgID', tenant) if tenant
|
185
187
|
req.body = Yajl.dump(body)
|
186
188
|
req.basic_auth(@username, @password) if @username
|
187
189
|
|
188
190
|
opts = ssl_opts(@uri)
|
189
191
|
|
190
|
-
|
192
|
+
msg = "sending #{req.body.length} bytes to loki"
|
193
|
+
msg += " (tenant: \"#{tenant}\")" if tenant
|
194
|
+
log.debug msg
|
191
195
|
|
192
196
|
Net::HTTP.start(@uri.host, @uri.port, **opts) { |http| http.request(req) }
|
193
197
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-grafana-loki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- woodsaj
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-
|
13
|
+
date: 2020-05-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|