Skip to content

Commit

Permalink
Fixed issue with updating audit fields in recent experiment runs (#4172)
Browse files Browse the repository at this point in the history
* fixed mongo schema decode issue

Signed-off-by: Saranya-jena <[email protected]>

* updated the same in other fields

Signed-off-by: Saranya-jena <[email protected]>

* fixed css

Signed-off-by: Saranya-jena <[email protected]>

---------

Signed-off-by: Saranya-jena <[email protected]>
  • Loading branch information
Saranya-jena authored Sep 15, 2023
1 parent afd2ac6 commit 42d3e85
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 22 deletions.
12 changes: 9 additions & 3 deletions chaoscenter/graphql/server/pkg/chaos_experiment/ops/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ func (c *chaosExperimentService) ProcessExperimentUpdate(workflow *model.ChaosEx
{"description", workflow.ExperimentDescription},
{"is_custom_experiment", workflow.IsCustomExperiment},
{"updated_at", time.Now().UnixMilli()},
{"updated_by", username},
{"updated_by", mongodb.UserDetailResponse{
Username: username,
}},
}},
{"$push", bson.D{
{"revision", workflowRevision},
Expand All @@ -267,7 +269,9 @@ func (c *chaosExperimentService) ProcessExperimentUpdate(workflow *model.ChaosEx
update = bson.D{
{"$set", bson.D{
{"updated_at", time.Now().UnixMilli()},
{"updated_by", username},
{"updated_by", mongodb.UserDetailResponse{
Username: username,
}},
{"revision.$.updated_at", time.Now().UnixMilli()},
{"revision.$.experiment_manifest", workflow.ExperimentManifest},
}},
Expand Down Expand Up @@ -313,7 +317,9 @@ func (c *chaosExperimentService) ProcessExperimentDelete(query bson.D, workflow
update := bson.D{
{"$set", bson.D{
{"is_removed", true},
{"updated_by", username},
{"updated_by", mongodb.UserDetailResponse{
Username: username,
}},
{"updated_at", time.Now().UnixMilli()},
}},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,9 @@ func (c *ChaosExperimentRunHandler) ChaosExperimentRunEvent(event model.Experime
{"recent_experiment_run_details.notify_id", event.NotifyID},
}
}

updatedByModel := mongodb.UserDetailResponse{
Username: string(updatedBy),
}
update := bson.D{
{
"$set", bson.D{
Expand All @@ -1235,7 +1237,7 @@ func (c *ChaosExperimentRunHandler) ChaosExperimentRunEvent(event model.Experime
{"recent_experiment_run_details.$.probes", probes},
{"recent_experiment_run_details.$.resiliency_score", workflowRunMetrics.ResiliencyScore},
{"recent_experiment_run_details.$.updated_at", currentTime.UnixMilli()},
{"recent_experiment_run_details.$.updated_by", string(updatedBy)},
{"recent_experiment_run_details.$.updated_by", updatedByModel},
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"strings"
"time"

"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb"

"github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/chaos_infrastructure"

dbChaosExperimentRun "github.com/litmuschaos/litmus/chaoscenter/graphql/server/pkg/database/mongodb/chaos_experiment_run"
Expand Down Expand Up @@ -49,7 +51,9 @@ func (c *chaosExperimentRunService) ProcessExperimentRunDelete(ctx context.Conte
{"$set", bson.D{
{"is_removed", experimentRun.IsRemoved},
{"updated_at", time.Now().UnixMilli()},
{"updated_by", username},
{"updated_by", mongodb.UserDetailResponse{
Username: username,
}},
}},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ func (in *infraService) DeleteInfra(ctx context.Context, projectID string, infra
{"$set", bson.D{
{"is_removed", true},
{"updated_at", time.Now().UnixMilli()},
{"updated_by", username},
{"updated_by", mongodb.UserDetailResponse{
Username: username,
}},
}},
}
err = in.infraOperator.UpdateInfra(context.TODO(), query, update)
Expand Down
8 changes: 6 additions & 2 deletions chaoscenter/graphql/server/pkg/chaoshub/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,9 @@ func (c *chaosHubService) UpdateChaosHub(ctx context.Context, chaosHub model.Upd
{"ssh_private_key", chaosHub.SSHPrivateKey},
{"ssh_public_key", chaosHub.SSHPublicKey},
{"updated_at", time},
{"updated_by", username},
{"updated_by", mongodb.UserDetailResponse{
Username: username,
}},
},
},
}
Expand Down Expand Up @@ -419,7 +421,9 @@ func (c *chaosHubService) DeleteChaosHub(ctx context.Context, hubID string, proj
{"$set", bson.D{
{"is_removed", true},
{"updated_at", time.Now().UnixMilli()},
{"updated_by", username},
{"updated_by", mongodb.UserDetailResponse{
Username: username,
}},
},
},
}
Expand Down
14 changes: 7 additions & 7 deletions chaoscenter/graphql/server/pkg/database/mongodb/probe/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ type Probes struct {
}

type ExecutionHistory struct {
ExperimentID string `bson:"experiment_id"`
ExperimentName string `bson:"experiment_name"`
UpdatedBy string `bson:"updated_by"`
ExecutionData string `bson:"execution_data"`
UpdatedAt int `bson:"updated_at"`
Probes []Probes `bson:"probes"`
Phase model.ExperimentRunStatus `bson:"phase"`
ExperimentID string `bson:"experiment_id"`
ExperimentName string `bson:"experiment_name"`
UpdatedBy mongodb.UserDetailResponse `bson:"updated_by"`
ExecutionData string `bson:"execution_data"`
UpdatedAt int `bson:"updated_at"`
Probes []Probes `bson:"probes"`
Phase model.ExperimentRunStatus `bson:"phase"`
}

type ProbeWithExecutionHistory struct {
Expand Down
8 changes: 6 additions & 2 deletions chaoscenter/graphql/server/pkg/environment/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ func (e *EnvironmentService) UpdateEnvironment(ctx context.Context, projectID st
updateQuery = append(updateQuery, bson.E{
Key: "$set", Value: bson.D{
{"updated_at", time.Now().UnixMilli()},
{"updated_by", username},
{"updated_by", mongodb.UserDetailResponse{
Username: username,
}},
},
})
if request.Name != nil {
Expand Down Expand Up @@ -176,7 +178,9 @@ func (e *EnvironmentService) DeleteEnvironment(ctx context.Context, projectID st
{"$set", bson.D{
{"is_removed", true},
{"updated_at", currTime},
{"updated_by", username},
{"updated_by", mongodb.UserDetailResponse{
Username: username,
}},
}},
}
err = e.EnvironmentOperator.UpdateEnvironment(context.TODO(), query, update)
Expand Down
6 changes: 4 additions & 2 deletions chaoscenter/graphql/server/pkg/probe/respository.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,9 @@ func (p *probe) DeleteProbe(ctx context.Context, probeName string) (bool, error)
{"$set", bson.D{
{"is_removed", true},
{"updated_at", Time},
{"updated_by", username},
{"updated_by", mongodb.UserDetailResponse{
Username: username,
}},
}},
}

Expand Down Expand Up @@ -884,7 +886,7 @@ func (p *probe) GetProbeReference(ctx context.Context, probeName string) (*model
ExperimentName: runs.ExperimentName,
UpdatedAt: runs.UpdatedAt,
UpdatedBy: &model.UserDetails{
Username: runs.UpdatedBy,
Username: runs.UpdatedBy.Username,
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion chaoscenter/web/src/views/Gitops/Gitops.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default function GitopsView({
return (
<DefaultLayout
headerToolbar={
<Layout.Horizontal flex={{ distribution: 'space-between' }} width="12%">
<Layout.Horizontal flex={{ distribution: 'space-between' }} style={{ gap: '0.5rem' }}>
<RbacButton
intent="primary"
data-testid="gitops"
Expand Down
2 changes: 1 addition & 1 deletion chaoscenter/web/src/views/ImageRegistry/ImageRegistry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default function ImageRegistryView({
return (
<DefaultLayout
headerToolbar={
<Layout.Horizontal flex={{ distribution: 'space-between' }} width="12%">
<Layout.Horizontal flex={{ distribution: 'space-between' }} style={{ gap: '0.5rem' }}>
<RbacButton
intent="primary"
data-testid="save-image-registry"
Expand Down

0 comments on commit 42d3e85

Please sign in to comment.