Skip to content

Commit

Permalink
multi error resolution (#277)
Browse files Browse the repository at this point in the history
* multi error resolution

* lint fix

* revert

Signed-off-by: J Yash Sakariya Jain <[email protected]>

---------

Signed-off-by: J Yash Sakariya Jain <[email protected]>
  • Loading branch information
yashjaind11 authored Jan 24, 2025
1 parent e662ae6 commit 7a51646
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions internal/service/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (e *Component) OperateComponent(ctx *context.Context, request *serviceProto
}
if response != nil {
message = util.GenerateResponseMessageComponentSpecific(response.GetServiceResponse(), []string{request.GetComponentName()})
logFailedComponentMessagesOnceForComponents(response.GetServiceResponse(), []string{request.GetComponentName()})
spinnerInstance.Prefix = fmt.Sprintf(" %s ", message)
spinnerInstance.Start()
}
Expand Down
18 changes: 18 additions & 0 deletions internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ func logFailedComponentMessagesOnce(response *serviceProto.ServiceResponse) {
}
}

func logFailedComponentMessagesOnceForComponents(response *serviceProto.ServiceResponse, components []string) {
for _, compMessage := range response.ComponentsStatus {
componentActionKey := compMessage.GetComponentName() + compMessage.GetComponentAction() + compMessage.GetComponentStatus()
//code to not print the same message for component action again
if responseMap[componentActionKey] == "" {
if util.Contains(compMessage.ComponentName, components) {
if compMessage.GetComponentStatus() == "FAILED" {
log.Error(fmt.Sprintf("Component %s %s %s %s", compMessage.GetComponentName(), compMessage.GetComponentAction(), compMessage.GetComponentStatus(), compMessage.GetError()))
}
responseMap[componentActionKey] = componentActionKey
}
}
}
}

// DeployServiceSet deploys service-set
func (e *Service) DeployServiceSet(ctx *context.Context, request *serviceProto.DeployServiceSetRequest) error {
conn, requestCtx, err := grpcClient(ctx)
Expand Down Expand Up @@ -178,6 +193,7 @@ func (e *Service) DeployReleasedService(ctx *context.Context, request *servicePr
for _, compMessage := range response.GetServiceResponse().ComponentsStatus {
message += fmt.Sprintf("\n Component %s %s %s", compMessage.ComponentName, compMessage.ComponentAction, compMessage.ComponentStatus)
}
logFailedComponentMessagesOnce(response.GetServiceResponse())
spinnerInstance.Prefix = fmt.Sprintf(" %s ", message)
spinnerInstance.Start()
}
Expand Down Expand Up @@ -224,6 +240,7 @@ func (e *Service) UndeployService(ctx *context.Context, request *serviceProto.Un
for _, compMessage := range response.ServiceResponse.ComponentsStatus {
message += fmt.Sprintf("\n Component %s %s %s", compMessage.ComponentName, compMessage.ComponentAction, compMessage.ComponentStatus)
}
logFailedComponentMessagesOnce(response.GetServiceResponse())
spinnerInstance.Prefix = fmt.Sprintf(" %s ", message)
spinnerInstance.Start()
}
Expand Down Expand Up @@ -267,6 +284,7 @@ func (e *Service) OperateService(ctx *context.Context, request *serviceProto.Ope
for _, compMessage := range response.ServiceResponse.ComponentsStatus {
message += fmt.Sprintf("\n Component %s %s %s", compMessage.ComponentName, compMessage.ComponentAction, compMessage.ComponentStatus)
}
logFailedComponentMessagesOnce(response.GetServiceResponse())
spinnerInstance.Prefix = fmt.Sprintf(" %s ", message)
spinnerInstance.Start()
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ func calculateDuration(parsedTime time.Time) string {
}
}

// contains checks if a string is present in an array of strings
func contains(str string, arr []string) bool {
// Contains checks if a string is present in a slice of strings.
func Contains(str string, arr []string) bool {
for _, item := range arr {
if item == str {
return true
Expand All @@ -128,8 +128,8 @@ func contains(str string, arr []string) bool {
func GenerateResponseMessageComponentSpecific(response *v1.ServiceResponse, components []string) string {
message := fmt.Sprintf("\n Service %s %s", response.ServiceStatus.ServiceAction, response.ServiceStatus)
for _, compMessage := range response.ComponentsStatus {
if contains(compMessage.ComponentName, components) {
message += fmt.Sprintf("\n Component %s %s %s %s", compMessage.ComponentName, compMessage.ComponentAction, compMessage.ComponentStatus, compMessage.Error)
if Contains(compMessage.ComponentName, components) {
message += fmt.Sprintf("\n Component %s %s %s", compMessage.ComponentName, compMessage.ComponentAction, compMessage.ComponentStatus)
}
}
return message
Expand Down

0 comments on commit 7a51646

Please sign in to comment.