chopshop-logreader 0.1.2 → 0.2.3

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: d6832e1640a4f8c99cfbdc2a010d39aac2510891a8505445e7ea5ce7e0f8d981
4
- data.tar.gz: 50d99bafbfa934f38a0a5e4bd7cf730863be08f83af926813beea6ed652b5581
3
+ metadata.gz: aa1d6a0266d4f7ee6fe20dd3a0d0e5042e1f587f5d276ba11a514b811742ff1c
4
+ data.tar.gz: d90185bece540bbce81b47e31a8346ad976f17ed54688d0234c26a3f277c62bf
5
5
  SHA512:
6
- metadata.gz: 02bb0cc3fd4371687cf0a90fc8b6e0b2d60b44e883da50b7b1b659a177fef8079044ef44f7fcfed316f7802fb40ec86763f764bdba5259e8ac73b5d0567756c9
7
- data.tar.gz: 3cdea25e30bc8f814ec426a3a39cd4a561a459679d01a651c70d8da98acb2c0c2d4d9b5b7493dd3229548ee67eb9973c3d9899e2e524c274e84d74c8c7b78ed7
6
+ metadata.gz: 3bd32954bfc925ff2194b51ea5704764152b248134a5e228b30973d5f7c2991fb8cccf540db357193fe76508a2ba03cb54dc271223cf1a4946ed2fc035614045
7
+ data.tar.gz: a993a805d2f281005b75b64cbc94deae2fc1401ec19d29a5f08370e6f426cc28c13664349050c21703b6394afefd34d21a286b33b2939537afd5ca01bdc6bf36
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chopshop-logreader (0.1.1)
4
+ chopshop-logreader (0.2.3)
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 (~> 1.17)
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
- 1.17.2
22
+ 2.2.33
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Chopshop::Logreader
2
2
 
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.
3
4
 
4
5
  ## Installation
5
6
 
@@ -11,20 +12,66 @@ gem 'chopshop-logreader'
11
12
 
12
13
  And then execute:
13
14
 
14
- $ bundle
15
+ ```bash
16
+ bundle
17
+ ```
15
18
 
16
19
  Or install it yourself as:
17
20
 
18
- $ gem install chopshop-logreader
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.
19
39
 
20
40
  ## Usage
21
41
 
22
- `chopshop-logreader -h` to get help
23
- example use:
24
- `chopshop-logreader SERVICE_NAME_HERE -n connect -s Running -l 10 -f false`
25
- default use:
26
- `chopshop-logreader profile-reader` expands to `chopshop-logreader profile-reader -n connect -s Running -l -1 -f true`
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
+ ```
27
73
 
74
+ the default use also assumes your have set the ENV VARS `DEFAULT_TENANT` and either `AWS_PROFILE` or `PROFILE`
28
75
 
29
76
  ## Development
30
77
 
@@ -43,3 +90,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
43
90
  ## Code of Conduct
44
91
 
45
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
@@ -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", "~> 1.17"
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,30 @@ module Chopshop
24
24
 
25
25
  def execute!
26
26
  options = @parser.parse
27
-
28
- container = nil
29
- service = ARGV[0]
30
- puts "looking for valid container"
31
- while !container
32
- containers = `kubectl get pods --namespace #{options[:namespace]} | grep #{service}`
33
- container = containers.split("\n").map {|line| line.split(" ") }.each do |line|
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
31
+
32
+ service = nil
33
+ service_name = ARGV[0]
34
+ `rally-kubectl -a #{region} -e #{profile} -t #{tenant}`
35
+ puts "looking for valid service container"
36
+ while !service
37
+ services = `kubectl get pods --namespace #{options.namespace} | grep #{service_name}`
38
+ service = services.split("\n").map {|line| line.split(" ") }.each do |line|
34
39
  match_data = REGEX.match(line[4])
35
40
  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[:status] }.sort_by {|line| line[5] }.first
37
-
38
- if container
39
- exec "kubectl logs --follow=#{options[:follow]} --tail=#{options[:lines]} --namespace connect #{container[0]}"
41
+ end.select{|line| line[2] == options.status }.sort_by {|line| line[5] }.first
42
+
43
+ if service
44
+ if container
45
+ exec "kubectl logs --follow=#{options.follow} --tail=#{options.lines} --namespace connect --container=#{container} #{service[0]}"
46
+ else
47
+ exec "kubectl logs --follow=#{options.follow} --tail=#{options.lines} --namespace connect #{service[0]}"
48
+ end
40
49
  end
41
50
 
42
-
43
51
  print "."
44
52
  sleep 1
45
53
  end
@@ -1,18 +1,24 @@
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
- status: "Running", # look for a currently running container
11
- namespace: "connect"
12
- }
11
+ status: "Running", # look for a currently running service
12
+ namespace: "connect",
13
+ tenant: nil,
14
+ profile: nil,
15
+ region: nil,
16
+ container: nil
17
+ )
18
+
13
19
 
14
20
  OptionParser.new do |opts|
15
- opts.banner = "Usage: ruby log-reader.rb SERVICE [options]"
21
+ opts.banner = "Usage: chopshop-logreader SERVICE [options]"
16
22
 
17
23
  opts.on("-f [FOLLOW]", "--follow [FOLLOW]", "boolean true/false on whether to follow output from the file. default: true", TrueClass) do |follow|
18
24
  options[:follow] = follow
@@ -22,14 +28,29 @@ module Chopshop
22
28
  options[:lines] = lines
23
29
  end
24
30
 
25
- opts.on("-s [STATUS]", "--status [STATUS]", "valid values: Completed|Running|Error. will only look for containers with the given status. default: Running", String) do |status|
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|
26
32
  options[:status] = status
27
33
  end
28
34
 
29
- opts.on("-n [NAMESPACE]", "--namespace [NAMESPACE]", "sets the kubernetes namespace to look for containers in. default: connect", String) do |status|
35
+ opts.on("-n [NAMESPACE]", "--namespace [NAMESPACE]", "sets the kubernetes namespace to look for service/job in. default: connect", String) do |status|
30
36
  options[:status] = status
31
37
  end
32
38
 
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|
40
+ options[:profile] = profile
41
+ end
42
+
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|
52
+ options[:tenant] = tenant
53
+ end
33
54
 
34
55
  opts.on("-h", "--help", "Prints this help") do
35
56
  puts opts
@@ -1,5 +1,5 @@
1
1
  module Chopshop
2
2
  module Logreader
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.3"
4
4
  end
5
5
  end
@@ -1,7 +1,6 @@
1
1
  module Chopshop
2
2
  module Logreader
3
3
  class Error < StandardError; end
4
- # Your code goes here...
5
4
  end
6
5
  end
7
6
 
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.1.2
4
+ version: 0.2.3
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-18 00:00:00.000000000 Z
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: '1.17'
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: '1.17'
26
+ version: '2.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +52,7 @@ 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:
@@ -87,7 +87,7 @@ metadata:
87
87
  homepage_uri: https://github.com/tperdue321/chopshop-logreader
88
88
  source_code_uri: https://github.com/tperdue321/chopshop-logreader
89
89
  changelog_uri: https://github.com/tperdue321/chopshop-logreader
90
- post_install_message:
90
+ post_install_message:
91
91
  rdoc_options: []
92
92
  require_paths:
93
93
  - lib
@@ -102,8 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
- rubygems_version: 3.0.3
106
- signing_key:
105
+ rubygems_version: 3.2.22
106
+ signing_key:
107
107
  specification_version: 4
108
108
  summary: Read logs out of kubernetes
109
109
  test_files: []