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

Update handlers to send complete error details #90

Merged
merged 3 commits into from
Aug 25, 2022
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
5 changes: 3 additions & 2 deletions adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"sync"

"github.com/layer5io/meshery-adapter-library/meshes"
meshkitCfg "github.com/layer5io/meshkit/config"
"github.com/layer5io/meshkit/logger"
)
Expand All @@ -35,8 +36,8 @@ type Handler interface {
ProcessOAM(ctx context.Context, srv OAMRequest, hchan *chan interface{}) (string, error)

// Need not implement this method and can be reused
StreamErr(*Event, error) // Streams an error event, e.g. to a channel
StreamInfo(*Event) // Streams an informational event, e.g. to a channel
StreamErr(*meshes.EventsResponse, error) // Streams an error event, e.g. to a channel
StreamInfo(*meshes.EventsResponse) // Streams an informational event, e.g. to a channel
}

// Adapter contains all handlers, channels, clients, and other parameters for an adapter.
Expand Down
5 changes: 3 additions & 2 deletions adapter/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package adapter
import (
"context"

"github.com/layer5io/meshery-adapter-library/meshes"
"github.com/layer5io/meshkit/logger"
)

Expand Down Expand Up @@ -85,10 +86,10 @@ func (s *adapterLogger) ListOperations() (Operations, error) {
return ops, err
}

func (s *adapterLogger) StreamErr(e *Event, err error) {
func (s *adapterLogger) StreamErr(e *meshes.EventsResponse, err error) {
s.log.Error(err)
}

func (s *adapterLogger) StreamInfo(*Event) {
func (s *adapterLogger) StreamInfo(*meshes.EventsResponse) {
s.log.Info("Sending event response")
}
5 changes: 3 additions & 2 deletions adapter/smi.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"github.com/layer5io/learn-layer5/smi-conformance/conformance"
"github.com/layer5io/meshery-adapter-library/meshes"
"github.com/layer5io/meshery-adapter-library/status"
"github.com/layer5io/meshkit/utils"
mesherykube "github.com/layer5io/meshkit/utils/kubernetes"
Expand Down Expand Up @@ -88,8 +89,8 @@ type SMITestOptions struct {

// RunSMITest runs the SMI test on the adapter's service mesh
func (h *Adapter) RunSMITest(opts SMITestOptions) (Response, error) {
e := &Event{
Operationid: opts.OperationID,
e := &meshes.EventsResponse{
OperationId: opts.OperationID,
Summary: status.Deploying,
Details: "None",
}
Expand Down
15 changes: 5 additions & 10 deletions adapter/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,16 @@

package adapter

type Event struct {
Operationid string `json:"operationid,omitempty"`
EType int32 `json:"type,string,omitempty"`
Summary string `json:"summary,omitempty"`
Details string `json:"details,omitempty"`
}
import "github.com/layer5io/meshery-adapter-library/meshes"

func (h *Adapter) StreamErr(e *Event, err error) {
func (h *Adapter) StreamErr(e *meshes.EventsResponse, err error) {
h.Log.Error(err)
e.EType = 2
e.EventType = 2
*h.Channel <- e
}

func (h *Adapter) StreamInfo(e *Event) {
func (h *Adapter) StreamInfo(e *meshes.EventsResponse) {
h.Log.Info("Sending event")
e.EType = 0
e.EventType = 0
*h.Channel <- e
}
13 changes: 9 additions & 4 deletions api/grpc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,15 @@ func (s *Service) StreamEvents(ctx *meshes.EventsRequest, srv meshes.MeshService
for {
data := <-s.Channel
event := &meshes.EventsResponse{
OperationId: data.(*adapter.Event).Operationid,
EventType: meshes.EventType(data.(*adapter.Event).EType),
Summary: data.(*adapter.Event).Summary,
Details: data.(*adapter.Event).Details,
OperationId: data.(*meshes.EventsResponse).OperationId,
EventType: meshes.EventType(data.(*meshes.EventsResponse).EventType),
Summary: data.(*meshes.EventsResponse).Summary,
Details: data.(*meshes.EventsResponse).Details,
ErrorCode: data.(*meshes.EventsResponse).ErrorCode,
ProbableCause: data.(*meshes.EventsResponse).ProbableCause,
SuggestedRemediation: data.(*meshes.EventsResponse).SuggestedRemediation,
Component: data.(*meshes.EventsResponse).Component,
ComponentName: data.(*meshes.EventsResponse).ComponentName,
}
if err := srv.Send(event); err != nil {
// to prevent loosing the event, will re-add to the channel
Expand Down
66 changes: 59 additions & 7 deletions meshes/meshops.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions meshes/meshops_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.