Skip to content

Commit

Permalink
fix: multiple document to one document
Browse files Browse the repository at this point in the history
Signed-off-by: DongYoung Kim <kwx4957@gmail.com>
  • Loading branch information
kwx4957 committed Dec 26, 2024
1 parent 0ef2ffe commit f14f36f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
35 changes: 22 additions & 13 deletions chaoscenter/graphql/server/pkg/chaos_experiment/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,8 @@ func (c *ChaosExperimentHandler) ListExperiment(projectID string, request model.
workflows []dbChaosExperiment.AggregatedExperiments
)

// ListExep, GetGetExperimentStats, ListExperimentRun, ListEnvironments

if err = workflowsCursor.All(context.Background(), &workflows); err != nil {
return &model.ListExperimentResponse{
TotalNoOfExperiments: 0,
Expand Down Expand Up @@ -1125,20 +1127,27 @@ func (c *ChaosExperimentHandler) GetExperimentStats(ctx context.Context, project

pipeline = append(pipeline, groupByResiliencyScore)

ddStage := bson.D{
{"$group", bson.D{
{"_id", nil},
{"total_experiments", bson.D{
{"$first", "$total_experiments"},
}},
{"categorized_by_resiliency_score",
bson.D{
{"$push", bson.D{
{"_id", "$_id"},
{"count", "$count"},
}},
}},
}},
}

pipeline = append(pipeline, ddStage)

projectStage := bson.D{
{"$project", bson.D{
{"_id", 0},
{"by_resiliency_score", bson.A{
bson.D{
{"_id", "$_id"},
{"count", "$count"},
},
}},
{"total_experiments", bson.A{
bson.D{
{"count", "$total_experiments"},
},
}},
}},
}

Expand All @@ -1165,8 +1174,8 @@ func (c *ChaosExperimentHandler) GetExperimentStats(ctx context.Context, project
return result, nil
}

if len(res[0].TotalExperiments) > 0 {
result.TotalExperiments = res[0].TotalExperiments[0].Count
if res[0].TotalExperiments > 0 {
result.TotalExperiments = res[0].TotalExperiments
}

if len(res[0].TotalFilteredExperiments) > 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ type CategorizedExperimentRunStats struct {
}

type AggregatedExperimentStats struct {
TotalExperiments []TotalFilteredData `bson:"total_experiments"`
TotalExperiments int `bson:"total_experiments"`
TotalFilteredExperiments []CategorizedExperimentRunStats `bson:"categorized_by_resiliency_score"`
}

Expand Down

0 comments on commit f14f36f

Please sign in to comment.