Skip to content

Commit

Permalink
Fixed issue with mongo watch events in graphql server (#4160)
Browse files Browse the repository at this point in the history
* Fixed issue with mongo watch events to add image registry on project creation

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

* Fixed imports

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

* resolved comments

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

* fixed imports

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

---------

Signed-off-by: Saranya-jena <[email protected]>
  • Loading branch information
Saranya-jena authored Sep 13, 2023
1 parent 2cc7d4c commit a64d321
Show file tree
Hide file tree
Showing 12 changed files with 138 additions and 83 deletions.
18 changes: 10 additions & 8 deletions chaoscenter/graphql/server/pkg/chaos_experiment/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,10 +391,12 @@ func (c *ChaosExperimentHandler) GetExperiment(ctx context.Context, projectID st
Phase: v.Phase,
ResiliencyScore: v.ResiliencyScore,
UpdatedBy: &model.UserDetails{
UserID: v.UpdatedBy,
Username: v.UpdatedBy.Username,
UserID: v.UpdatedBy.UserID,
},
CreatedBy: &model.UserDetails{
UserID: v.CreatedBy,
Username: v.CreatedBy.Username,
UserID: v.CreatedBy.UserID,
},
UpdatedAt: strconv.FormatInt(v.UpdatedAt, 10),
CreatedAt: strconv.FormatInt(v.CreatedAt, 10),
Expand Down Expand Up @@ -424,10 +426,10 @@ func (c *ChaosExperimentHandler) GetExperiment(ctx context.Context, projectID st
IsRemoved: exp.IsRemoved,
Infra: chaosInfrastructure,
UpdatedBy: &model.UserDetails{
Username: exp.UpdatedBy,
Username: exp.UpdatedBy.Username,
},
CreatedBy: &model.UserDetails{
Username: exp.UpdatedBy,
Username: exp.UpdatedBy.Username,
},
RecentExperimentRunDetails: recentExpRuns,
},
Expand Down Expand Up @@ -754,10 +756,10 @@ func (c *ChaosExperimentHandler) ListExperiment(projectID string, request model.
Phase: v.Phase,
ResiliencyScore: v.ResiliencyScore,
UpdatedBy: &model.UserDetails{
Username: v.UpdatedBy,
Username: v.UpdatedBy.Username,
},
CreatedBy: &model.UserDetails{
Username: v.UpdatedBy,
Username: v.UpdatedBy.Username,
},
UpdatedAt: strconv.FormatInt(v.UpdatedAt, 10),
CreatedAt: strconv.FormatInt(v.CreatedAt, 10),
Expand All @@ -781,10 +783,10 @@ func (c *ChaosExperimentHandler) ListExperiment(projectID string, request model.
IsRemoved: workflow.IsRemoved,
Infra: chaosInfrastructure,
UpdatedBy: &model.UserDetails{
Username: workflow.UpdatedBy,
Username: workflow.UpdatedBy.Username,
},
CreatedBy: &model.UserDetails{
Username: workflow.UpdatedBy,
Username: workflow.UpdatedBy.Username,
},
RecentExperimentRunDetails: recentExpRuns,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,12 @@ func (c *chaosExperimentService) ProcessExperimentCreation(ctx context.Context,
CreatedAt: timeNow,
UpdatedAt: timeNow,
IsRemoved: false,
CreatedBy: username,
UpdatedBy: username,
CreatedBy: mongodb.UserDetailResponse{
Username: username,
},
UpdatedBy: mongodb.UserDetailResponse{
Username: username,
},
},
Revision: revision,
RecentExperimentRunDetails: []dbChaosExperiment.ExperimentRunDetail{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (c *ChaosExperimentRunHandler) GetExperimentRun(ctx context.Context, projec
RunSequence: int(wfRun.RunSequence),

UpdatedBy: &model.UserDetails{
Username: wfRun.UpdatedBy,
Username: wfRun.UpdatedBy.Username,
},
UpdatedAt: strconv.FormatInt(wfRun.UpdatedAt, 10),
CreatedAt: strconv.FormatInt(wfRun.CreatedAt, 10),
Expand Down Expand Up @@ -621,7 +621,7 @@ func (c *ChaosExperimentRunHandler) ListExperimentRun(projectID string, request
ExecutionData: workflow.ExecutionData,
IsRemoved: &workflow.IsRemoved,
UpdatedBy: &model.UserDetails{
Username: workflow.UpdatedBy,
Username: workflow.UpdatedBy.Username,
},
UpdatedAt: strconv.FormatInt(workflow.UpdatedAt, 10),
CreatedAt: strconv.FormatInt(workflow.CreatedAt, 10),
Expand Down Expand Up @@ -811,9 +811,13 @@ func (c *ChaosExperimentRunHandler) RunChaosWorkFlow(ctx context.Context, projec
Audit: mongodb.Audit{
IsRemoved: false,
CreatedAt: currentTime,
CreatedBy: username,
CreatedBy: mongodb.UserDetailResponse{
Username: username,
},
UpdatedAt: currentTime,
UpdatedBy: username,
UpdatedBy: mongodb.UserDetailResponse{
Username: username,
},
},
},
}
Expand Down Expand Up @@ -853,9 +857,13 @@ func (c *ChaosExperimentRunHandler) RunChaosWorkFlow(ctx context.Context, projec
Audit: mongodb.Audit{
IsRemoved: false,
CreatedAt: currentTime,
CreatedBy: username,
CreatedBy: mongodb.UserDetailResponse{
Username: username,
},
UpdatedAt: currentTime,
UpdatedBy: username,
UpdatedBy: mongodb.UserDetailResponse{
Username: username,
},
},
NotifyID: &notifyID,
Completed: false,
Expand Down Expand Up @@ -1171,7 +1179,9 @@ func (c *ChaosExperimentRunHandler) ChaosExperimentRunEvent(event model.Experime
IsRemoved: false,
CreatedAt: time.Now().UnixMilli(),
UpdatedAt: time.Now().UnixMilli(),
UpdatedBy: string(updatedBy),
UpdatedBy: mongodb.UserDetailResponse{
Username: string(updatedBy),
},
},
},
}
Expand Down Expand Up @@ -1259,8 +1269,12 @@ func (c *ChaosExperimentRunHandler) ChaosExperimentRunEvent(event model.Experime
Audit: mongodb.Audit{
IsRemoved: isRemoved,
UpdatedAt: currentTime.UnixMilli(),
UpdatedBy: string(updatedBy),
CreatedBy: string(updatedBy),
UpdatedBy: mongodb.UserDetailResponse{
Username: string(updatedBy),
},
CreatedBy: mongodb.UserDetailResponse{
Username: string(updatedBy),
},
},
})
if err != nil {
Expand Down
12 changes: 8 additions & 4 deletions chaoscenter/graphql/server/pkg/chaos_infrastructure/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ func (in *infraService) RegisterInfra(c context.Context, projectID string, input
CreatedAt: currentTime.UnixMilli(),
UpdatedAt: currentTime.UnixMilli(),
IsRemoved: false,
CreatedBy: username,
UpdatedBy: username,
CreatedBy: mongodb.UserDetailResponse{
Username: username,
},
UpdatedBy: mongodb.UserDetailResponse{
Username: username,
},
},
EnvironmentID: input.EnvironmentID,
AccessKey: utils.RandomString(32),
Expand Down Expand Up @@ -685,9 +689,9 @@ func (in *infraService) ListInfras(projectID string, request *model.ListInfraReq
newInfra.NoOfExperiments = &infra.ExperimentDetails[0].TotalSchedules
}

newInfra.CreatedBy = &model.UserDetails{Username: infra.CreatedBy}
newInfra.CreatedBy = &model.UserDetails{Username: infra.CreatedBy.Username}
newInfra.UpdatedBy = &model.UserDetails{
Username: infra.UpdatedBy,
Username: infra.UpdatedBy.Username,
}
newInfras = append(newInfras, &newInfra)

Expand Down
36 changes: 24 additions & 12 deletions chaoscenter/graphql/server/pkg/chaoshub/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ func (c *chaosHubService) AddChaosHub(ctx context.Context, chaosHub model.Create
CreatedAt: currentTime.UnixMilli(),
UpdatedAt: currentTime.UnixMilli(),
IsRemoved: false,
CreatedBy: username,
UpdatedBy: username,
CreatedBy: mongodb.UserDetailResponse{
Username: username,
},
UpdatedBy: mongodb.UserDetailResponse{
Username: username,
},
},
LastSyncedAt: time.Now().UnixMilli(),
IsDefault: false,
Expand Down Expand Up @@ -166,8 +170,12 @@ func (c *chaosHubService) AddRemoteChaosHub(ctx context.Context, chaosHub model.
CreatedAt: currentTime.UnixMilli(),
UpdatedAt: currentTime.UnixMilli(),
IsRemoved: false,
CreatedBy: username,
UpdatedBy: username,
CreatedBy: mongodb.UserDetailResponse{
Username: username,
},
UpdatedBy: mongodb.UserDetailResponse{
Username: username,
},
},
LastSyncedAt: time.Now().UnixMilli(),
IsDefault: false,
Expand Down Expand Up @@ -237,8 +245,12 @@ func (c *chaosHubService) SaveChaosHub(ctx context.Context, chaosHub model.Creat
CreatedAt: currentTime.UnixMilli(),
UpdatedAt: currentTime.UnixMilli(),
IsRemoved: false,
CreatedBy: username,
UpdatedBy: username,
CreatedBy: mongodb.UserDetailResponse{
Username: username,
},
UpdatedBy: mongodb.UserDetailResponse{
Username: username,
},
},
LastSyncedAt: time.Now().UnixMilli(),
}
Expand Down Expand Up @@ -634,8 +646,8 @@ func (c *chaosHubService) ListChaosHubs(ctx context.Context, projectID string, r
TotalExperiments: strconv.Itoa(experimentCount),
CreatedAt: strconv.Itoa(int(hub.CreatedAt)),
UpdatedAt: strconv.Itoa(int(hub.UpdatedAt)),
CreatedBy: &model.UserDetails{Username: hub.CreatedBy},
UpdatedBy: &model.UserDetails{Username: hub.UpdatedBy},
CreatedBy: &model.UserDetails{Username: hub.CreatedBy.Username},
UpdatedBy: &model.UserDetails{Username: hub.UpdatedBy.Username},
}
hubDetails = append(hubDetails, hubDetail)
}
Expand Down Expand Up @@ -694,8 +706,8 @@ func (c *chaosHubService) GetChaosHub(ctx context.Context, chaosHubID string, pr
TotalExperiments: strconv.Itoa(experimentCount),
CreatedAt: strconv.Itoa(int(hub.CreatedAt)),
UpdatedAt: strconv.Itoa(int(hub.UpdatedAt)),
CreatedBy: &model.UserDetails{Username: hub.CreatedBy},
UpdatedBy: &model.UserDetails{Username: hub.UpdatedBy},
CreatedBy: &model.UserDetails{Username: hub.CreatedBy.Username},
UpdatedBy: &model.UserDetails{Username: hub.UpdatedBy.Username},
}

return hubDetail, nil
Expand Down Expand Up @@ -755,8 +767,8 @@ func (c *chaosHubService) getChaosHubDetails(ctx context.Context, hubID string,
Tags: hub.Tags,
Description: &hub.Description,
//TODO util functions for this
CreatedBy: &model.UserDetails{Username: hub.CreatedBy},
UpdatedBy: &model.UserDetails{Username: hub.UpdatedBy},
CreatedBy: &model.UserDetails{Username: hub.CreatedBy.Username},
UpdatedBy: &model.UserDetails{Username: hub.UpdatedBy.Username},
}, nil
}

Expand Down
16 changes: 11 additions & 5 deletions chaoscenter/graphql/server/pkg/database/mongodb/common_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ type ResourceDetails struct {
}

type Audit struct {
UpdatedAt int64 `bson:"updated_at"`
CreatedAt int64 `bson:"created_at"`
CreatedBy string `bson:"created_by"`
UpdatedBy string `bson:"updated_by"`
IsRemoved bool `bson:"is_removed"`
UpdatedAt int64 `bson:"updated_at"`
CreatedAt int64 `bson:"created_at"`
CreatedBy UserDetailResponse `bson:"created_by" json:"createdBy"`
UpdatedBy UserDetailResponse `bson:"updated_by" json:"updatedBy"`
IsRemoved bool `bson:"is_removed"`
}

type UserDetailResponse struct {
UserID string `bson:"user_id" json:"userID"`
Username string `bson:"username" json:"username"`
Email string `bson:"email" json:"email"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ func (probe *Probe) GetOutputProbe() *model.Probe {
Type: model.ProbeType(probe.Type),
InfrastructureType: probe.InfrastructureType,
CreatedBy: &model.UserDetails{
Username: probe.CreatedBy,
Username: probe.CreatedBy.Username,
},
UpdatedBy: &model.UserDetails{
Username: probe.UpdatedBy,
Username: probe.UpdatedBy.Username,
},
}
if probe.InfrastructureType == model.InfrastructureTypeKubernetes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Member struct {
UserID string `bson:"user_id"`
Role MemberRole `bson:"role"`
Invitation Invitation `bson:"invitation"`
JoinedAt string `bson:"joined_at"`
JoinedAt int64 `bson:"joined_at"`
}

// MemberRole defines the project role a member has in the project
Expand Down
16 changes: 10 additions & 6 deletions chaoscenter/graphql/server/pkg/environment/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ func (e *EnvironmentService) CreateEnvironment(ctx context.Context, projectID st
CreatedAt: currentTime.UnixMilli(),
UpdatedAt: currentTime.UnixMilli(),
IsRemoved: false,
CreatedBy: username,
UpdatedBy: username,
CreatedBy: mongodb.UserDetailResponse{
Username: username,
},
UpdatedBy: mongodb.UserDetailResponse{
Username: username,
},
},
}

Expand Down Expand Up @@ -203,8 +207,8 @@ func (e *EnvironmentService) GetEnvironment(projectID string, environmentID stri
Type: model.EnvironmentType(env.Type),
CreatedAt: strconv.FormatInt(env.CreatedAt, 10),
UpdatedAt: strconv.FormatInt(env.UpdatedAt, 10),
CreatedBy: &model.UserDetails{Username: env.CreatedBy},
UpdatedBy: &model.UserDetails{Username: env.UpdatedBy},
CreatedBy: &model.UserDetails{Username: env.CreatedBy.Username},
UpdatedBy: &model.UserDetails{Username: env.UpdatedBy.Username},
InfraIDs: env.InfraIDs,
IsRemoved: &env.IsRemoved,
}, nil
Expand Down Expand Up @@ -394,8 +398,8 @@ func (e *EnvironmentService) ListEnvironments(projectID string, request *model.L
Type: model.EnvironmentType(env.Type),
CreatedAt: strconv.FormatInt(env.CreatedAt, 10),
UpdatedAt: strconv.FormatInt(env.UpdatedAt, 10),
CreatedBy: &model.UserDetails{Username: env.CreatedBy},
UpdatedBy: &model.UserDetails{Username: env.UpdatedBy},
CreatedBy: &model.UserDetails{Username: env.CreatedBy.Username},
UpdatedBy: &model.UserDetails{Username: env.UpdatedBy.Username},
InfraIDs: env.InfraIDs,
IsRemoved: &env.IsRemoved,
})
Expand Down
14 changes: 10 additions & 4 deletions chaoscenter/graphql/server/pkg/probe/respository.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ func (p *probe) AddProbe(ctx context.Context, probe model.ProbeRequest) (*model.
CreatedAt: currTime,
UpdatedAt: currTime,
IsRemoved: false,
CreatedBy: username,
UpdatedBy: username,
CreatedBy: mongodb.UserDetailResponse{
Username: username,
},
UpdatedBy: mongodb.UserDetailResponse{
Username: username,
},
},
Type: dbSchemaProbe.ProbeType(probe.Type),
InfrastructureType: probe.InfrastructureType,
Expand Down Expand Up @@ -141,7 +145,9 @@ func (p *probe) UpdateProbe(ctx context.Context, request model.ProbeRequest) (st
UpdatedAt: time.Now().UnixMilli(),
IsRemoved: false,
CreatedBy: pr.CreatedBy,
UpdatedBy: username,
UpdatedBy: mongodb.UserDetailResponse{
Username: username,
},
},
Type: pr.Type,
InfrastructureType: pr.InfrastructureType,
Expand Down Expand Up @@ -702,7 +708,7 @@ func GetProbeExecutionHistoryInExperimentRuns(projectID string, probeName string
ExperimentName: execution.ExperimentName,
UpdatedAt: int(execution.UpdatedAt),
UpdatedBy: &model.UserDetails{
Username: execution.UpdatedBy,
Username: execution.UpdatedBy.Username,
},
},
}
Expand Down
Loading

0 comments on commit a64d321

Please sign in to comment.