Skip to content

Commit

Permalink
Merge pull request #112 from MUzairS15/error-details
Browse files Browse the repository at this point in the history
Send detailed error response to client
  • Loading branch information
Revolyssup committed Aug 26, 2022
2 parents f4891c7 + 067c45a commit 5cd54b9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 30 deletions.
54 changes: 31 additions & 23 deletions appmesh/app_mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import (

"github.com/layer5io/meshery-adapter-library/adapter"
"github.com/layer5io/meshery-adapter-library/common"
"github.com/layer5io/meshery-adapter-library/meshes"
"github.com/layer5io/meshery-adapter-library/status"
"github.com/layer5io/meshery-app-mesh/appmesh/oam"
internalconfig "github.com/layer5io/meshery-app-mesh/internal/config"
meshkitCfg "github.com/layer5io/meshkit/config"
"github.com/layer5io/meshkit/errors"
"github.com/layer5io/meshkit/logger"
"github.com/layer5io/meshkit/models"
"github.com/layer5io/meshkit/models/oam/core/v1alpha1"
Expand Down Expand Up @@ -48,21 +50,22 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat
return err
}

e := &adapter.Event{
Operationid: opReq.OperationID,
e := &meshes.EventsResponse{
OperationId: opReq.OperationID,
Summary: status.Deploying,
Details: "Operation is not supported",
Component: internalconfig.ServerConfig["type"],
ComponentName: internalconfig.ServerConfig["name"],
}
stat := status.Deploying

switch opReq.OperationName {
case internalconfig.AppMeshOperation:
go func(hh *AppMesh, ee *adapter.Event) {
go func(hh *AppMesh, ee *meshes.EventsResponse) {
version := string(operations[opReq.OperationName].Versions[0])
if stat, err = hh.installAppMesh(opReq.IsDeleteOperation, version, opReq.Namespace, kubeConfigs); err != nil {
e.Summary = fmt.Sprintf("Error while %s AWS App mesh", stat)
e.Details = err.Error()
hh.StreamErr(e, err)
summary := fmt.Sprintf("Error while %s AWS App mesh", stat)
hh.streamErr(summary, e, err)
return
}
ee.Summary = fmt.Sprintf("App mesh %s successfully", stat)
Expand All @@ -71,24 +74,23 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat
}(appMesh, e)

case internalconfig.LabelNamespace:
go func(hh *AppMesh, ee *adapter.Event) {
go func(hh *AppMesh, ee *meshes.EventsResponse) {
err := hh.LoadNamespaceToMesh(opReq.Namespace, opReq.IsDeleteOperation, kubeConfigs)
operation := "enabled"
if opReq.IsDeleteOperation {
operation = "removed"
}
if err != nil {
e.Summary = fmt.Sprintf("Error while labelling %s", opReq.Namespace)
e.Details = err.Error()
hh.StreamErr(e, err)
summary := fmt.Sprintf("Error while labelling %s", opReq.Namespace)
hh.streamErr(summary, e, err)
return
}
ee.Summary = fmt.Sprintf("Label updated on %s namespace", opReq.Namespace)
ee.Details = fmt.Sprintf("APP-MESH-INJECTION label %s on %s namespace", operation, opReq.Namespace)
hh.StreamInfo(e)
}(appMesh, e)
case internalconfig.PrometheusAddon, internalconfig.GrafanaAddon:
go func(hh *AppMesh, ee *adapter.Event) {
go func(hh *AppMesh, ee *meshes.EventsResponse) {
svcname := operations[opReq.OperationName].AdditionalProperties[common.ServiceName]
helmChartURL := operations[opReq.OperationName].AdditionalProperties[internalconfig.HelmChartURL]
patches := make([]string, 0)
Expand All @@ -100,23 +102,21 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat
}

if err != nil {
e.Summary = fmt.Sprintf("Error while %sing %s", operation, opReq.OperationName)
e.Details = err.Error()
hh.StreamErr(e, err)
summary := fmt.Sprintf("Error while %sing %s", operation, opReq.OperationName)
hh.streamErr(summary, e, err)
return
}
ee.Summary = fmt.Sprintf("Succesfully %sed %s", operation, opReq.OperationName)
ee.Details = fmt.Sprintf("Succesfully %sed %s from the %s namespace", operation, opReq.OperationName, opReq.Namespace)
hh.StreamInfo(e)
}(appMesh, e)
case common.BookInfoOperation, common.HTTPBinOperation, common.ImageHubOperation, common.EmojiVotoOperation:
go func(hh *AppMesh, ee *adapter.Event) {
go func(hh *AppMesh, ee *meshes.EventsResponse) {
appName := operations[opReq.OperationName].AdditionalProperties[common.ServiceName]
stat, err := hh.installSampleApp(opReq.Namespace, opReq.IsDeleteOperation, operations[opReq.OperationName].Templates, kubeConfigs)
if err != nil {
e.Summary = fmt.Sprintf("Error while %s %s application", stat, appName)
e.Details = err.Error()
hh.StreamErr(e, err)
summary := fmt.Sprintf("Error while %s %s application", stat, appName)
hh.streamErr(summary, e, err)
return
}
ee.Summary = fmt.Sprintf("%s application %s successfully", appName, stat)
Expand All @@ -125,20 +125,19 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat
}(appMesh, e)

case common.CustomOperation:
go func(hh *AppMesh, ee *adapter.Event) {
go func(hh *AppMesh, ee *meshes.EventsResponse) {
stat, err := hh.applyCustomOperation(opReq.Namespace, opReq.CustomBody, opReq.IsDeleteOperation, kubeConfigs)
if err != nil {
e.Summary = fmt.Sprintf("Error while %s custom operation", stat)
e.Details = err.Error()
hh.StreamErr(e, err)
summary := fmt.Sprintf("Error while %s custom operation", stat)
hh.streamErr(summary, e, err)
return
}
ee.Summary = fmt.Sprintf("Manifest %s successfully", status.Deployed)
ee.Details = ""
hh.StreamInfo(e)
}(appMesh, e)
default:
appMesh.StreamErr(e, ErrOpInvalid)
appMesh.streamErr("Invalid operation", e, ErrOpInvalid)

}
return nil
Expand Down Expand Up @@ -245,3 +244,12 @@ func (appMesh *AppMesh) ProcessOAM(ctx context.Context, oamReq adapter.OAMReques

return msg1 + "\n" + msg2, nil
}

func(appMesh *AppMesh) streamErr(summary string, e *meshes.EventsResponse, err error) {
e.Summary = summary
e.Details = err.Error()
e.ErrorCode = errors.GetCode(err)
e.ProbableCause = errors.GetCause(err)
e.SuggestedRemediation = errors.GetRemedy(err)
appMesh.StreamErr(e, err)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ replace (
)

require (
github.com/layer5io/meshery-adapter-library v0.5.8
github.com/layer5io/meshery-adapter-library v0.5.9
github.com/layer5io/meshkit v0.5.32
github.com/layer5io/service-mesh-performance v0.3.4
gopkg.in/yaml.v2 v2.4.0
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -852,12 +852,8 @@ github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6Fm
github.com/layer5io/kuttl v0.4.1-0.20200723152044-916f10574334/go.mod h1:UmrVd7x+bNVKrpmKgTtfRiTKHZeNPcMjQproJ0vGwhE=
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34 h1:QaViadDOBCMDUwYx78kfRvHMkzRVnh/GOhm3s2gxoP4=
github.com/layer5io/learn-layer5/smi-conformance v0.0.0-20210317075357-06b4f88b3e34/go.mod h1:BQPLwdJt7v7y0fXIejI4whR9zMyX07Wjt5xrbgEmHLw=
github.com/layer5io/meshery-adapter-library v0.5.6 h1:pbZTMkWNcGWPk314K7WhO4UGVxSnKvGLmwQXBWZ05GI=
github.com/layer5io/meshery-adapter-library v0.5.6/go.mod h1:YmLV0w6ucBagrqUB0x9q8ZVXrhN1tJBP5j+Pu6LOY/M=
github.com/layer5io/meshery-adapter-library v0.5.8 h1:usu2OKaytOHRLHiLNeybX5MkQ7rMsqYzJIjvDkh7UgY=
github.com/layer5io/meshery-adapter-library v0.5.8/go.mod h1:IvURQMnZHa3z0OTcUSPqCHUgTsW2x0/+KjCqpYfMbt0=
github.com/layer5io/meshkit v0.5.31 h1:z6U3Ggp0sJaU47j/l8MClCgmkm7cZwJssYHpk/eorPI=
github.com/layer5io/meshkit v0.5.31/go.mod h1:dt0uOluDzatK6hbJEDAZbUsm7LJNb4nsXXaGUDtYxD0=
github.com/layer5io/meshery-adapter-library v0.5.9 h1:Zp79l4J8kMjML9zAQ4Xu4QiKM5q5HEGcv04Jjg+xWSA=
github.com/layer5io/meshery-adapter-library v0.5.9/go.mod h1:IvURQMnZHa3z0OTcUSPqCHUgTsW2x0/+KjCqpYfMbt0=
github.com/layer5io/meshkit v0.5.32 h1:jIkQ9gKH7TPMWKbVtf6wQ+qv4553UyZ9SV4yKA2D4oo=
github.com/layer5io/meshkit v0.5.32/go.mod h1:dt0uOluDzatK6hbJEDAZbUsm7LJNb4nsXXaGUDtYxD0=
github.com/layer5io/service-mesh-performance v0.3.2-0.20210122142912-a94e0658b021/go.mod h1:W153amv8aHAeIWxO7b7d7Vibt9RhaEVh4Uh+RG+BumQ=
Expand Down

0 comments on commit 5cd54b9

Please sign in to comment.