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 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 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
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
51 changes: 51 additions & 0 deletions chaoscenter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# NOTE - These will be executed when any make target is invoked.
#
IS_DOCKER_INSTALLED = $(shell which docker >> /dev/null 2>&1; echo $$?)
SHELL := /bin/bash

.PHONY: help
help:
Expand Down Expand Up @@ -61,6 +62,31 @@ backend-services-checks:
&& exit 1; \
fi
@echo "------------------"
@echo "--> Check chaos-center graphql-server [aws documentDB support operator]"
@echo "------------------"
@curl -Os https://raw.githubusercontent.com/awslabs/amazon-documentdb-tools/master/compat-tool/compat.py
@result=$$(python3 compat.py --version 5.0 --directory graphql/server); \
if echo "$${result}" | grep -qi 'unsupported operators were found'; then \
echo "$${result}" | awk '/unsupported operators were found/ {f=1} f' \
&& exit 1; \
fi
@lookupResults=""; \
while read file; do \
fileLookupResult=$$(awk 'BEGIN {found_lookup=0} \
/\$$lookup/ {found_lookup=1} \
found_lookup && NF==0 {found_lookup=0} \
found_lookup && /"let"|"pipeline"/ { \
print "Found let or pipeline in file " FILENAME " at line " NR; \
}' "$${file}"); \
if [ -n "$${fileLookupResult}" ]; then \
lookupResults="$${lookupResults}$${fileLookupResult}\n"; \
fi; \
done < <(find graphql/server -name "*.go"); \
if [ -n "$${lookupResults}" ]; then \
echo -e "$${lookupResults}" \
&& exit 1; \
fi
@echo "------------------"
@echo "--> Check chaos-center authentication [go mod tidy]"
@echo "------------------"
@tidyRes=$$(cd authentication && go mod tidy); \
Expand All @@ -70,6 +96,31 @@ backend-services-checks:
&& exit 1; \
fi
@echo "------------------"
@echo "--> Check chaos-center authentication [aws documentDB support operator]"
@echo "------------------"
@curl -Os https://raw.githubusercontent.com/awslabs/amazon-documentdb-tools/master/compat-tool/compat.py
@result=$$(python3 compat.py --version 5.0 --directory authentication); \
if echo "$${result}" | grep -qi 'unsupported operators were found'; then \
echo "$${result}" | awk '/unsupported operators were found/ {f=1} f' \
&& exit 1; \
fi
@lookupResults=""; \
while read file; do \
fileLookupResult=$$(awk 'BEGIN {found_lookup=0} \
/\$$lookup/ {found_lookup=1} \
found_lookup && NF==0 {found_lookup=0} \
found_lookup && /"let"|"pipeline"/ { \
print "Found let or pipeline in file " FILENAME " at line " NR; \
}' "$${file}"); \
if [ -n "$${fileLookupResult}" ]; then \
lookupResults="$${lookupResults}$${fileLookupResult}\n"; \
fi; \
done < <(find authentication -name "*.go"); \
if [ -n "$${lookupResults}" ]; then \
echo -e "$${lookupResults}" \
&& exit 1; \
fi
@echo "------------------"
@echo "--> Check chaos-center subscriber [go mod tidy]"
@echo "------------------"
@tidyRes=$$(cd subscriber && go mod tidy); \
Expand Down
31 changes: 17 additions & 14 deletions chaoscenter/authentication/api/utils/project_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,25 +184,28 @@ func CreateSortStage(sort *entities.SortInput) bson.D {
}
}

func CreatePaginationStage(pagination *entities.Pagination) []bson.D {
func CreatePaginationStage(pagination *entities.Pagination) ([]bson.D, int, int) {
var stages []bson.D
skip := 0
limit := 10

if pagination != nil {
page := pagination.Page
limit := pagination.Limit
limit = pagination.Limit

// upper limit of 50 to prevent exceeding max limit 16mb
if pagination.Limit > 50 {
if limit > 50 {
limit = 50
}
stages = append(stages, bson.D{
{"$skip", page * limit},
})
stages = append(stages, bson.D{
{"$limit", limit},
})
} else {
stages = append(stages, bson.D{
{"$limit", 10},
})
skip = page * limit
}
return stages

stages = append(stages, bson.D{
{"$skip", skip},
})
stages = append(stages, bson.D{{
"$limit", limit},
})

return stages, skip, limit
}
42 changes: 25 additions & 17 deletions chaoscenter/authentication/pkg/project/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,29 @@ func (r repository) GetProjectsByUserID(request *entities.ListProjectRequest) (*
pipeline = append(pipeline, sortStage)
}

// Pagination stages
paginationStages := project_utils.CreatePaginationStage(request.Pagination)

// Facet stage to count total projects and paginate results
facetStage := bson.D{
{"$facet", bson.D{
{"totalCount", bson.A{
bson.D{{"$count", "totalNumberOfProjects"}},
}},
{"projects", append(mongo.Pipeline{}, paginationStages...)},
// Pagination stage
_, skip, limit := project_utils.CreatePaginationStage(request.Pagination)

// Count total project and get top-level document to array
countStage := bson.D{
{"$group", bson.D{
{"_id", nil},
{"totalNumberOfProjects", bson.D{{"$sum", 1}}},
{"projects", bson.D{{"$push", "$$ROOT"}}},
}},
}
pipeline = append(pipeline, facetStage)

// Paging results
pagingStage := bson.D{
{"$project", bson.D{
{"_id", 0},
{"totalNumberOfProjects", 1},
{"projects", bson.D{
{"$slice", bson.A{"$projects", skip, limit}},
}},
}}}

pipeline = append(pipeline, countStage, pagingStage)

// Execute the aggregate pipeline
cursor, err := r.Collection.Aggregate(ctx, pipeline)
Expand All @@ -115,10 +125,8 @@ func (r repository) GetProjectsByUserID(request *entities.ListProjectRequest) (*

// Extract results
var result struct {
TotalCount []struct {
TotalNumberOfProjects int64 `bson:"totalNumberOfProjects"`
} `bson:"totalCount"`
Projects []*entities.Project `bson:"projects"`
TotalNumberOfProjects int64 `bson:"totalNumberOfProjects"`
Projects []*entities.Project `bson:"projects"`
}

if cursor.Next(ctx) {
Expand All @@ -128,8 +136,8 @@ func (r repository) GetProjectsByUserID(request *entities.ListProjectRequest) (*
}

var totalNumberOfProjects int64
if len(result.TotalCount) > 0 {
totalNumberOfProjects = result.TotalCount[0].TotalNumberOfProjects
if result.TotalNumberOfProjects > 0 {
totalNumberOfProjects = result.TotalNumberOfProjects
} else {
zero := int64(0)
return &entities.ListProjectResponse{
Expand Down
Loading
Loading