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-11769: Improve waterfall handling for inactive versions #8361

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
32 changes: 21 additions & 11 deletions graphql/query_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,15 +1000,23 @@ func (r *queryResolver) Waterfall(ctx context.Context, options WaterfallOptions)

// Since GetAllWaterfallVersions uses an inclusive order range ($gte instead of $gt), add 1 to our minimum range
minVersionOrder := minOrderOpt + 1
if minOrderOpt == 0 {
if minOrderOpt == 0 && len(activeVersions) != 0 {
// Only use the last active version order number if no minOrder was provided. Using the activeVersions bounds may omit inactive versions between the min and the last active version found.
minVersionOrder = activeVersions[len(activeVersions)-1].RevisionOrderNumber
} else if len(activeVersions) == 0 {
// If there are no active versions, use 0 to fetch all inactive versions
minVersionOrder = 0
}

// Same as above, but subtract for max order
maxVersionOrder := maxOrderOpt - 1
if maxOrderOpt == 0 {
// Same as above: only use the first active version if no maxOrder was specified to avoid omitting inactive versions.
if len(activeVersions) == 0 {
maxVersionOrder = 0
} else if maxOrderOpt == 0 && minOrderOpt == 0 {
// If no order options were specified, we're on the first page and should not put a limit on the first version returned so that we don't omit inactive versions
maxVersionOrder = 0
} else if maxOrderOpt == 0 {
// If we're paginating backwards, use the newest active version as the upper bound
maxVersionOrder = activeVersions[0].RevisionOrderNumber
}

Expand All @@ -1027,16 +1035,18 @@ func (r *queryResolver) Waterfall(ctx context.Context, options WaterfallOptions)
}

waterfallVersions := groupInactiveVersions(activeVersionIds, allVersions)
bv := []*model.WaterfallBuildVariant{}

buildVariants, err := model.GetWaterfallBuildVariants(ctx, activeVersionIds)
if err != nil {
return nil, InternalServerError.Send(ctx, fmt.Sprintf("getting waterfall build variants: %s", err.Error()))
}
if len(activeVersionIds) > 0 {
buildVariants, err := model.GetWaterfallBuildVariants(ctx, activeVersionIds)
if err != nil {
return nil, InternalServerError.Send(ctx, fmt.Sprintf("getting waterfall build variants: %s", err.Error()))
}

bv := []*model.WaterfallBuildVariant{}
for _, b := range buildVariants {
bCopy := b
bv = append(bv, &bCopy)
for _, b := range buildVariants {
bCopy := b
bv = append(bv, &bCopy)
}
}

// Return the min and max orders returned to be used as parameters for navigating to the next page
Expand Down
34 changes: 32 additions & 2 deletions graphql/tests/query/waterfall/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,36 @@
"author": "mohamed.khelif",
"status": "created",
"order": 45
},
{
"_id": "inactive1",
"gitspec": "abc",
"identifier": "mci",
"r": "gitter_request",
"activated": false,
"author": "sophie.stadler",
"status": "inactive",
"order": 1
},
{
"_id": "inactive2",
"gitspec": "abc",
"identifier": "mci",
"r": "gitter_request",
"activated": false,
"author": "sophie.stadler",
"status": "inactive",
"order": 2
},
{
"_id": "inactive3",
"gitspec": "abc",
"identifier": "mci",
"r": "gitter_request",
"activated": false,
"author": "sophie.stadler",
"status": "inactive",
"order": 3
}
],
"tasks": [
Expand Down Expand Up @@ -169,8 +199,8 @@
"identifier": "spruce-identifier"
},
{
"_id": "evergreen",
"identifier": "evergreen"
"_id": "mci",
"identifier": "mci"
}
],
"builds": [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
waterfall(options: { projectIdentifier: "mci" }) {
nextPageOrder
prevPageOrder
versions {
version {
activated
author
id
order
}
inactiveVersions {
activated
author
id
order
}
}
}
}
36 changes: 36 additions & 0 deletions graphql/tests/query/waterfall/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,42 @@
}
}
}
},
{
"query_file": "all_inactive_versions.graphql",
"result": {
"data": {
"waterfall": {
"nextPageOrder": 1,
"prevPageOrder": 0,
"versions": [
{
"version": null,
"inactiveVersions": [
{
"activated": false,
"author": "sophie.stadler",
"id": "inactive3",
"order": 3
},
{
"activated": false,
"author": "sophie.stadler",
"id": "inactive2",
"order": 2
},
{
"activated": false,
"author": "sophie.stadler",
"id": "inactive1",
"order": 1
}
]
}
]
}
}
}
}
]
}
18 changes: 13 additions & 5 deletions model/waterfall.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ func GetActiveWaterfallVersions(ctx context.Context, projectId string, opts Wate

// GetAllWaterfallVersions returns all of a project's versions within an inclusive range of orders.
func GetAllWaterfallVersions(ctx context.Context, projectId string, minOrder int, maxOrder int) ([]Version, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there might be a small bug with the revision order number range, when I load the default Spruce waterfall I see 13 inactive versions at the end (which doesn't show up on the main branch). Comparing with the Project Health page, I think these commits might actually be active so they wouldn't end up being collapsed 👀

Screenshot 2024-10-03 at 11 35 22 AM

if minOrder >= maxOrder {
hasOrderFilters := maxOrder != 0 && minOrder != 0
if hasOrderFilters && minOrder >= maxOrder {
return nil, errors.New("minOrder must be less than maxOrder")
}

Expand All @@ -112,10 +113,17 @@ func GetAllWaterfallVersions(ctx context.Context, projectId string, minOrder int
VersionRequesterKey: bson.M{
"$in": evergreen.SystemVersionRequesterTypes,
},
VersionRevisionOrderNumberKey: bson.M{
"$gte": minOrder,
"$lte": maxOrder,
},
}

if hasOrderFilters {
revisionFilter := bson.M{}
if minOrder != 0 {
revisionFilter["$gte"] = minOrder
}
if maxOrder != 0 {
revisionFilter["$lte"] = maxOrder
}
match[VersionRevisionOrderNumberKey] = revisionFilter
}

pipeline := []bson.M{{"$match": match}}
Expand Down
4 changes: 4 additions & 0 deletions model/waterfall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ func TestGetAllWaterfallVersions(t *testing.T) {
assert.NoError(t, err)
require.Len(t, versions, 1)
assert.EqualValues(t, "v_1", versions[0].Id)

versions, err = GetAllWaterfallVersions(ctx, p.Id, 0, 0)
assert.NoError(t, err)
require.Len(t, versions, 5)
}

func TestGetWaterfallBuildVariants(t *testing.T) {
Expand Down
Loading