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 + } } } }