Skip to content

Commit 4ad1243

Browse files
[Backport 7.58.x] discovery: Allow delta for create time check (#30664)
Co-authored-by: vitkyrka <[email protected]>
1 parent 2e06337 commit 4ad1243

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pkg/collector/corechecks/servicediscovery/module/impl_linux_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,19 @@ func assertStat(t assert.TestingT, svc model.Service) {
551551
return
552552
}
553553

554-
assert.Equal(t, uint64(createTimeMs/1000), svc.StartTimeSecs)
554+
// The value returned by proc.CreateTime() can vary between invocations
555+
// since the BootTime (used internally in proc.CreateTime()) can vary when
556+
// the version of BootTimeWithContext which uses /proc/uptime is active in
557+
// gopsutil (either on Docker, or even outside of it due to a bug fixed in
558+
// v4.24.8:
559+
// https://github.com/shirou/gopsutil/commit/aa0b73dc6d5669de5bc9483c0655b1f9446317a9).
560+
//
561+
// This is due to an inherent race since the code in BootTimeWithContext
562+
// substracts the uptime of the host from the current time, and there can be
563+
// in theory an unbounded amount of time between the read of /proc/uptime
564+
// and the retrieval of the current time. Allow a 10 second diff as a
565+
// reasonable value.
566+
assert.InDelta(t, uint64(createTimeMs/1000), svc.StartTimeSecs, 10)
555567
}
556568

557569
func assertCPU(t *testing.T, url string, pid int) {

0 commit comments

Comments
 (0)