chopshop-logreader 0.2.3 → 0.2.4

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: aa1d6a0266d4f7ee6fe20dd3a0d0e5042e1f587f5d276ba11a514b811742ff1c
4
- data.tar.gz: d90185bece540bbce81b47e31a8346ad976f17ed54688d0234c26a3f277c62bf
3
+ metadata.gz: ed7a741e3549b4d7b48cc7a30bb099a9debda0378c2d9873cea0ba07fafcad2d
4
+ data.tar.gz: 9b8f94a7360e0319370c5391a547f2ad874833a27ff00e4325a7731e30fb908d
5
5
  SHA512:
6
- metadata.gz: 3bd32954bfc925ff2194b51ea5704764152b248134a5e228b30973d5f7c2991fb8cccf540db357193fe76508a2ba03cb54dc271223cf1a4946ed2fc035614045
7
- data.tar.gz: a993a805d2f281005b75b64cbc94deae2fc1401ec19d29a5f08370e6f426cc28c13664349050c21703b6394afefd34d21a286b33b2939537afd5ca01bdc6bf36
6
+ metadata.gz: e2a513f331481b74f60a122b318552826d08d8fca8dcb651e212ca4fbad37257378efe8f286490aae16d02428814b918ba0ee3f5f262503a2bdc6ca3462e52b7
7
+ data.tar.gz: 3fc6ad5d1c1fbe8810132e45258672728079e1ebcb5871755b7ae8432025224d75e85bc12e142fd0c015836152788bf7122e1fa4fdb64076d54e81ab8266b2a6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chopshop-logreader (0.2.3)
4
+ chopshop-logreader (0.2.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -3,8 +3,12 @@ require "chopshop/logreader/parser"
3
3
  module Chopshop
4
4
  module Logreader
5
5
  class Executor
6
- attr_reader :parser
6
+ attr_reader :parser, :options, :profile, :tenant,
7
+ :region, :namespace, :container, :service_name
7
8
 
9
+ # The regex + time calculator takes the human readable output from the kubernetes CLI
10
+ # and calculates how long any given pod has been running. It then selects the most
11
+ # recently pod/shortest living pod
8
12
  REGEX = /(?<t1>\d+)(?<v1>[a-z]+)(?<t2>\d*)(?<v2>[a-z]*)/i
9
13
  TIME_CALCULATOR = {
10
14
  "s" => 1,
@@ -22,32 +26,43 @@ module Chopshop
22
26
  @parser = Chopshop::Logreader::Parser.new
23
27
  end
24
28
 
25
- def execute!
26
- options = @parser.parse
27
- profile = options.profile || ENV["AWS_PROFILE"] || ENV["PROFILE"]
28
- tenant = options.tenant || ENV["DEFAULT_TENANT"]
29
- region = options.region || ENV["AWS_REGION"] || "us-east-1"
30
- container = options.container
29
+ def parse_options
30
+ @options = @parser.parse
31
+ @profile = options.profile || ENV["AWS_PROFILE"] || ENV["PROFILE"]
32
+ @tenant = options.tenant || ENV["DEFAULT_TENANT"]
33
+ @region = options.region || ENV["AWS_REGION"] || "us-east-1"
34
+ @namespace = options.namespace || ENV["K8_NAMESPACE"] || "connect"
35
+ @container = options.container
36
+ @service_name = ARGV[0]
37
+ end
31
38
 
39
+ def execute!
40
+ parse_options
32
41
  service = nil
33
- service_name = ARGV[0]
42
+
43
+ # log into the EKS cluster, may require 2FA authing here.
34
44
  `rally-kubectl -a #{region} -e #{profile} -t #{tenant}`
35
45
  puts "looking for valid service container"
36
46
  while !service
37
- services = `kubectl get pods --namespace #{options.namespace} | grep #{service_name}`
47
+ services = `kubectl get pods --namespace #{namespace} | grep #{service_name}`
38
48
  service = services.split("\n").map {|line| line.split(" ") }.each do |line|
49
+ # get the length of time the pod has been running from the kubernetes CLI output
39
50
  match_data = REGEX.match(line[4])
51
+ # calculate the human readable version of time into a single integer for comparison
40
52
  line[5] = TIME_CALCULATOR[match_data.captures[1].downcase] * match_data.captures[0].to_i + TIME_CALCULATOR[match_data.captures[3].downcase] * match_data.captures[2].to_i
53
+ # select the most recent/shortest living pod
41
54
  end.select{|line| line[2] == options.status }.sort_by {|line| line[5] }.first
42
55
 
56
+ # if we have a pod we want logs from, then get logs and be done
43
57
  if service
44
58
  if container
45
- exec "kubectl logs --follow=#{options.follow} --tail=#{options.lines} --namespace connect --container=#{container} #{service[0]}"
59
+ exec "kubectl logs --follow=#{options.follow} --tail=#{options.lines} --namespace #{namespace} --container=#{container} #{service[0]}"
46
60
  else
47
- exec "kubectl logs --follow=#{options.follow} --tail=#{options.lines} --namespace connect #{service[0]}"
61
+ exec "kubectl logs --follow=#{options.follow} --tail=#{options.lines} --namespace #{namespace} #{service[0]}"
48
62
  end
49
63
  end
50
64
 
65
+ # no pod with logs, wait 1 second and try again.
51
66
  print "."
52
67
  sleep 1
53
68
  end
@@ -9,7 +9,7 @@ module Chopshop
9
9
  follow: true, # follow output from log file
10
10
  lines: -1, # whole file always,
11
11
  status: "Running", # look for a currently running service
12
- namespace: "connect",
12
+ namespace: nil,
13
13
  tenant: nil,
14
14
  profile: nil,
15
15
  region: nil,
@@ -32,8 +32,8 @@ module Chopshop
32
32
  options[:status] = status
33
33
  end
34
34
 
35
- opts.on("-n [NAMESPACE]", "--namespace [NAMESPACE]", "sets the kubernetes namespace to look for service/job in. default: connect", String) do |status|
36
- options[:status] = status
35
+ opts.on("-n [NAMESPACE]", "--namespace [NAMESPACE]", "sets the kubernetes namespace to look for service/job in. default: connect", String) do |namespace|
36
+ options[:namespace] = namespace
37
37
  end
38
38
 
39
39
  opts.on("-p [PROFILE]", "--profile [PROFILE]", "chooses the cloud profile to use for permissions. default: nil. You must provide this value or set the ENV VAR AWS_PROFILE' or the ENV VAR 'PROFILE'", String) do |profile|
@@ -64,4 +64,4 @@ module Chopshop
64
64
  end
65
65
  end
66
66
  end
67
- end
67
+ end
@@ -1,5 +1,5 @@
1
1
  module Chopshop
2
2
  module Logreader
3
- VERSION = "0.2.3"
3
+ VERSION = "0.2.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chopshop-logreader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Perdue
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-13 00:00:00.000000000 Z
11
+ date: 2022-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler