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

Support DocumentDB by replacing certain MongoDB operations #4886

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1bf1fdf
Refactor using default page values
kwx4957 Aug 27, 2024
6f6141f
Feat replace mongodb operation $facet for support aws documentDB
kwx4957 Aug 27, 2024
f1ea9a8
Refactor extract common pagination feature
kwx4957 Aug 27, 2024
93d6a6c
Feat replace mongodb operation $facet for support aws documentDB
kwx4957 Aug 27, 2024
342d0ad
Feat replace mongodb operation $facet for support aws documentDB
kwx4957 Aug 27, 2024
4bdaad1
Feat replace mongodb operation $facet for support aws documentDB
kwx4957 Aug 27, 2024
05bb505
Feat replace mongodb operation $facet for support aws documentDB
kwx4957 Aug 27, 2024
82e28c7
Feat replace mongodb operation $facet for support aws documentDB
kwx4957 Aug 27, 2024
890f9de
Fix change reposne struect type
kwx4957 Aug 27, 2024
b91f7d5
Feat replace mongodb operation $facet for support aws documentDB
kwx4957 Aug 27, 2024
858f03c
Feat replace mongodb operation $facet for support aws documentDB
kwx4957 Aug 28, 2024
289b6bc
Fix return type String to int in groupByResScoreStage
kwx4957 Aug 31, 2024
ee27c4a
Fix ListExperimentRun test code expect array to int
kwx4957 Aug 31, 2024
15df6b2
Feat replace mongodb operation $facet for support aws documentDB
kwx4957 Aug 31, 2024
73607c9
Feat replace mongodb operation $facet for support aws documentDB
kwx4957 Aug 31, 2024
d23954a
Fix null pointer error
kwx4957 Sep 5, 2024
4bd1652
Merge remote-tracking branch 'upstream/master' into feat/documentdb
kwx4957 Sep 14, 2024
731e22b
Feat separte pipeline in $lookup
kwx4957 Sep 14, 2024
42894de
Feat separte pipeline to match and addField in $lookup
kwx4957 Sep 15, 2024
7639c87
Feat separte pipeline to match and project in $lookup
kwx4957 Sep 15, 2024
19d9dfd
Feat separte pipeline to project in $lookup
kwx4957 Sep 15, 2024
d232159
Feat separte pipeline to addField in $lookup
kwx4957 Sep 15, 2024
526cbf0
Add pre-commit check for aws documentDB
kwx4957 Sep 15, 2024
dc74d1b
Fix goimports
kwx4957 Sep 16, 2024
2c0848c
Add pre-commit check $lookup multiple join
kwx4957 Sep 16, 2024
9cb3bc2
Fix missing execution_data field added
kwx4957 Sep 17, 2024
839c3a3
Fix missing revision.execution_manifest field added
kwx4957 Sep 17, 2024
1169a34
Fix filtering condition for AWS DocumentDB compatibility
kwx4957 Sep 29, 2024
0ef2ffe
Merge remote-tracking branch 'upstream/master' into feat/documentdb
kwx4957 Dec 24, 2024
f14f36f
fix: multiple document to one document
kwx4957 Dec 26, 2024
83e8b1c
style: rename variable
kwx4957 Jan 3, 2025
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
Prev Previous commit
Next Next commit
Feat replace mongodb operation $facet for support aws documentDB
Replace $facet to $group and $project
Change the result type. return type has changed
Extract common pagination feature

Signed-off-by: DongYoung Kim <kwx4957@gmail.com>
kwx4957 committed Sep 8, 2024
commit 93d6a6c384e000dfd2af265fa535df889ea35479
Original file line number Diff line number Diff line change
@@ -23,6 +23,6 @@ type TotalFilteredData struct {
}

type AggregatedEnvironments struct {
TotalFilteredEnvironments []TotalFilteredData `bson:"total_filtered_environments"`
Environments []Environment `bson:"environments"`
TotalFilteredEnvironments int `bson:"total_filtered_environments"`
Environments []Environment `bson:"environments"`
}
54 changes: 25 additions & 29 deletions chaoscenter/graphql/server/pkg/environment/handler/handler.go
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import (

"github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph/model"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb/common"
"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb/environments"
dbOperationsEnvironment "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb/environments"
"go.mongodb.org/mongo-driver/bson"
@@ -319,38 +320,32 @@ func (e *EnvironmentService) ListEnvironments(projectID string, request *model.L
}
}

// Pagination or adding a default limit of 15 if pagination not provided
paginatedExperiments := bson.A{
sortStage,
}

if request.Pagination != nil {
paginationSkipStage := bson.D{
{"$skip", request.Pagination.Page * request.Pagination.Limit},
}
paginationLimitStage := bson.D{
{"$limit", request.Pagination.Limit},
}
pipeline = append(pipeline, sortStage)

paginatedExperiments = append(paginatedExperiments, paginationSkipStage, paginationLimitStage)
} else {
limitStage := bson.D{
{"$limit", 15},
}

paginatedExperiments = append(paginatedExperiments, limitStage)
// Pagination or adding a default limit of 15 if pagination not provided
_, skip, limit := common.CreatePaginationStage(request.Pagination)

// Count total project and get top-level document to array
countStage := bson.D{
{"$group", bson.D{
{"_id", nil},
{"total_filtered_environments", bson.D{{"$sum", 1}}},
{"environments", bson.D{{"$push", "$$ROOT"}}},
}},
}

// Add two stages where we first count the number of filtered workflow and then paginate the results
facetStage := bson.D{
{"$facet", bson.D{
{"total_filtered_environments", bson.A{
bson.D{{"$count", "count"}},
// Paging results
pagingStage := bson.D{
{"$project", bson.D{
{"_id", 0},
{"total_filtered_environments", 1},
{"environments", bson.D{
{"$slice", bson.A{"$environments", skip, limit}},
}},
{"environments", paginatedExperiments},
}},
}
pipeline = append(pipeline, facetStage)

pipeline = append(pipeline, countStage, pagingStage)

cursor, err := e.EnvironmentOperator.GetAggregateEnvironments(pipeline)
if err != nil {
@@ -362,12 +357,13 @@ func (e *EnvironmentService) ListEnvironments(projectID string, request *model.L
aggregatedEnvironments []environments.AggregatedEnvironments
)

if err = cursor.All(context.Background(), &aggregatedEnvironments); err != nil || len(aggregatedEnvironments) == 0 {
if err = cursor.All(context.Background(), &aggregatedEnvironments); err != nil {
return &model.ListEnvironmentResponse{
TotalNoOfEnvironments: 0,
Environments: envs,
}, errors.New("error decoding environment cursor: " + err.Error())
}

if len(aggregatedEnvironments) == 0 {
return &model.ListEnvironmentResponse{
TotalNoOfEnvironments: 0,
@@ -393,8 +389,8 @@ func (e *EnvironmentService) ListEnvironments(projectID string, request *model.L
}

totalFilteredEnvironmentsCounter := 0
if len(envs) > 0 && len(aggregatedEnvironments[0].TotalFilteredEnvironments) > 0 {
totalFilteredEnvironmentsCounter = aggregatedEnvironments[0].TotalFilteredEnvironments[0].Count
if len(envs) > 0 && aggregatedEnvironments[0].TotalFilteredEnvironments > 0 {
totalFilteredEnvironmentsCounter = aggregatedEnvironments[0].TotalFilteredEnvironments
}

output := model.ListEnvironmentResponse{