greenhat 0.9.1 → 0.10.0

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: 0107064d86f7742b834d46b40d19cf8de0a8ec0d37445c0a514d778b7faef7dd
4
- data.tar.gz: 9a980031e5c392d1801901a67433a8999d6ed72ed468d0f444a4d37a794f6cf0
3
+ metadata.gz: 43ceab157825b4db4eb440dcf05d5d47a5c785a02fa9b0e80df8650305368ca7
4
+ data.tar.gz: 5ec5d03c007f0c9ab3aa5d8148efdab7587bc44dba8c92aa795a54b21641a81c
5
5
  SHA512:
6
- metadata.gz: 260b3a5f31f732c33a20812be19264108d3691f44329d44665bbb7d032256cd58c3616177c098eefc8f7abdf402fc10b88e513ab56a9e59acc22539cab6d4437
7
- data.tar.gz: e6dd3c2ddcaef6d3644fbd14425cda9caa0a3281a2949fdde185a9b3e37c07db5bad977346e3b01112cd653f77462efae81ff2fba7a615d87bf7b149d3ceb97d
6
+ metadata.gz: 36e4e8602238a35dab943159a716120f8e4d5504c39ac6350321478878ebaed325bbbe1e5dd70583cc0fe3e13abea2f8c91812b84db3958aa0db2275137914d0
7
+ data.tar.gz: 277506e7a15ccbfaf6fdbce7e470398a943ee9d1a9acb7acc2b8c3c5a3bab6cd2956ba84eee1d80d2c86f3948380a05521dbf5bcb62db68e83e3d598022573db
@@ -153,6 +153,7 @@ module GreenHat
153
153
 
154
154
  puts ' --command, -c'.pastel(:green)
155
155
  puts ' Run and then exit a GreenHat Shell command'
156
+ puts ' Ex. greenhat --command="reports production_log_duration" production_json.log'
156
157
  puts
157
158
 
158
159
  puts ' --web, -w'.pastel(:green)
@@ -8,7 +8,8 @@ module GreenHat
8
8
  @settings ||= {
9
9
  assume_json: true,
10
10
  fuzzy_file_match: true,
11
- assume_raw: false,
11
+ # TODO: Confirm good idea to have this raw by default
12
+ assume_raw: true,
12
13
  truncate: TTY::Screen.width * 4, # Dynamic Setting
13
14
  color: true
14
15
  }
@@ -79,7 +79,7 @@ module GreenHat
79
79
  # Arguments that Accept multiple options / Comma Delimted
80
80
  def self.arg_special_split
81
81
  %i[
82
- slice except uniq pluck sort archive stats exists transform
82
+ slice except uniq pluck sort archive stats exists transform filter_keys
83
83
  ]
84
84
  end
85
85
 
@@ -87,7 +87,7 @@ module GreenHat
87
87
  def self.arg_to_flag_list
88
88
  %i[
89
89
  archive end except exists json limit pluck reverse round slice sort start total
90
- stats truncate uniq page time_zone table_style percentile interval percentile transform
90
+ stats truncate uniq page time_zone table_style percentile interval percentile transform filter_keys
91
91
  ]
92
92
  end
93
93
 
@@ -19,7 +19,7 @@ module GreenHat
19
19
  puts ' Do not use less/paging'
20
20
  puts ' --search'.pastel(:green)
21
21
  puts ' Case-insensitive search of controller/method/worker field'
22
- puts ' --sort'.pastel(:green)
22
+ puts ' --sort-by'.pastel(:green)
23
23
  puts ' count,fail,max,median,min,p95,p99,rps,score'
24
24
  puts ' --limit'.pastel(:green)
25
25
  puts ' The number of rows to print'
@@ -52,7 +52,7 @@ module GreenHat
52
52
  puts ' Default'.pastel(:bright_white)
53
53
  puts ' gitaly/current'
54
54
  puts ' --raw gitlab-rails/production_json.log'
55
- puts ' gitlab-rails/api_json.log --sort=count'
55
+ puts ' gitlab-rails/api_json.log --sort-by=count'
56
56
  puts ' --search=pipeline sidekiq/current'
57
57
  puts
58
58
 
@@ -77,6 +77,25 @@ module GreenHat
77
77
  ' Ex: --slice=path or --slice=path,params'
78
78
  ],
79
79
 
80
+ filter_keys: [
81
+ '--filter_keys'.pastel(:green),
82
+ ' Does a key filter partial match on keys',
83
+ ' Useful when looking at production logs and wanting to slice specific key patterns',
84
+ ' Ex: --filter_keys=db_ --filter_keys=meta'
85
+ ],
86
+
87
+ duration_only: [
88
+ '--duration_only'.pastel(:green),
89
+ ' Keys/grep for duration keys only',
90
+ ' Useful when looking at production logs and wanting to only see durations'
91
+ ],
92
+
93
+ time_ms_only: [
94
+ '--time_ms_only'.pastel(:green),
95
+ ' Keys/grep for time_ms keys only',
96
+ ' Useful when looking at gitaly logs and wanting to only see durations'
97
+ ],
98
+
80
99
  except: [
81
100
  '--except'.pastel(:green),
82
101
  ' Exclude specific fields (except multiple with comma)',
@@ -199,6 +199,15 @@ module GreenHat
199
199
  results.reverse!
200
200
  end
201
201
 
202
+ # Show Duration Entries Only
203
+ results = filter_duration_only(results) if flags.key?(:duration_only)
204
+
205
+ # Show Duration Entries Only
206
+ results = filter_time_ms_only(results) if flags.key?(:time_ms_only)
207
+
208
+ # Filter Keys
209
+ results = filter_keys(results, flags[:filter_keys]) if flags.key?(:filter_keys)
210
+
202
211
  # JSON Formatting
203
212
  results = results.map { |x| Oj.dump(x) } if flags.key?(:json)
204
213
 
@@ -330,6 +339,37 @@ module GreenHat
330
339
  results.compact.map { |row| row.slice(*slice) }
331
340
  end
332
341
 
342
+ # Helper to show only duration entries
343
+ # Grep might be too slow? Its doing it per row too...
344
+ def self.filter_duration_only(results)
345
+ results.compact.map do |row|
346
+ slice = row.keys.grep(/duration/)
347
+ row.slice(*slice)
348
+ end
349
+ end
350
+
351
+ # Helper to show only duration entries
352
+ # Grep might be too slow? Its doing it per row too...
353
+ def self.filter_time_ms_only(results)
354
+ results.compact.map do |row|
355
+ slice = row.keys.grep(/time_ms/)
356
+ row.slice(*slice)
357
+ end
358
+ end
359
+
360
+ # Filter Keys. This may need optimization for larger data sets
361
+ def self.filter_keys(results, filter_keys)
362
+ filter_keys = [filter_keys] unless filter_keys.is_a? Array
363
+ filter_keys = filter_keys.map(&:to_s)
364
+
365
+ results.compact.map do |row|
366
+ slice = row.keys.select do |k|
367
+ filter_keys.any? { |x| k.to_s.include? x }
368
+ end
369
+ row.slice(*slice)
370
+ end
371
+ end
372
+
333
373
  def self.filter_pluck(results, pluck)
334
374
  # Avoid Empty Results
335
375
  if pluck.empty?
@@ -510,6 +550,9 @@ module GreenHat
510
550
  # Cast to String/Integer Helper
511
551
  entry, value = filter_entry_cast(entry, arg, flags)
512
552
 
553
+ # Safety on bad query format
554
+ return false if value.blank?
555
+
513
556
  entry.send(arg.logic, value)
514
557
  end
515
558
 
@@ -518,8 +561,8 @@ module GreenHat
518
561
  # Cast to String
519
562
  value = arg.value.to_s
520
563
 
521
- # No Logic on Empty Entries
522
- return [entry, value] if entry.empty?
564
+ # No Logic on Empty Entries || Blank better than empty?
565
+ return [entry, value] if entry.blank?
523
566
 
524
567
  case arg.logic
525
568
  when :include?
@@ -1,3 +1,3 @@
1
1
  module GreenHat
2
- VERSION = '0.9.1'.freeze
2
+ VERSION = '0.10.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: greenhat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davin Walker
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-22 00:00:00.000000000 Z
10
+ date: 2025-11-19 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: actionview