From bae0e9d66117f42e13939855f08ddc5f417f8e91 Mon Sep 17 00:00:00 2001 From: Michael Smithhisler Date: Tue, 6 Jan 2026 21:11:08 +0000 Subject: [PATCH] backport of commit 52629ac9d76cb2bf5b361f78072c1bee54fb9564 --- .changelog/27317.txt | 3 +++ client/allocrunner/alloc_runner.go | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 .changelog/27317.txt diff --git a/.changelog/27317.txt b/.changelog/27317.txt new file mode 100644 index 00000000000..aa2fd14dc2e --- /dev/null +++ b/.changelog/27317.txt @@ -0,0 +1,3 @@ +```release-note:bug +api: only include running tasks in allocation resource usage +``` diff --git a/client/allocrunner/alloc_runner.go b/client/allocrunner/alloc_runner.go index 9516ab46b10..e0cb0d7daa8 100644 --- a/client/allocrunner/alloc_runner.go +++ b/client/allocrunner/alloc_runner.go @@ -1314,9 +1314,11 @@ func (ar *allocRunner) LatestAllocStats(taskFilter string) (*cstructs.AllocResou if usage := tr.LatestResourceUsage(); usage != nil { astat.Tasks[name] = usage - astat.ResourceUsage.Add(usage.ResourceUsage) - if usage.Timestamp > astat.Timestamp { - astat.Timestamp = usage.Timestamp + if tr.IsRunning() { + astat.ResourceUsage.Add(usage.ResourceUsage) + if usage.Timestamp > astat.Timestamp { + astat.Timestamp = usage.Timestamp + } } } }