Alexandros Kosiaris has uploaded a new change for review.
https://gerrit.wikimedia.org/r/170310
Change subject: Catch a couple of corner cases in check_puppetrun
......................................................................
Catch a couple of corner cases in check_puppetrun
time_ago that was introduced in 5a3fe15 did not catch a couple of corner
cases. Notably if s was 0 or 1 the entire sorted reversed struct would be
returned and periods like 60 seconds would not be converted to 1 minute
and so on. Fix this by testing for s == 0, change > to >= and provide a
default return value in case of other failures
Change-Id: Iecaafb4ea696fab68a3ad3e7c857626ef2371cff
---
M modules/base/files/monitoring/check_puppetrun
1 file changed, 6 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/puppet
refs/changes/10/170310/1
diff --git a/modules/base/files/monitoring/check_puppetrun
b/modules/base/files/monitoring/check_puppetrun
index b8fd053..c486a44 100755
--- a/modules/base/files/monitoring/check_puppetrun
+++ b/modules/base/files/monitoring/check_puppetrun
@@ -96,9 +96,13 @@
def time_ago(s)
units = {86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second'}
- units.sort.reverse.each do |len, unit|
- return "#{s / len} #{unit}#{'s' if s / len > 1}" if s > len
+ if s == 0
+ return "0 seconds"
end
+ units.sort.reverse.each do |len, unit|
+ return "#{s / len} #{unit}#{'s' if s / len > 1}" if s >= len
+ end
+ "Indeterminate amount of time (see time_ago)"
end
time_since_last_run = Time.now.to_i - lastrun
--
To view, visit https://gerrit.wikimedia.org/r/170310
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iecaafb4ea696fab68a3ad3e7c857626ef2371cff
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Alexandros Kosiaris <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits