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

multi error resolution #277

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change of capital name only ?

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
Loading