fix messageGap metric (#12337)

This commit is contained in:
Yuanli Han 2022-03-29 00:21:06 +08:00 committed by GitHub
parent 9c6b9abcde
commit f2495a67d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -263,7 +263,8 @@ public class FireDepartmentMetrics
retVal.messageMaxTimestamp.set(messageMaxTimestamp.get());
retVal.messageProcessingCompletionTime.set(messageProcessingCompletionTime.get());
retVal.messageProcessingCompletionTime.compareAndSet(DEFAULT_PROCESSING_COMPLETION_TIME, System.currentTimeMillis());
retVal.messageGap.set(retVal.messageProcessingCompletionTime.get() - messageMaxTimestamp.get());
long maxTimestamp = retVal.messageMaxTimestamp.get();
retVal.messageGap.set(maxTimestamp > 0 ? retVal.messageProcessingCompletionTime.get() - maxTimestamp : 0L);
return retVal;
}
}

View File

@ -33,6 +33,12 @@ public class FireDepartmentMetricsTest
metrics = new FireDepartmentMetrics();
}
@Test
public void testSnapshotBeforeProcessing()
{
Assert.assertEquals(0L, metrics.snapshot().messageGap());
}
@Test
public void testSnapshotAfterProcessingOver()
{