Skip to content

Commit 9660e00

Browse files
committed
Sort failed jobs in check_pgagent_jobs for stable output
Also, append a space to test regexps to make sure the output really ends there (otherwise, there would be a ';') and fix a testcase where this was wrong.
1 parent 1ceed17 commit 9660e00

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

check_postgres.pl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5972,6 +5972,7 @@ sub check_pgagent_jobs {
59725972
JOIN pgagent.pga_jobsteplog slog ON jlog.jlgid = slog.jsljlgid AND step.jstid = slog.jsljstid
59735973
WHERE ((slog.jslresult = -1 AND step.jstkind='s') OR (slog.jslresult <> 0 AND step.jstkind='b'))
59745974
AND EXTRACT('epoch' FROM NOW() - (jlog.jlgstart + jlog.jlgduration)) < $seconds
5975+
ORDER BY jlog.jlgstart DESC
59755976
};
59765977

59775978
my $info = run_command($SQL);
@@ -10344,12 +10345,14 @@ =head1 HISTORY
1034410345
total_relation_size, using the respective pg_indexes_size() and
1034510346
pg_total_relation_size() functions. All size checks will now also check
1034610347
materialized views where applicable.
10348+
(Christoph Berg)
1034710349
1034810350
Connection errors are now always critical, not unknown.
1034910351
(Christoph Berg)
1035010352
1035110353
New action replication_slots checking if logical or physical replication
1035210354
slots have accumulated too much data
10355+
(Glyn Astill)
1035310356
1035410357
Multiple same_schema improvements
1035510358
(Glyn Astill)
@@ -10382,6 +10385,9 @@ =head1 HISTORY
1038210385
Remove \r from psql output as it can confuse some regexes
1038310386
(Greg Sabino Mullane)
1038410387
10388+
Sort failed jobs in check_pgagent_jobs for stable output.
10389+
(Christoph Berg)
10390+
1038510391
=item B<Version 2.22.0> June 30, 2015
1038610392
1038710393
Add xact timestamp support to hot_standby_delay.

t/02_pgagent_jobs.t

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ like $cp->run('-c=2h'), qr{^$label OK: DB "postgres"},
124124
"$S -c=2h returns ok with failed job before our time";
125125

126126
like $cp->run('-c=6h'),
127-
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!},
127+
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF! },
128128
"$S -c=6h returns critical with failed job within our time";
129129

130130
like $cp->run('-w=2h'), qr{^$label OK: DB "postgres"},
131131
"$S -w=2h returns ok with failed job before our time";
132132

133133
like $cp->run('-w=6h'),
134-
qr{^$label WARNING: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!},
134+
qr{^$label WARNING: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF! },
135135
"$S -w=6h returns warninf with failed job within our time";
136136

137137
like $cp->run('-w=2h'), qr{^$label OK: DB "postgres"},
@@ -141,15 +141,15 @@ like $cp->run('-w=4h -c=2h'), qr{^$label OK: DB "postgres"},
141141
"$S -w=4h =c=2h returns ok with failed job before our time";
142142

143143
like $cp->run('-w=5h -c=2h'),
144-
qr{^$label WARNING: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!},
144+
qr{^$label WARNING: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF! },
145145
"$S -w=5h =c=2h returns warning with failed job within our time";
146146

147147
like $cp->run('-w=2h -c=5h'),
148-
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!},
148+
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF! },
149149
"$S -w=2h =c=5h returns critical with failed job within our time";
150150

151151
like $cp->run('-w=5h -c=5h'),
152-
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!},
152+
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF! },
153153
"$S -w=5h =c=5h returns critical with failed job within our time";
154154

155155
# Make a second job fail, back 30 hours.
@@ -165,14 +165,14 @@ like $cp->run('-c=2h'), qr{^$label OK: DB "postgres"},
165165
"$S -c=2h returns ok with failed job before our time";
166166

167167
like $cp->run('-c=6h'),
168-
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!},
168+
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF! },
169169
"$S -c=6h returns critical with failed job within our time";
170170

171171
like $cp->run('-w=2h'), qr{^$label OK: DB "postgres"},
172172
"$S -w=2h returns ok with failed job before our time";
173173

174174
like $cp->run('-w=6h'),
175-
qr{^$label WARNING: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!},
175+
qr{^$label WARNING: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF! },
176176
"$S -w=6h returns warninf with failed job within our time";
177177

178178
like $cp->run('-w=2h'), qr{^$label OK: DB "postgres"},
@@ -182,42 +182,42 @@ like $cp->run('-w=4h -c=2h'), qr{^$label OK: DB "postgres"},
182182
"$S -w=4h =c=2h returns ok with failed job before our time";
183183

184184
like $cp->run('-w=5h -c=2h'),
185-
qr{^$label WARNING: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!},
185+
qr{^$label WARNING: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF! },
186186
"$S -w=5h =c=2h returns warning with failed job within our time";
187187

188188
like $cp->run('-w=2h -c=5h'),
189-
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!},
189+
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF! },
190190
"$S -w=2h =c=5h returns critical with failed job within our time";
191191

192192
like $cp->run('-w=5h -c=5h'),
193-
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!},
193+
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF! },
194194
"$S -w=5h -c=5h returns critical with failed job within our time";
195195

196196
# Go back further in time!
197197
like $cp->run('-w=30h -c=2h'),
198-
qr{^$label WARNING: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!},
199-
"$S -w=30h -c=5h returns warning for older failed job";
198+
qr{^$label WARNING: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!; 64 Restore/analyze: OMGWTFLOL! },
199+
"$S -w=30h -c=2h returns warning for older failed job";
200200

201201
like $cp->run('-w=30h -c=6h'),
202-
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!; 64 Restore/analyze: OMGWTFLOL!},
202+
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!; 64 Restore/analyze: OMGWTFLOL! },
203203
"$S -w=30h -c=6h returns critical with both jobs, more recent critical";
204204

205205
like $cp->run('-c=30h'),
206-
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!; 64 Restore/analyze: OMGWTFLOL!},
206+
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!; 64 Restore/analyze: OMGWTFLOL! },
207207
"$S -c=30h returns critical with both failed jobs";
208208

209209
like $cp->run('-w=30h'),
210-
qr{^$label WARNING: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!; 64 Restore/analyze: OMGWTFLOL!},
210+
qr{^$label WARNING: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!; 64 Restore/analyze: OMGWTFLOL! },
211211
"$S -w=30h returns critical with both failed jobs";
212212

213213
# Try with critical recent and warning longer ago.
214214
like $cp->run('-w=30h -c=6h'),
215-
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!; 64 Restore/analyze: OMGWTFLOL!},
215+
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!; 64 Restore/analyze: OMGWTFLOL! },
216216
"$S -w=30h -c=6h returns critical with both failed jobs";
217217

218218
# Try with warning recent and critical longer ago.
219219
like $cp->run('-c=30h -w=6h'),
220-
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!; 64 Restore/analyze: OMGWTFLOL!},
220+
qr{^$label CRITICAL: DB "postgres" [()][^)]+[)] 255 Restore/analyze: WTF!; 64 Restore/analyze: OMGWTFLOL! },
221221
"$S -c=30h -w=6h returns critical with both failed jobs";
222222

223223
# Undo the more recent failure.

0 commit comments

Comments
 (0)