diff --git a/client/alloc_runner.go b/client/alloc_runner.go index e6f17746a..63491ed1d 100644 --- a/client/alloc_runner.go +++ b/client/alloc_runner.go @@ -31,7 +31,6 @@ type AllocStateUpdater func(alloc *structs.Allocation) // AllocStatsReporter exposes stats related APIs of an allocation runner type AllocStatsReporter interface { AllocStats() map[string]TaskStatsReporter - TaskStats(task string) (TaskStatsReporter, error) } // AllocRunner is used to wrap an allocation and provide the execution context. diff --git a/client/task_runner.go b/client/task_runner.go index 5ecae660e..7ee22f8dc 100644 --- a/client/task_runner.go +++ b/client/task_runner.go @@ -37,7 +37,12 @@ const ( // TaskStatsReporter exposes APIs to query resource usage of a Task type TaskStatsReporter interface { + // ResourceUsage returns the latest resource usage data point collected for + // the task ResourceUsage() *cstructs.TaskResourceUsage + + // ResourceUsageTS returns all the resource usage data points since a given + // time ResourceUsageTS(since time.Time) []*cstructs.TaskResourceUsage } diff --git a/command/agent/alloc_endpoint.go b/command/agent/alloc_endpoint.go index 0558d7d45..4d43ed5de 100644 --- a/command/agent/alloc_endpoint.go +++ b/command/agent/alloc_endpoint.go @@ -76,8 +76,8 @@ func (s *HTTPServer) ClientAllocRequest(resp http.ResponseWriter, req *http.Requ } if task := req.URL.Query().Get("task"); task != "" { - taskStats, err := allocStats.TaskStats(task) - if err != nil { + taskStats, ok := allocStats.AllocStats()[task] + if !ok { return nil, CodedError(404, "task not present in allocation") } return taskStats.ResourceUsage(), nil