Skip to content

Commit b0a67a2

Browse files
Googlercopybara-github
Googler
authored andcommitted
Clear WorkerMetricsCollector fields properly.
Previously uncleared fields could add the misinterpretation to the meaning of fields. PiperOrigin-RevId: 477113885 Change-Id: I94360169687b6627ca4ba539dfe4a75a5c09fa6d
1 parent 11aa727 commit b0a67a2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/main/java/com/google/devtools/build/lib/worker/WorkerMetricsCollector.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class WorkerMetricsCollector {
5656

5757
private final Map<Integer, Instant> workerLastCallTime = new ConcurrentHashMap<>();
5858

59-
private MetricsWithTime lastMetrics = new MetricsWithTime(ImmutableList.of(), Instant.EPOCH);
59+
private MetricsWithTime lastMetrics;
6060

6161
private WorkerMetricsCollector() {}
6262

@@ -188,7 +188,7 @@ public Process buildPsProcess() throws IOException {
188188
*/
189189
public ImmutableList<WorkerMetric> collectMetrics(Duration interval) {
190190
Instant now = Instant.ofEpochMilli(clock.currentTimeMillis());
191-
if (Duration.between(lastMetrics.time, now).compareTo(interval) < 0) {
191+
if (lastMetrics != null && Duration.between(lastMetrics.time, now).compareTo(interval) < 0) {
192192
return lastMetrics.metrics;
193193
}
194194

@@ -235,6 +235,8 @@ public ImmutableList<WorkerMetric> collectMetrics() {
235235

236236
public void clear() {
237237
workerIdToWorkerProperties.clear();
238+
workerLastCallTime.clear();
239+
lastMetrics = null;
238240
}
239241

240242
@VisibleForTesting

0 commit comments

Comments
 (0)