logstash_writer 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/logstash_writer.rb +14 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 581706d47cefad1062b70b5abf2e6689dac1671a3edbaeaad776bb4b8af8aa21
|
4
|
+
data.tar.gz: f9c9e6939dfc94a8aad4c54ee175fc8d0f3a2b9d35a1a932ab5944df3c0267cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b019d96a15b990080f0afc0fc0f9d5dad69644d92338e07dde8eabc9dece477e88f207a8b6f78e49be6a910351826c8640b51b52475589ad5d888320ee8d0f02
|
7
|
+
data.tar.gz: f7c747495bd1823e3f62d52f88b33b60e7df0039242c874333d94462d9b3a7d9f88cc14a0a28b9857cf8a3729b02dbe93f1990c642a51b2910380ccbbad43d8f
|
data/lib/logstash_writer.rb
CHANGED
@@ -8,8 +8,8 @@ require 'prometheus/client'
|
|
8
8
|
#
|
9
9
|
# Flings events, represented as JSON objects, to logstash using the
|
10
10
|
# `json_lines` codec (over TCP). Doesn't do any munging or modification of
|
11
|
-
# the event data given to it, other than adding `@timestamp` and
|
12
|
-
# fields if they do not already exist.
|
11
|
+
# the event data given to it, other than adding `@timestamp` and
|
12
|
+
# `[@metadata][_id]` fields if they do not already exist.
|
13
13
|
#
|
14
14
|
# We support highly-available logstash installations by means of multiple
|
15
15
|
# address records, or via SRV records. See the docs for .new for details
|
@@ -104,8 +104,8 @@ class LogstashWriter
|
|
104
104
|
|
105
105
|
# Add an event to the queue, to be sent to logstash. Actual event
|
106
106
|
# delivery will happen in a worker thread that is started with
|
107
|
-
# #run. If the event does not have a `@timestamp` or `_id`
|
108
|
-
# will be added with appropriate values.
|
107
|
+
# #run. If the event does not have a `@timestamp` or `[@metadata][_id]`
|
108
|
+
# element, they will be added with appropriate values.
|
109
109
|
#
|
110
110
|
# @param e [Hash] the event data to be sent.
|
111
111
|
#
|
@@ -120,12 +120,20 @@ class LogstashWriter
|
|
120
120
|
e[:@timestamp] = Time.now.utc.strftime("%FT%T.%NZ")
|
121
121
|
end
|
122
122
|
|
123
|
-
|
123
|
+
if e.has_key?("@metadata")
|
124
|
+
e[:@metadata] = (e[:@metadata] || {}).merge(e["@metadata"])
|
125
|
+
end
|
126
|
+
|
127
|
+
unless e.has_key?(:@metadata)
|
128
|
+
e[:@metadata] = {}
|
129
|
+
end
|
130
|
+
|
131
|
+
unless e[:@metadata].has_key?(:_id) || e.has_key?("_id")
|
124
132
|
# This is the quickest way I've found to get a long, random string.
|
125
133
|
# We don't need any sort of cryptographic or unpredictability
|
126
134
|
# guarantees for what we're doing here, so SecureRandom is unnecessary
|
127
135
|
# overhead.
|
128
|
-
e[:_id] = rand(0x1000_0000_0000_0000_0000_0000_0000_0000).to_s(36)
|
136
|
+
e[:@metadata][:_id] = rand(0x1000_0000_0000_0000_0000_0000_0000_0000).to_s(36)
|
129
137
|
end
|
130
138
|
|
131
139
|
@queue_mutex.synchronize do
|