kubernetes_health_checker 0.0.0.8 → 0.0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 1b91f9a1f8905f8e09dfd8a3d67f092e909e59ff
4
- data.tar.gz: 552bf56c1edf01d4a5e878344a2ce16523fc228c
2
+ SHA256:
3
+ metadata.gz: 58a40f40dddb563becfc52a7ab63d9e3848d8b18fdc167c7bad02880bb1a0d75
4
+ data.tar.gz: 5264cc5ce67872d52fbc8d545a40eef33a83a24b7ad9d9baea29364b703ce5ec
5
5
  SHA512:
6
- metadata.gz: 45573b6b8e3674a46a79599306b39ad678d8a268b5f3e87ce101e9403b1dbf694ff1248c003b9063fb3c448e9130fdb23570acb4f77b8fb17beba1bb15c618fa
7
- data.tar.gz: d2b68dcf889eabeacb47b13e0952e522df3c3f18e53854d4a40bdbf2225d2973bac62fc362384ebc2773e23fa4e7d73bffe302f4eafb00872686948c19cecdfb
6
+ metadata.gz: '0859e8c5514b2a3d2235005b26e469eeef777b99dbe6ad312e0cf48da1c7ff0516f05a64830bc3df385d0ddd5451aba408e58b3cba38080eb13277656dbfa72c'
7
+ data.tar.gz: 7f2d7c96cea1dbc26287ceaf5e8cfb0ba41d3c051e4dae7df5e9b6ee46e4b0c6d0b2604d6839cf4890eff085b856fbea309e5fc152800f2e093117743b3b22a0
@@ -3,6 +3,7 @@
3
3
  require 'rubygems'
4
4
  require 'thor'
5
5
  require 'json'
6
+ require 'byebug'
6
7
 
7
8
  module KubernetesHealthChecker
8
9
  class Runner < Thor
@@ -15,7 +16,13 @@ module KubernetesHealthChecker
15
16
  method_option :url, aliases: '-u', type: :string, desc: 'Specify the slack url you would like the alert POSTed to'
16
17
  method_option :test, aliases: '-t', type: :boolean, desc: 'Specify if running the gem in test mode'
17
18
 
18
- ALERT_STATUSES = ['crashloopbackoff', 'pending'].freeze
19
+ ALERT_STATUSES = ['crashloopbackoff'].freeze
20
+
21
+ # time is in seconds
22
+ TIMED_ALERT_STATUSES = {
23
+ 'pending' => 30,
24
+ 'containercreating' => 30,
25
+ }
19
26
 
20
27
  RUN_INTERVAL = 120
21
28
 
@@ -78,7 +85,7 @@ module KubernetesHealthChecker
78
85
  `curl -X POST --data-urlencode 'payload=#{JSON.generate(payload)}' #{@url}`
79
86
  end
80
87
 
81
- def get_pod_message(pod_name:, new_status:, new_restarts:)
88
+ def get_pod_message(pod_name:, new_status:, new_restarts:, age:)
82
89
  old_restarts = @pods_data[pod_name][:restarts]
83
90
  old_status = @pods_data[pod_name][:status]
84
91
  text = ""
@@ -87,6 +94,11 @@ module KubernetesHealthChecker
87
94
  # we've already alerted from this state, skip
88
95
  elsif ALERT_STATUSES.include?(new_status.downcase)
89
96
  text = "Pod *#{pod_name}* is in status: *#{new_status}*.\n"
97
+ elsif TIMED_ALERT_STATUSES.keys.include?(new_status.downcase)
98
+ alert_threshold = TIMED_ALERT_STATUSES[new_status.downcase]
99
+ if age > alert_threshold
100
+ text = "Pod #{pod_name} has been in status: *#{new_status}* for #{age} seconds :grimacing:."
101
+ end
90
102
  elsif new_restarts > @alert_threshold
91
103
  text = "Pod *#{pod_name}* has restarted *#{new_restarts}* times and has status: *#{new_status}*.\n"
92
104
  end
@@ -106,9 +118,10 @@ module KubernetesHealthChecker
106
118
  pod_name = row[0]
107
119
  status = row[2]
108
120
  restarts = row[3].to_i
121
+ age = get_age_in_seconds(row[4])
109
122
 
110
123
  @pods_data[pod_name] ||= {}
111
- message += get_pod_message(pod_name: pod_name, new_status: status, new_restarts: restarts)
124
+ message += get_pod_message(pod_name: pod_name, new_status: status, new_restarts: restarts, age: age)
112
125
 
113
126
  # update our data store for the pods
114
127
  @pods_data[pod_name][:status] = status
@@ -117,6 +130,24 @@ module KubernetesHealthChecker
117
130
 
118
131
  message
119
132
  end
133
+
134
+ def get_age_in_seconds(raw_age)
135
+ # this split does: 1d = [1, d]
136
+ number, unit = raw_age.split(/(?<=\d)(?=[A-Za-z])/)
137
+ case unit
138
+ when 's'
139
+ number.to_i
140
+ when 'm'
141
+ number.to_i * 60
142
+ when 'h'
143
+ number.to_i * 60 * 60
144
+ when 'd'
145
+ number.to_i * 60 * 60 * 24
146
+ else
147
+ # I don't think we'll ever get here
148
+ nil
149
+ end
150
+ end
120
151
  end
121
152
  end
122
153
  end
@@ -43,7 +43,7 @@ refresh-cross-org-external-pairs-rc-lbj69 1/1 Running 0
43
43
  refresh-email-address-strengths-rc-qnxjl 1/1 Running 0 1d
44
44
  refresh-internal-externals-rc-t88d3 1/1 Running 0 1d
45
45
  refresh-organization-relevant-company-rc-vqzv7 1/1 Running 0 1d
46
- refresh-person-smart-attributes-rc-8m1xd 1/1 Running 0 1d
46
+ refresh-person-smart-attributes-rc-8m1xd 1/1 ContainerCreating 0 10m
47
47
  reset-reminders-and-create-notifications-rc-w75wt 1/1 Running 0 1d
48
48
  reset-reminders-email-consumer-rc-bvwq7 1/1 Running 0 1d
49
49
  reset-reminders-event-consumer-rc-2fx0g 1/1 Running 1 1d
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubernetes_health_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0.8
4
+ version: 0.0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rohan Sahai
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  requirements: []
87
87
  rubyforge_project:
88
- rubygems_version: 2.6.12
88
+ rubygems_version: 2.7.7
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: Get notifications for unhealthy kubernetes pods