logstash-filter-kafka_time_machine 3.0.0 → 3.0.2.pre

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f8ebc093ec36312aa92be6f7b158cd840021cad43bc1cacda8a8e9b816c9f2cf
4
- data.tar.gz: 821bbb0f5b29ba23c4e650366da3eeb0ebaa94b6f55eb49f33d2b05c13571fbb
3
+ metadata.gz: f0493db2db2981e58eb360408a6ca29529f267e3b2f3206275329bc8c05ac473
4
+ data.tar.gz: 02266346ba816a9fef2b12f4aba8bc283847fa7f55ebbaae507ca107798458f8
5
5
  SHA512:
6
- metadata.gz: 8c341477b352621f6eb708b63637b1caa1f39aeb9c9e2e399ec2d28c8c8aeb96e813cdbaa0f2f409811f75bb42fdc03cf741ac9acd22c861ff1727f49f523c78
7
- data.tar.gz: bca9c8ef6a474f761403e298ad9e494316a50b109e3aa666e85390db556dc749b732eee30a4399a430c4d81854fe1561b8c13f47fe97c0eabd44bac38e1a0776
6
+ metadata.gz: bea392a66af7f726c13d953ca1f03bfaebfe0782c5df11944cb8b8db845650f5619e0f1d8dab31e22de50372929dd1c68288678bcf5d91931688593887249bec
7
+ data.tar.gz: 48ba960f4285a64b5c5f81be76e0380c39581e9adcdfa62c46062e7b77ff6b4d422524a4cafeeebae43d5c17511ef665d84e3a842a6e0919c4ad031a1ec94624
@@ -38,6 +38,9 @@ class LogStash::Filters::KafkaTimeMachine < LogStash::Filters::Base
38
38
  # Owner of the event currenty being process.
39
39
  config :event_owner, :validate => :string, :required => true
40
40
 
41
+ # tag of the event currenty being process.
42
+ config :event_tag, :validate => :string, :required => true
43
+
41
44
  # Current time since EPOCH in ms that should be set in the generated metric
42
45
  config :event_time_ms, :validate => :string, :required => true
43
46
 
@@ -49,7 +52,7 @@ class LogStash::Filters::KafkaTimeMachine < LogStash::Filters::Base
49
52
 
50
53
  public
51
54
  def register
52
-
55
+
53
56
  end
54
57
 
55
58
  public
@@ -57,7 +60,7 @@ class LogStash::Filters::KafkaTimeMachine < LogStash::Filters::Base
57
60
 
58
61
  @logger.debug("Starting filter calculations")
59
62
 
60
- # Note - It was considered to error check for strings that are invalid, i.e. "%{[@metadata][ktm][kafka_datacenter_shipper]}". However, this string being present is a good way to identify
63
+ # Note - It was considered to error check for strings that are invalid, i.e. "%{[@metadata][ktm][kafka_datacenter_shipper]}". However, this string being present is a good way to identify
61
64
  # shipper/indexer logstash configs that are wrong so its allowed to pass through unaltered.
62
65
  #
63
66
  # Extract all string values to local variables.
@@ -78,9 +81,12 @@ class LogStash::Filters::KafkaTimeMachine < LogStash::Filters::Base
78
81
  shipper_logstash_kafka_read_time = get_numeric(event.sprintf(@logstash_kafka_read_time_shipper))
79
82
  indexer_kafka_append_time = get_numeric(event.sprintf(@kafka_append_time_indexer))
80
83
  indexer_logstash_kafka_read_time = get_numeric(event.sprintf(@logstash_kafka_read_time_indexer))
81
-
84
+
85
+ # Extract tags
86
+ event_tag = event.sprintf(@event_tag)
87
+
82
88
  # Validate the shipper data
83
- shipper_kafka_array = Array[shipper_kafka_datacenter, shipper_kafka_topic, shipper_kafka_consumer_group, shipper_kafka_append_time, shipper_logstash_kafka_read_time, event_owner, event_time_ms, elasticsearch_cluster, elasticsearch_cluster_index]
89
+ shipper_kafka_array = Array[shipper_kafka_datacenter, shipper_kafka_topic, shipper_kafka_consumer_group, shipper_kafka_append_time, shipper_logstash_kafka_read_time, event_owner, event_tag, event_time_ms, elasticsearch_cluster, elasticsearch_cluster_index]
84
90
  if (shipper_kafka_array.any? { |text| text.nil? || text.to_s.empty? })
85
91
  @logger.debug("shipper_kafka_array invalid: Found null")
86
92
  error_string_shipper = sprintf("Error in shipper data: %s", shipper_kafka_array)
@@ -95,7 +101,7 @@ class LogStash::Filters::KafkaTimeMachine < LogStash::Filters::Base
95
101
  end
96
102
 
97
103
  # Validate the indexer data
98
- indexer_kafka_array = Array[shipper_kafka_datacenter, indexer_kafka_topic, indexer_kafka_consumer_group, indexer_kafka_append_time, indexer_logstash_kafka_read_time, event_owner, event_time_ms, elasticsearch_cluster, elasticsearch_cluster_index]
104
+ indexer_kafka_array = Array[shipper_kafka_datacenter, indexer_kafka_topic, indexer_kafka_consumer_group, indexer_kafka_append_time, indexer_logstash_kafka_read_time, event_owner, event_tag, event_time_ms, elasticsearch_cluster, elasticsearch_cluster_index]
99
105
  if (indexer_kafka_array.any? { |text| text.nil? || text.to_s.empty? })
100
106
  @logger.debug("indexer_kafka_array invalid: Found null")
101
107
  error_string_indexer = sprintf("Error in indexer data: %s", indexer_kafka_array)
@@ -109,10 +115,18 @@ class LogStash::Filters::KafkaTimeMachine < LogStash::Filters::Base
109
115
  indexer_kafka_lag_ms = indexer_logstash_kafka_read_time - indexer_kafka_append_time
110
116
  end
111
117
 
112
- # Add in the size of the payload field
113
- payload_size_bytes = 0
118
+ # Add in the size of the payload field if it exist
114
119
  if event.get("[payload]")
115
- payload_size_bytes = event.get("[payload]").bytesize
120
+ # pipeline gets random poison pill that crashes KTM with error: "error=>"(NoMethodError) undefined method `bytesize' for #Hash:0x38fe76d4", :exception=>Java::OrgJrubyExceptions::NoMethodError"
121
+ # This should prevent the crash and log the error
122
+ begin
123
+ payload_size_bytes = event.get("[payload]").bytesize
124
+ rescue NoMethodError => e
125
+ payload_size_bytes = 0
126
+ @logger.fatal("payload bytesize operation failed: #{e.message}")
127
+ end
128
+ else
129
+ payload_size_bytes = 0
116
130
  end
117
131
 
118
132
  # Set time (nanoseconds) for event that is generated
@@ -128,34 +142,34 @@ class LogStash::Filters::KafkaTimeMachine < LogStash::Filters::Base
128
142
  if (shipper_valid == true && indexer_valid == true && epoch_time_ns != nil)
129
143
  total_kafka_lag_ms = indexer_logstash_kafka_read_time - shipper_kafka_append_time
130
144
 
131
- point_ktm = create_point_ktm(shipper_kafka_datacenter, event_owner, payload_size_bytes, "total", total_kafka_lag_ms, epoch_time_ns, elasticsearch_cluster, elasticsearch_cluster_index)
145
+ point_ktm = create_point_ktm(shipper_kafka_datacenter, event_owner, event_tag, payload_size_bytes, "total", total_kafka_lag_ms, epoch_time_ns, elasticsearch_cluster, elasticsearch_cluster_index)
132
146
  ktm_metric_event_array.push point_ktm
133
147
 
134
148
  elsif (shipper_valid == true && indexer_valid == false && epoch_time_ns != nil)
135
- point_ktm = create_point_ktm(shipper_kafka_datacenter, event_owner, payload_size_bytes, "shipper", shipper_kafka_lag_ms, epoch_time_ns, elasticsearch_cluster, elasticsearch_cluster_index)
149
+ point_ktm = create_point_ktm(shipper_kafka_datacenter, event_owner, event_tag, payload_size_bytes, "shipper", shipper_kafka_lag_ms, epoch_time_ns, elasticsearch_cluster, elasticsearch_cluster_index)
136
150
  ktm_metric_event_array.push point_ktm
137
151
 
138
- point_ktm = create_point_ktm_error(shipper_kafka_datacenter, event_owner, epoch_time_ns, "indexer", elasticsearch_cluster, elasticsearch_cluster_index)
152
+ point_ktm = create_point_ktm_error(shipper_kafka_datacenter, event_owner, event_tag, epoch_time_ns, "indexer", elasticsearch_cluster, elasticsearch_cluster_index)
139
153
  ktm_metric_event_array.push point_ktm
140
154
 
141
155
  elsif (indexer_valid == true && shipper_valid == false && epoch_time_ns != nil)
142
- point_ktm = create_point_ktm(shipper_kafka_datacenter, event_owner, payload_size_bytes, "indexer", indexer_kafka_lag_ms, epoch_time_ns, elasticsearch_cluster, elasticsearch_cluster_index)
156
+ point_ktm = create_point_ktm(shipper_kafka_datacenter, event_owner, event_tag, payload_size_bytes, "indexer", indexer_kafka_lag_ms, epoch_time_ns, elasticsearch_cluster, elasticsearch_cluster_index)
143
157
  ktm_metric_event_array.push point_ktm
144
158
 
145
- point_ktm = create_point_ktm_error(shipper_kafka_datacenter, event_owner, epoch_time_ns, "shipper", elasticsearch_cluster, elasticsearch_cluster_index)
159
+ point_ktm = create_point_ktm_error(shipper_kafka_datacenter, event_owner, event_tag, epoch_time_ns, "shipper", elasticsearch_cluster, elasticsearch_cluster_index)
146
160
  ktm_metric_event_array.push point_ktm
147
161
 
148
162
  elsif (indexer_valid == false && shipper_valid == false)
149
163
 
150
- point_ktm = create_point_ktm_error(shipper_kafka_datacenter, event_owner, epoch_time_ns, "insufficient_data", elasticsearch_cluster, elasticsearch_cluster_index)
164
+ point_ktm = create_point_ktm_error(shipper_kafka_datacenter, event_owner, event_tag, epoch_time_ns, "insufficient_data", elasticsearch_cluster, elasticsearch_cluster_index)
151
165
  ktm_metric_event_array.push point_ktm
152
166
 
153
167
  error_string = sprintf("Error kafka_time_machine: Could not build valid response --> %s, %s", error_string_shipper, error_string_indexer)
154
168
  @logger.debug(error_string)
155
-
169
+
156
170
  else
157
171
 
158
- point_ktm = create_point_ktm_error(shipper_kafka_datacenter, event_owner, epoch_time_ns, "unknown", elasticsearch_cluster, elasticsearch_cluster_index)
172
+ point_ktm = create_point_ktm_error(shipper_kafka_datacenter, event_owner, event_tag, epoch_time_ns, "unknown", elasticsearch_cluster, elasticsearch_cluster_index)
159
173
  ktm_metric_event_array.push point_ktm
160
174
 
161
175
  error_string = "Unknown error encountered"
@@ -165,22 +179,22 @@ class LogStash::Filters::KafkaTimeMachine < LogStash::Filters::Base
165
179
 
166
180
  # Publish even event in our array
167
181
  ktm_metric_event_array.each do |metric_event|
168
-
182
+
169
183
  # Create new event for KTM metric
170
184
  event_ktm = LogStash::Event.new(metric_event)
171
185
  event_ktm.set("[@metadata][ktm_tags][ktm_metric]", "true")
172
186
 
173
187
  filter_matched(event_ktm)
174
188
  yield event_ktm
175
-
189
+
176
190
  end
177
191
 
178
192
  end # def filter
179
193
 
180
194
  # Creates hash with ktm data point to return
181
195
  public
182
- def create_point_ktm(datacenter, event_owner, payload_size_bytes, lag_type, lag_ms, epoch_time_ns, elasticsearch_cluster, elasticsearch_cluster_index)
183
-
196
+ def create_point_ktm(datacenter, event_owner, event_tag, payload_size_bytes, lag_type, lag_ms, epoch_time_ns, elasticsearch_cluster, elasticsearch_cluster_index)
197
+
184
198
  point = Hash.new
185
199
 
186
200
  # Name of point and time created
@@ -190,6 +204,7 @@ class LogStash::Filters::KafkaTimeMachine < LogStash::Filters::Base
190
204
  # tags
191
205
  point["datacenter"] = datacenter
192
206
  point["owner"] = event_owner
207
+ point["tag"] = event_tag
193
208
  point["lag_type"] = lag_type
194
209
  point["es_cluster"] = elasticsearch_cluster
195
210
  point["es_cluster_index"] = elasticsearch_cluster_index
@@ -204,7 +219,7 @@ class LogStash::Filters::KafkaTimeMachine < LogStash::Filters::Base
204
219
 
205
220
  # Creates hash with ktm data point to return
206
221
  public
207
- def create_point_ktm_error(datacenter, event_owner, epoch_time_ns, type, elasticsearch_cluster, elasticsearch_cluster_index)
222
+ def create_point_ktm_error(datacenter, event_owner, event_tag, epoch_time_ns, type, elasticsearch_cluster, elasticsearch_cluster_index)
208
223
 
209
224
  # Check for nil values
210
225
  if (nil == datacenter)
@@ -215,6 +230,10 @@ class LogStash::Filters::KafkaTimeMachine < LogStash::Filters::Base
215
230
  event_owner = "unknown"
216
231
  end
217
232
 
233
+ if (nil == event_tag)
234
+ event_tag = "unknown"
235
+ end
236
+
218
237
  # set time if we didn't recieve it
219
238
  if (nil == epoch_time_ns)
220
239
  epoch_time_ns = ((Time.now.to_f * 1000).to_i)*1000000
@@ -225,33 +244,34 @@ class LogStash::Filters::KafkaTimeMachine < LogStash::Filters::Base
225
244
  # Name of point and time created
226
245
  point["name"] = "ktm_error"
227
246
  point["epoch_time_ns"] = epoch_time_ns
228
-
247
+
229
248
  # tags
230
249
  point["datacenter"] = datacenter
231
250
  point["owner"] = event_owner
251
+ point["tag"] = event_tag
232
252
  point["source"] = type
233
253
  point["es_cluster"] = elasticsearch_cluster
234
254
  point["es_cluster_index"] = elasticsearch_cluster_index
235
-
255
+
236
256
  # fields
237
257
  point["count"] = 1
238
-
258
+
239
259
  return point
240
260
 
241
261
  end # def create_point_ktm_error
242
262
 
243
263
  # Ensures the provided value is numeric; if not returns 'nil'
244
264
  public
245
- def get_numeric(input_str)
265
+ def get_numeric(input_str)
246
266
 
247
267
  # @logger.debug("Aggregate timeout for '#{@task_id}' pattern: #{@timeout} seconds")
248
268
  @logger.debug("get_numeric operating on: #{input_str} ")
249
-
269
+
250
270
  is_numeric = input_str.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
251
271
  if (true == is_numeric)
252
272
  @logger.debug("get_numeric - valid value provided")
253
273
  num_value = Float(sprintf(input_str))
254
-
274
+
255
275
  if (false == num_value.positive?)
256
276
  @logger.debug("get_numeric - negative value provided")
257
277
  num_value = nil
@@ -268,4 +288,4 @@ class LogStash::Filters::KafkaTimeMachine < LogStash::Filters::Base
268
288
 
269
289
  end # def get_numberic
270
290
 
271
- end # class LogStash::Filters::KafkaTimeMachine
291
+ end # class LogStash::Filters::KafkaTimeMachine
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-filter-kafka_time_machine'
3
- s.version = '3.0.0'
3
+ s.version = '3.0.2.pre'
4
4
  s.licenses = ['Apache-2.0']
5
5
  s.summary = "Calculate total time of logstash event that traversed 2 Kafka queues from a shipper site to an indexer site"
6
6
  s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
 
12
12
  # Files
13
13
  s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
14
-
14
+
15
15
  # Tests
16
16
  s.test_files = s.files.grep(%r{^(test|spec|features)/})
17
17
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-kafka_time_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.2.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Foster
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-10 00:00:00.000000000 Z
11
+ date: 2025-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstash-core-plugin-api
@@ -73,9 +73,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
73
  version: '0'
74
74
  required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  requirements:
76
- - - ">="
76
+ - - ">"
77
77
  - !ruby/object:Gem::Version
78
- version: '0'
78
+ version: 1.3.1
79
79
  requirements: []
80
80
  rubygems_version: 3.0.3.1
81
81
  signing_key: