-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add missing k8s job submission times to allocations (#9028)
tasks stats used to report Go time zero value as their start time on k8s ``` determined> select allocation_id, start_time, end_time - start_time as duration from task_stats where event_type = 'QUEUED' ```
- Loading branch information
Showing
10 changed files
with
111 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package rm | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/determined-ai/determined/master/internal/db" | ||
"github.com/determined-ai/determined/master/pkg/model" | ||
"github.com/determined-ai/determined/proto/pkg/jobv1" | ||
) | ||
|
||
// FetchAvgQueuedTime fetches the average queued time for a resource pool. | ||
func FetchAvgQueuedTime(pool string) ( | ||
[]*jobv1.AggregateQueueStats, error, | ||
) { | ||
aggregates := []model.ResourceAggregates{} | ||
err := db.Bun().NewSelect().Model(&aggregates). | ||
Where("aggregation_type = ?", model.AggregationTypeQueued). | ||
Where("aggregation_key = ?", pool). | ||
Where("date >= CURRENT_TIMESTAMP - interval '30 days'"). | ||
Order("date ASC").Scan(context.TODO()) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "error fetching aggregates") | ||
} | ||
res := make([]*jobv1.AggregateQueueStats, 0) | ||
for _, record := range aggregates { | ||
res = append(res, &jobv1.AggregateQueueStats{ | ||
PeriodStart: record.Date.Format("2006-01-02"), | ||
Seconds: record.Seconds, | ||
}) | ||
} | ||
today := float32(0) | ||
subq := db.Bun().NewSelect().TableExpr("allocations").Column("allocation_id"). | ||
Where("resource_pool = ?", pool). | ||
Where("start_time >= CURRENT_DATE") | ||
err = db.Bun().NewSelect().TableExpr("task_stats").ColumnExpr( | ||
"avg(extract(epoch FROM end_time - start_time))", | ||
).Where("event_type = ?", "QUEUED"). | ||
Where("end_time >= CURRENT_DATE AND allocation_id IN (?) ", subq). | ||
Scan(context.TODO(), &today) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "error fetching average queued time") | ||
} | ||
res = append(res, &jobv1.AggregateQueueStats{ | ||
PeriodStart: time.Now().Format("2006-01-02"), | ||
Seconds: today, | ||
}) | ||
return res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters