logstash_writer 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/logstash_writer.rb +14 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b3f279724a1874b171c9080fb4aae626e844c13b845bec88a50ae832b660a85
4
- data.tar.gz: cb3463bfddf9673808fb874cc1bca6b1b51527f2eb626134bada7cacff91b856
3
+ metadata.gz: 581706d47cefad1062b70b5abf2e6689dac1671a3edbaeaad776bb4b8af8aa21
4
+ data.tar.gz: f9c9e6939dfc94a8aad4c54ee175fc8d0f3a2b9d35a1a932ab5944df3c0267cc
5
5
  SHA512:
6
- metadata.gz: 41611118bbcc2992196a8c2dc49bec74ce00dc3ec0505b9682132c9e6bcf6e7a8dd48355f35f06cd393f8e2c41460a24b28c53b0c0b0f5ee48c8ec6ec9964503
7
- data.tar.gz: 5527ef9d6bf2a9ed3de0c3483bf43ed6ffd5e69a4e7b8687bdb9d33d258651bdae95a9b990617007578fb10003533840b6f397d87fa2e955836704f9eb064955
6
+ metadata.gz: b019d96a15b990080f0afc0fc0f9d5dad69644d92338e07dde8eabc9dece477e88f207a8b6f78e49be6a910351826c8640b51b52475589ad5d888320ee8d0f02
7
+ data.tar.gz: f7c747495bd1823e3f62d52f88b33b60e7df0039242c874333d94462d9b3a7d9f88cc14a0a28b9857cf8a3729b02dbe93f1990c642a51b2910380ccbbad43d8f
@@ -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 `_id`
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` element, they
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
- unless e.has_key?(:_id) || e.has_key?("_id")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash_writer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Palmer