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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/chopshop/logreader/executor.rb +26 -11
- data/lib/chopshop/logreader/parser.rb +4 -4
- data/lib/chopshop/logreader/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed7a741e3549b4d7b48cc7a30bb099a9debda0378c2d9873cea0ba07fafcad2d
|
4
|
+
data.tar.gz: 9b8f94a7360e0319370c5391a547f2ad874833a27ff00e4325a7731e30fb908d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2a513f331481b74f60a122b318552826d08d8fca8dcb651e212ca4fbad37257378efe8f286490aae16d02428814b918ba0ee3f5f262503a2bdc6ca3462e52b7
|
7
|
+
data.tar.gz: 3fc6ad5d1c1fbe8810132e45258672728079e1ebcb5871755b7ae8432025224d75e85bc12e142fd0c015836152788bf7122e1fa4fdb64076d54e81ab8266b2a6
|
data/Gemfile.lock
CHANGED
@@ -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
|
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
|
-
|
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
|
-
|
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 #{
|
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
|
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
|
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:
|
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 |
|
36
|
-
options[:
|
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
|
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.
|
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:
|
11
|
+
date: 2022-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|