Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVPROD-4573: Query hosts by Running status for Task Queue UI #7690

Merged
merged 8 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion graphql/query_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func (r *queryResolver) TaskQueueDistros(ctx context.Context) ([]*TaskQueueDistr
distros := []*TaskQueueDistro{}

for _, distro := range queues {
numHosts, err := host.CountRunningHosts(ctx, distro.Distro)
numHosts, err := host.CountRunningStatusHosts(ctx, distro.Distro)
if err != nil {
return nil, InternalServerError.Send(ctx, fmt.Sprintf("Error getting associated hosts: %s", err.Error()))
}
Expand Down
2 changes: 1 addition & 1 deletion graphql/tests/query/taskQueueDistros/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
"id": "debian71-test",
"taskCount": 0,
"hostCount": 1
"hostCount": 0
}
]
}
Expand Down
15 changes: 15 additions & 0 deletions model/host/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,16 @@ func runningHostsQuery(distroID string) bson.M {
return query
}

// byRunningStatusQuery produces a query that returns all hosts
// with the running status that belong to the given distro.
func byRunningStatusQuery(distroID string) bson.M {
distroIDKey := bsonutil.GetDottedKeyName(DistroKey, distro.IdKey)
return bson.M{
distroIDKey: distroID,
StatusKey: evergreen.HostRunning,
}
}

func idleStartedTaskHostsQuery(distroID string) bson.M {
query := bson.M{
StatusKey: bson.M{"$in": evergreen.StartedHostStatus},
Expand Down Expand Up @@ -263,6 +273,11 @@ func CountRunningHosts(ctx context.Context, distroID string) (int, error) {
return num, errors.Wrap(err, "counting running hosts")
}

func CountRunningStatusHosts(ctx context.Context, distroID string) (int, error) {
num, err := Count(ctx, byRunningStatusQuery(distroID))
return num, errors.Wrap(err, "counting running status hosts")
}

func CountAllRunningDynamicHosts(ctx context.Context) (int, error) {
query := IsLive()
query[ProviderKey] = bson.M{"$in": evergreen.ProviderSpawnable}
Expand Down
55 changes: 55 additions & 0 deletions model/host/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,3 +781,58 @@ func TestFindHostsScheduledToStart(t *testing.T) {
})
}
}

func TestCountRunningStatusHosts(t *testing.T) {
assert.NoError(t, db.ClearCollections(Collection))
d1 := distro.Distro{
Id: "d1",
}
h1 := Host{
Id: "h1",
Distro: d1,
Status: evergreen.HostRunning,
}
h2 := Host{
Id: "h2",
Distro: d1,
Status: evergreen.HostTerminated,
}
h3 := Host{
Id: "h3",
Distro: d1,
Status: evergreen.HostStopping,
}
h4 := Host{
Id: "h4",
Distro: d1,
Status: evergreen.HostRunning,
}
h5 := Host{
Id: "h5",
Distro: d1,
Status: evergreen.HostBuilding,
}
h6 := Host{
Id: "h6",
Distro: d1,
Status: evergreen.HostProvisionFailed,
}
h7 := Host{
Id: "h7",
Distro: d1,
Status: evergreen.HostStopped,
}
h8 := Host{
Id: "h8",
Distro: d1,
Status: evergreen.HostProvisioning,
}

assert.NoError(t, db.InsertMany(Collection, h1, h2, h3, h4, h5, h6, h7, h8))

ctx := context.TODO()
count, err := CountRunningStatusHosts(ctx, "d1")
assert.NoError(t, err)
assert.Equal(t, 2, count)

}
Loading