From 0b99f154d054ac90f70aa4d849c25db39f1d51a2 Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Sat, 20 Aug 2022 20:02:06 +0530 Subject: [PATCH 1/3] Send detailed error response to client Signed-off-by: MUzairS15 --- appmesh/app_mesh.go | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/appmesh/app_mesh.go b/appmesh/app_mesh.go index 6ff9f6b..e03ab3c 100644 --- a/appmesh/app_mesh.go +++ b/appmesh/app_mesh.go @@ -52,6 +52,8 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat Operationid: opReq.OperationID, Summary: status.Deploying, Details: "Operation is not supported", + Component: internalconfig.ServerConfig["type"], + ComponentName: internalconfig.ServerConfig["name"], } stat := status.Deploying @@ -60,9 +62,8 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat go func(hh *AppMesh, ee *adapter.Event) { 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) @@ -78,9 +79,8 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat 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) @@ -100,9 +100,8 @@ 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) @@ -114,9 +113,8 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat 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) @@ -128,9 +126,8 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat go func(hh *AppMesh, ee *adapter.Event) { 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) @@ -138,7 +135,7 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat hh.StreamInfo(e) }(appMesh, e) default: - appMesh.StreamErr(e, ErrOpInvalid) + appMesh.streamErr("Invalid operation", e, ErrOpInvalid) } return nil @@ -245,3 +242,12 @@ func (appMesh *AppMesh) ProcessOAM(ctx context.Context, oamReq adapter.OAMReques return msg1 + "\n" + msg2, nil } + +func(appMesh *AppMesh) streamErr(summary string, e *adapter.Event, 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) +} \ No newline at end of file From 4d7b3e0bada8e76e98f1cd104ab84cce9eb2b3d6 Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Thu, 25 Aug 2022 19:48:48 +0530 Subject: [PATCH 2/3] Use EventsResponse struct Signed-off-by: MUzairS15 --- appmesh/app_mesh.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/appmesh/app_mesh.go b/appmesh/app_mesh.go index e03ab3c..54bd1bd 100644 --- a/appmesh/app_mesh.go +++ b/appmesh/app_mesh.go @@ -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" @@ -48,8 +50,8 @@ 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"], @@ -59,7 +61,7 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat 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 { summary := fmt.Sprintf("Error while %s AWS App mesh", stat) @@ -72,7 +74,7 @@ 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 { @@ -88,7 +90,7 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat 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) @@ -109,7 +111,7 @@ func (appMesh *AppMesh) ApplyOperation(ctx context.Context, opReq adapter.Operat 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 { @@ -123,7 +125,7 @@ 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 { summary := fmt.Sprintf("Error while %s custom operation", stat) @@ -243,7 +245,7 @@ func (appMesh *AppMesh) ProcessOAM(ctx context.Context, oamReq adapter.OAMReques return msg1 + "\n" + msg2, nil } -func(appMesh *AppMesh) streamErr(summary string, e *adapter.Event, err error) { +func(appMesh *AppMesh) streamErr(summary string, e *meshes.EventsResponse, err error) { e.Summary = summary e.Details = err.Error() e.ErrorCode = errors.GetCode(err) From 067c45a126f1263cca4038596657bf9804d14cd4 Mon Sep 17 00:00:00 2001 From: MUzairS15 Date: Thu, 25 Aug 2022 21:52:27 +0530 Subject: [PATCH 3/3] dep update Signed-off-by: MUzairS15 --- go.mod | 2 +- go.sum | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index a10bb8d..90c1ffb 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 20ce5b6..ff7740b 100644 --- a/go.sum +++ b/go.sum @@ -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=