logstash_writer 0.0.8 → 0.0.9
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/README.md +1 -1
- data/lib/logstash_writer.rb +5 -21
- 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: 0aee91f724739c7f2a3c573dc323048217ca5bcda61728bad1e0daa01b5b6928
|
4
|
+
data.tar.gz: 0e17940054d609ff3097b61b257d1488263c4eb1f13e6e5e3b14b00a9c561369
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7af085a2d487f1c21dedad9f7d897b219ae94047e5e38ce124a7a415f6a99e300220db21cb7ef3eaad3ad6cf474d68418b473bebe5d157b884acabebcf9e1ee0
|
7
|
+
data.tar.gz: 2c0fde510617bb7785deec8c7f16f7a21be006f9c2c087f07d50ae3e1d0ec278b285fdca288c97fc736a862d9e6438394fce45ecbd60113ccce025583750a993
|
data/README.md
CHANGED
@@ -186,7 +186,7 @@ conduct](CODE_OF_CONDUCT.md).
|
|
186
186
|
Unless otherwise stated, everything in this repo is covered by the following
|
187
187
|
copyright notice:
|
188
188
|
|
189
|
-
Copyright (C)
|
189
|
+
Copyright (C) 2016,2017,2018 Civilized Discourse Construction Kit, Inc.
|
190
190
|
|
191
191
|
This program is free software: you can redistribute it and/or modify it
|
192
192
|
under the terms of the GNU General Public License version 3, as
|
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`
|
12
|
-
#
|
11
|
+
# the event data given to it, other than adding a `@timestamp` field if
|
12
|
+
# it doesn't 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`
|
108
|
-
#
|
107
|
+
# #run. If the event does not have a `@timestamp` field, it will
|
108
|
+
# be added set to the current time.
|
109
109
|
#
|
110
110
|
# @param e [Hash] the event data to be sent.
|
111
111
|
#
|
@@ -120,22 +120,6 @@ class LogstashWriter
|
|
120
120
|
e[:@timestamp] = Time.now.utc.strftime("%FT%T.%NZ")
|
121
121
|
end
|
122
122
|
|
123
|
-
if e.has_key?("@metadata")
|
124
|
-
e[:@metadata] = (e[:@metadata] || {}).merge(e.delete("@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")
|
132
|
-
# This is the quickest way I've found to get a long, random string.
|
133
|
-
# We don't need any sort of cryptographic or unpredictability
|
134
|
-
# guarantees for what we're doing here, so SecureRandom is unnecessary
|
135
|
-
# overhead.
|
136
|
-
e[:@metadata][:_id] = rand(0x1000_0000_0000_0000_0000_0000_0000_0000).to_s(36)
|
137
|
-
end
|
138
|
-
|
139
123
|
@queue_mutex.synchronize do
|
140
124
|
@queue << { content: e, arrival_timestamp: Time.now }
|
141
125
|
while @queue.length > @backlog
|
@@ -303,7 +287,7 @@ class LogstashWriter
|
|
303
287
|
# server and recycle
|
304
288
|
@metrics[:write_exception].increment(server: @current_target.describe_peer, class: ex.class.to_s)
|
305
289
|
@metrics[:connected].set({ server: @current_target.describe_peer }, 0)
|
306
|
-
@logger.
|
290
|
+
@logger.error("LogstashWriter") { "Error while writing to current server #{@current_target.describe_peer}: #{ex.message} (#{ex.class})" }
|
307
291
|
@current_target.close
|
308
292
|
@current_target = nil
|
309
293
|
|