Skip to content

Commit

Permalink
Merge pull request #145 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 authored Aug 26, 2022
2 parents 52881f2 + eefdd2e commit 26168d1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
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.31
github.com/layer5io/service-mesh-performance v0.3.4
gopkg.in/yaml.v2 v2.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -862,8 +862,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.8 h1:usu2OKaytOHRLHiLNeybX5MkQ7rMsqYzJIjvDkh7UgY=
github.com/layer5io/meshery-adapter-library v0.5.8/go.mod h1:IvURQMnZHa3z0OTcUSPqCHUgTsW2x0/+KjCqpYfMbt0=
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.31 h1:z6U3Ggp0sJaU47j/l8MClCgmkm7cZwJssYHpk/eorPI=
github.com/layer5io/meshkit v0.5.31/go.mod h1:dt0uOluDzatK6hbJEDAZbUsm7LJNb4nsXXaGUDtYxD0=
github.com/layer5io/service-mesh-performance v0.3.2-0.20210122142912-a94e0658b021/go.mod h1:W153amv8aHAeIWxO7b7d7Vibt9RhaEVh4Uh+RG+BumQ=
Expand Down
58 changes: 34 additions & 24 deletions nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"github.com/layer5io/meshery-adapter-library/adapter"
"github.com/layer5io/meshery-adapter-library/common"
adapterconfig "github.com/layer5io/meshery-adapter-library/config"
"github.com/layer5io/meshery-adapter-library/meshes"
"github.com/layer5io/meshery-adapter-library/status"
internalconfig "github.com/layer5io/meshery-nginx/internal/config"
"github.com/layer5io/meshkit/errors"
"github.com/layer5io/meshkit/logger"
"github.com/layer5io/meshkit/models"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -47,49 +49,50 @@ func (nginx *Nginx) ApplyOperation(ctx context.Context, opReq adapter.OperationR

stat := status.Deploying

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

}

switch opReq.OperationName {
case internalconfig.NginxOperation:
go func(hh *Nginx, ee *adapter.Event) {
go func(hh *Nginx, ee *meshes.EventsResponse) {
version := string(operations[opReq.OperationName].Versions[0])
if stat, err = hh.installNginx(opReq.IsDeleteOperation, version, opReq.Namespace, kubeConfigs); err != nil {
e.Summary = fmt.Sprintf("Error while %s NGINX Service Mesh", stat)
e.Details = err.Error()
hh.StreamErr(e, err)
summary := fmt.Sprintf("Error while %s NGINX Service Mesh", stat)
hh.streamErr(summary, e, err)
return
}
ee.Summary = fmt.Sprintf("NGINX Service Mesh %s successfully", stat)
ee.Details = fmt.Sprintf("NGINX Service Mesh is now %s.", stat)
hh.StreamInfo(e)
}(nginx, e)
case internalconfig.LabelNamespace:
go func(hh *Nginx, ee *adapter.Event) {
go func(hh *Nginx, 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("NGINX-INJECTION label %s on %s namespace", operation, opReq.Namespace)
hh.StreamInfo(e)
}(nginx, e)
case common.SmiConformanceOperation:
go func(hh *Nginx, ee *adapter.Event) {
go func(hh *Nginx, ee *meshes.EventsResponse) {
name := operations[opReq.OperationName].Description
_, err := hh.RunSMITest(adapter.SMITestOptions{
Ctx: context.TODO(),
OperationID: ee.Operationid,
OperationID: ee.OperationId,
Manifest: string(operations[opReq.OperationName].Templates[0]),
Namespace: "meshery",
Labels: make(map[string]string),
Expand All @@ -98,44 +101,41 @@ func (nginx *Nginx) ApplyOperation(ctx context.Context, opReq adapter.OperationR
},
})
if err != nil {
e.Summary = fmt.Sprintf("Error while %s %s test", status.Running, name)
e.Details = err.Error()
hh.StreamErr(e, err)
summary := fmt.Sprintf("Error while %s %s test", status.Running, name)
hh.streamErr(summary, e, err)
return
}
ee.Summary = fmt.Sprintf("%s test %s successfully", name, status.Completed)
ee.Details = ""
hh.StreamInfo(e)
}(nginx, e)
case common.BookInfoOperation, common.HTTPBinOperation, common.ImageHubOperation, common.EmojiVotoOperation:
go func(hh *Nginx, ee *adapter.Event) {
go func(hh *Nginx, 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)
ee.Details = fmt.Sprintf("The %s application is now %s.", appName, stat)
hh.StreamInfo(e)
}(nginx, e)
case common.CustomOperation:
go func(hh *Nginx, ee *adapter.Event) {
go func(hh *Nginx, 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)
}(nginx, e)
default:
nginx.StreamErr(e, ErrOpInvalid)
nginx.streamErr("Invalid operation", e, ErrOpInvalid)
}

return nil
Expand Down Expand Up @@ -185,3 +185,13 @@ func (nginx *Nginx) CreateKubeconfigs(kubeconfigs []string) error {
}
return mergeErrors(errs)
}


func(nginx *Nginx) 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)
nginx.StreamErr(e, err)
}

0 comments on commit 26168d1

Please sign in to comment.