chopshop-logreader 0.2.1 → 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 +35 -14
- data/lib/chopshop/logreader/parser.rb +19 -9
- 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,26 +26,43 @@ module Chopshop
|
|
22
26
|
@parser = Chopshop::Logreader::Parser.new
|
23
27
|
end
|
24
28
|
|
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
|
38
|
+
|
25
39
|
def execute!
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
service
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
container = containers.split("\n").map {|line| line.split(" ") }.each do |line|
|
40
|
+
parse_options
|
41
|
+
service = nil
|
42
|
+
|
43
|
+
# log into the EKS cluster, may require 2FA authing here.
|
44
|
+
`rally-kubectl -a #{region} -e #{profile} -t #{tenant}`
|
45
|
+
puts "looking for valid service container"
|
46
|
+
while !service
|
47
|
+
services = `kubectl get pods --namespace #{namespace} | grep #{service_name}`
|
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
|
37
50
|
match_data = REGEX.match(line[4])
|
51
|
+
# calculate the human readable version of time into a single integer for comparison
|
38
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
|
39
54
|
end.select{|line| line[2] == options.status }.sort_by {|line| line[5] }.first
|
40
55
|
|
41
|
-
if
|
42
|
-
|
56
|
+
# if we have a pod we want logs from, then get logs and be done
|
57
|
+
if service
|
58
|
+
if container
|
59
|
+
exec "kubectl logs --follow=#{options.follow} --tail=#{options.lines} --namespace #{namespace} --container=#{container} #{service[0]}"
|
60
|
+
else
|
61
|
+
exec "kubectl logs --follow=#{options.follow} --tail=#{options.lines} --namespace #{namespace} #{service[0]}"
|
62
|
+
end
|
43
63
|
end
|
44
64
|
|
65
|
+
# no pod with logs, wait 1 second and try again.
|
45
66
|
print "."
|
46
67
|
sleep 1
|
47
68
|
end
|
@@ -8,15 +8,17 @@ module Chopshop
|
|
8
8
|
options = OpenStruct.new(
|
9
9
|
follow: true, # follow output from log file
|
10
10
|
lines: -1, # whole file always,
|
11
|
-
status: "Running", # look for a currently running
|
12
|
-
namespace:
|
11
|
+
status: "Running", # look for a currently running service
|
12
|
+
namespace: nil,
|
13
13
|
tenant: nil,
|
14
|
-
profile: nil
|
14
|
+
profile: nil,
|
15
|
+
region: nil,
|
16
|
+
container: nil
|
15
17
|
)
|
16
18
|
|
17
19
|
|
18
20
|
OptionParser.new do |opts|
|
19
|
-
opts.banner = "Usage:
|
21
|
+
opts.banner = "Usage: chopshop-logreader SERVICE [options]"
|
20
22
|
|
21
23
|
opts.on("-f [FOLLOW]", "--follow [FOLLOW]", "boolean true/false on whether to follow output from the file. default: true", TrueClass) do |follow|
|
22
24
|
options[:follow] = follow
|
@@ -26,19 +28,27 @@ module Chopshop
|
|
26
28
|
options[:lines] = lines
|
27
29
|
end
|
28
30
|
|
29
|
-
opts.on("-s [STATUS]", "--status [STATUS]", "valid values: Completed|Running|Error. will only look for
|
31
|
+
opts.on("-s [STATUS]", "--status [STATUS]", "valid values: Completed|Running|Error. will only look for services/jobs with the given status. default: Running", String) do |status|
|
30
32
|
options[:status] = status
|
31
33
|
end
|
32
34
|
|
33
|
-
opts.on("-n [NAMESPACE]", "--namespace [NAMESPACE]", "sets the kubernetes namespace to look for
|
34
|
-
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
|
35
37
|
end
|
36
38
|
|
37
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|
|
38
40
|
options[:profile] = profile
|
39
41
|
end
|
40
42
|
|
41
|
-
opts.on("-
|
43
|
+
opts.on("-r [REGION]", "--region [REGION]", "sets the cloud region to look for a tenant within. default: us-east-1. You may also provide this value via the ENV VAR 'AWS_REGION'", String) do |region|
|
44
|
+
options[:region] = region
|
45
|
+
end
|
46
|
+
|
47
|
+
opts.on("-c [CONTAINER]", "--container [CONTAINER]", "sets the kubernetes tenant to look for containers in. default: nil. Often not needed", String) do |container|
|
48
|
+
options[:container] = container
|
49
|
+
end
|
50
|
+
|
51
|
+
opts.on("-t [TENANT]", "--tenant [TENANT]", "sets the kubernetes tenant to look for the service/job in. default: nil. You must provide this value or set the ENV VAR DEFAULT_TENANT'", String) do |tenant|
|
42
52
|
options[:tenant] = tenant
|
43
53
|
end
|
44
54
|
|
@@ -54,4 +64,4 @@ module Chopshop
|
|
54
64
|
end
|
55
65
|
end
|
56
66
|
end
|
57
|
-
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
|