Skip to content

Commit 41665f7

Browse files
committed
Avoid potential panic in prometheus if xrootd decrements destructions
1 parent 2c440ab commit 41665f7

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

metrics/xrootd_metrics.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,8 +1895,19 @@ func HandleSummaryPacket(packet []byte) error {
18951895
incBy = 0
18961896
}
18971897
ThreadCreations.Add(incBy)
1898-
ThreadDestructions.Add(float64(stat.ThreadDestructions - lastStats.ThreadDestructions))
1899-
ThreadLimitReached.Add(float64(stat.ThreadLimitReached - lastStats.ThreadLimitReached))
1898+
1899+
incBy = float64(stat.ThreadDestructions - lastStats.ThreadDestructions)
1900+
if stat.ThreadDestructions < lastStats.ThreadDestructions {
1901+
incBy = 0
1902+
}
1903+
ThreadDestructions.Add(incBy)
1904+
1905+
incBy = float64(stat.ThreadLimitReached - lastStats.ThreadLimitReached)
1906+
if stat.ThreadLimitReached < lastStats.ThreadLimitReached {
1907+
incBy = 0
1908+
}
1909+
ThreadLimitReached.Add(incBy)
1910+
19001911
lastStats.ThreadCreations = stat.ThreadCreations
19011912
lastStats.ThreadDestructions = stat.ThreadDestructions
19021913
lastStats.ThreadLimitReached = stat.ThreadLimitReached

0 commit comments

Comments
 (0)