chopshop-logreader 0.1.1 → 0.2.2
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 +3 -3
- data/README.md +60 -7
- data/bin/chopshop-logreader +6 -0
- data/chopshop-logreader.gemspec +1 -1
- data/lib/chopshop/logreader/executor.rb +7 -4
- data/lib/chopshop/logreader/parser.rb +19 -3
- data/lib/chopshop/logreader/version.rb +1 -1
- data/lib/chopshop/logreader.rb +0 -1
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4643ced8d7e2c59fbf952f664830b153535e759faec0808a0929fa468e6a527
|
4
|
+
data.tar.gz: b3297dd87e662429b8a7fb8eb8319572d58bddc08dedb8bfc182732b1816bb64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6914d2d72ed31d866a8db404d3593e5a8440f4982df84b88a8d012828b2b08d74987337b1f31a97153facff046a6bb3cee4d58af9822bc145556628ca983c127
|
7
|
+
data.tar.gz: 29f0107c67bc1360c89c5f60ea56919b99daa5bc71b1269a694a11b37d74cb2d5be28bef2304251d6776ab8aee6387e150c0b16fd74c19ff1a6491d8258cade6
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
chopshop-logreader (0.
|
4
|
+
chopshop-logreader (0.2.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -13,10 +13,10 @@ PLATFORMS
|
|
13
13
|
ruby
|
14
14
|
|
15
15
|
DEPENDENCIES
|
16
|
-
bundler (~>
|
16
|
+
bundler (~> 2.2)
|
17
17
|
chopshop-logreader!
|
18
18
|
minitest (~> 5.0)
|
19
19
|
rake (~> 10.0)
|
20
20
|
|
21
21
|
BUNDLED WITH
|
22
|
-
|
22
|
+
2.2.33
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Chopshop::Logreader
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
This is a simple CLI tool that allows you to find & follow the logs for the most recently running kubernetes pod with a given name for a given status (default status is "Running"). As of now there is no support for searching for pods that started running in a given window of time, although that is a possible feature add if requested. if a valid pod is not found, it will ping the API once a second until one is found or the program is exited. This primarily just wraps some `kubectl` commands and handles parsing the output in standard way to quickly find a pod's logs.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -14,15 +12,66 @@ gem 'chopshop-logreader'
|
|
14
12
|
|
15
13
|
And then execute:
|
16
14
|
|
17
|
-
|
15
|
+
```bash
|
16
|
+
bundle
|
17
|
+
```
|
18
18
|
|
19
19
|
Or install it yourself as:
|
20
20
|
|
21
|
-
|
21
|
+
```bash
|
22
|
+
gem install chopshop-logreader
|
23
|
+
```
|
24
|
+
|
25
|
+
## Getting started
|
26
|
+
|
27
|
+
This gem assumes 2 things.
|
28
|
+
|
29
|
+
1. you will provide a cloud provider profile (think aws) via one of 3 sources:
|
30
|
+
- an option on the command line (`-p PROFILE` or `--profile PROFILE`)
|
31
|
+
- via the ENV VAR `AWS_PROFILE`
|
32
|
+
- via the ENV VAR `PROFILE`
|
33
|
+
|
34
|
+
2. you will provide a tenant via one of 2 sources:
|
35
|
+
- an option on the command line (`t TENANT` or `--tenant TENANT`)
|
36
|
+
- via the ENV VAR `DEFAULT_TENANT`
|
37
|
+
|
38
|
+
Ideally you will set those env vars before starting.
|
22
39
|
|
23
40
|
## Usage
|
24
41
|
|
25
|
-
|
42
|
+
to get help:
|
43
|
+
|
44
|
+
```bash
|
45
|
+
chopshop-logreader -h
|
46
|
+
```
|
47
|
+
|
48
|
+
example uses:
|
49
|
+
|
50
|
+
```bash
|
51
|
+
chopshop-logreader SERVICE_NAME_HERE -n connect -s Completed -l 10 -f false
|
52
|
+
```
|
53
|
+
|
54
|
+
```bash
|
55
|
+
chopshop-logreader SERVICE_NAME_HERE -n connect -s Error -l -1 -f true
|
56
|
+
```
|
57
|
+
|
58
|
+
```bash
|
59
|
+
chopshop-logreader SERVICE_NAME_HERE -n connect -s Error -l -1 -f true -t some-cool-tenant-name -p my-cool-aws-dev-profile
|
60
|
+
```
|
61
|
+
|
62
|
+
### Default Use
|
63
|
+
|
64
|
+
```bash
|
65
|
+
chopshop-logreader profile-reader
|
66
|
+
```
|
67
|
+
|
68
|
+
expands to
|
69
|
+
|
70
|
+
```bash
|
71
|
+
chopshop-logreader profile-reader -n connect -s Running -l -1 -f true
|
72
|
+
```
|
73
|
+
|
74
|
+
the default use also assumes your have set the ENV VARS `DEFAULT_TENANT` and either `AWS_PROFILE` or `PROFILE`
|
26
75
|
|
27
76
|
## Development
|
28
77
|
|
@@ -32,7 +81,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
81
|
|
33
82
|
## Contributing
|
34
83
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[
|
84
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[tperdue321]/chopshop-logreader. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
85
|
|
37
86
|
## License
|
38
87
|
|
@@ -41,3 +90,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
41
90
|
## Code of Conduct
|
42
91
|
|
43
92
|
Everyone interacting in the Chopshop::Logreader project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/chopshop-logreader/blob/master/CODE_OF_CONDUCT.md).
|
93
|
+
|
94
|
+
## Project TODO
|
95
|
+
|
96
|
+
- add a startup script that will set the default profile/tenant for a user
|
data/chopshop-logreader.gemspec
CHANGED
@@ -35,7 +35,7 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
36
36
|
spec.require_paths = ["lib"]
|
37
37
|
|
38
|
-
spec.add_development_dependency "bundler", "~>
|
38
|
+
spec.add_development_dependency "bundler", "~> 2.2"
|
39
39
|
spec.add_development_dependency "rake", "~> 10.0"
|
40
40
|
spec.add_development_dependency "minitest", "~> 5.0"
|
41
41
|
end
|
@@ -24,22 +24,25 @@ module Chopshop
|
|
24
24
|
|
25
25
|
def execute!
|
26
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"
|
27
30
|
|
28
31
|
container = nil
|
29
32
|
service = ARGV[0]
|
33
|
+
`rally-kubectl -a #{region} -e #{profile} -t #{tenant}`
|
30
34
|
puts "looking for valid container"
|
31
35
|
while !container
|
32
|
-
containers = `kubectl get pods --namespace #{options
|
36
|
+
containers = `kubectl get pods --namespace #{options.namespace} | grep #{service}`
|
33
37
|
container = containers.split("\n").map {|line| line.split(" ") }.each do |line|
|
34
38
|
match_data = REGEX.match(line[4])
|
35
39
|
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
|
36
|
-
end.select{|line| line[2] == options
|
40
|
+
end.select{|line| line[2] == options.status }.sort_by {|line| line[5] }.first
|
37
41
|
|
38
42
|
if container
|
39
|
-
exec "kubectl logs --follow=#{options
|
43
|
+
exec "kubectl logs --follow=#{options.follow} --tail=#{options.lines} --namespace connect #{container[0]}"
|
40
44
|
end
|
41
45
|
|
42
|
-
|
43
46
|
print "."
|
44
47
|
sleep 1
|
45
48
|
end
|
@@ -1,15 +1,20 @@
|
|
1
1
|
require "optparse"
|
2
|
+
require 'ostruct'
|
2
3
|
|
3
4
|
module Chopshop
|
4
5
|
module Logreader
|
5
6
|
class Parser
|
6
7
|
def parse
|
7
|
-
options =
|
8
|
+
options = OpenStruct.new(
|
8
9
|
follow: true, # follow output from log file
|
9
10
|
lines: -1, # whole file always,
|
10
11
|
status: "Running", # look for a currently running container
|
11
|
-
namespace: "connect"
|
12
|
-
|
12
|
+
namespace: "connect",
|
13
|
+
tenant: nil,
|
14
|
+
profile: nil,
|
15
|
+
region: nil
|
16
|
+
)
|
17
|
+
|
13
18
|
|
14
19
|
OptionParser.new do |opts|
|
15
20
|
opts.banner = "Usage: ruby log-reader.rb SERVICE [options]"
|
@@ -30,6 +35,17 @@ module Chopshop
|
|
30
35
|
options[:status] = status
|
31
36
|
end
|
32
37
|
|
38
|
+
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|
|
39
|
+
options[:profile] = profile
|
40
|
+
end
|
41
|
+
|
42
|
+
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|
|
43
|
+
options[:region] = region
|
44
|
+
end
|
45
|
+
|
46
|
+
opts.on("-t [TENANT]", "--tenant [TENANT]", "sets the kubernetes tenant to look for containers in. default: nil. You must provide this value or set the ENV VAR DEFAULT_TENANT'", String) do |tenant|
|
47
|
+
options[:tenant] = tenant
|
48
|
+
end
|
33
49
|
|
34
50
|
opts.on("-h", "--help", "Prints this help") do
|
35
51
|
puts opts
|
data/lib/chopshop/logreader.rb
CHANGED
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.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Travis Perdue
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.2'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,10 +52,11 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
-
description:
|
55
|
+
description:
|
56
56
|
email:
|
57
57
|
- travis.perdue@rallyhealth.com
|
58
58
|
executables:
|
59
|
+
- chopshop-logreader
|
59
60
|
- chopshop_logreader
|
60
61
|
- console
|
61
62
|
- setup
|
@@ -70,6 +71,7 @@ files:
|
|
70
71
|
- LICENSE.txt
|
71
72
|
- README.md
|
72
73
|
- Rakefile
|
74
|
+
- bin/chopshop-logreader
|
73
75
|
- bin/chopshop_logreader
|
74
76
|
- bin/console
|
75
77
|
- bin/setup
|
@@ -85,7 +87,7 @@ metadata:
|
|
85
87
|
homepage_uri: https://github.com/tperdue321/chopshop-logreader
|
86
88
|
source_code_uri: https://github.com/tperdue321/chopshop-logreader
|
87
89
|
changelog_uri: https://github.com/tperdue321/chopshop-logreader
|
88
|
-
post_install_message:
|
90
|
+
post_install_message:
|
89
91
|
rdoc_options: []
|
90
92
|
require_paths:
|
91
93
|
- lib
|
@@ -100,8 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
102
|
- !ruby/object:Gem::Version
|
101
103
|
version: '0'
|
102
104
|
requirements: []
|
103
|
-
rubygems_version: 3.
|
104
|
-
signing_key:
|
105
|
+
rubygems_version: 3.2.22
|
106
|
+
signing_key:
|
105
107
|
specification_version: 4
|
106
108
|
summary: Read logs out of kubernetes
|
107
109
|
test_files: []
|