Skip to content

Commit

Permalink
Renamed to remove get from lots of systemeventlog action methods and …
Browse files Browse the repository at this point in the history
…such, per review

Signed-off-by: Matthew Burns <[email protected]>
  • Loading branch information
mattcburns committed Dec 13, 2023
1 parent 8d69758 commit b8d642c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 48 deletions.
12 changes: 6 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ func ClearSystemEventLog(ctx context.Context, client v1.DiagnosticClient, taskCl
return statusResp, nil
}

// GetSystemEventLog retrieves the System Event Log of the server.
func GetSystemEventLog(ctx context.Context, client v1.DiagnosticClient, request *v1.GetSystemEventLogRequest) (*v1.GetSystemEventLogResponse, error) {
return client.GetSystemEventLog(ctx, request)
// SystemEventLog retrieves the System Event Log of the server.
func SystemEventLog(ctx context.Context, client v1.DiagnosticClient, request *v1.SystemEventLogRequest) (*v1.SystemEventLogResponse, error) {
return client.SystemEventLog(ctx, request)
}

// GetSystemEventLogRaw retrieves the System Event Log of the server.
func GetSystemEventLogRaw(ctx context.Context, client v1.DiagnosticClient, request *v1.GetSystemEventLogRawRequest) (*v1.GetSystemEventLogRawResponse, error) {
return client.GetSystemEventLogRaw(ctx, request)
// SystemEventLogRaw retrieves the System Event Log of the server.
func SystemEventLogRaw(ctx context.Context, client v1.DiagnosticClient, request *v1.SystemEventLogRawRequest) (*v1.SystemEventLogRawResponse, error) {
return client.SystemEventLogRaw(ctx, request)
}
4 changes: 2 additions & 2 deletions cmd/sel.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var (
defer conn.Close()
client := v1.NewDiagnosticClient(conn)

resp, err := v1Client.GetSystemEventLog(ctx, client, &v1.GetSystemEventLogRequest{
resp, err := v1Client.SystemEventLog(ctx, client, &v1.SystemEventLogRequest{
Authn: &v1.Authn{
Authn: &v1.Authn_DirectAuthn{
DirectAuthn: &v1.DirectAuthn{
Expand Down Expand Up @@ -123,7 +123,7 @@ var (
defer conn.Close()
client := v1.NewDiagnosticClient(conn)

resp, err := v1Client.GetSystemEventLogRaw(ctx, client, &v1.GetSystemEventLogRawRequest{
resp, err := v1Client.SystemEventLogRaw(ctx, client, &v1.SystemEventLogRawRequest{
Authn: &v1.Authn{
Authn: &v1.Authn_DirectAuthn{
DirectAuthn: &v1.DirectAuthn{
Expand Down
8 changes: 4 additions & 4 deletions grpc/oob/diagnostic/diagnostic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (

type Action struct {
common.Accessory
ScreenshotRequest *v1.ScreenshotRequest
ClearSystemEventLogRequest *v1.ClearSystemEventLogRequest
GetSystemEventLogRequest *v1.GetSystemEventLogRequest
GetSystemEventLogRawRequest *v1.GetSystemEventLogRawRequest
ScreenshotRequest *v1.ScreenshotRequest
ClearSystemEventLogRequest *v1.ClearSystemEventLogRequest
SystemEventLogRequest *v1.SystemEventLogRequest
SystemEventLogRawRequest *v1.SystemEventLogRawRequest
}

// WithLogger adds a logr to an Action struct.
Expand Down
49 changes: 23 additions & 26 deletions grpc/oob/diagnostic/getsel.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,47 @@ import (
"go.opentelemetry.io/otel/trace"
)

func NewSystemEventLogGetter(req *v1.GetSystemEventLogRequest, opts ...Option) (*Action, error) {
func NewSystemEventLogAction(req interface{}, opts ...Option) (*Action, error) {
a := &Action{}
a.GetSystemEventLogRequest = req
for _, opt := range opts {
err := opt(a)
if err != nil {
return nil, err
}
switch r := req.(type) {
case *v1.SystemEventLogRequest:
a.SystemEventLogRequest = r
case *v1.SystemEventLogRawRequest:
a.SystemEventLogRawRequest = r
default:
return nil, fmt.Errorf("unsupported request type")
}
return a, nil
}

func NewSystemEventLogRawGetter(req *v1.GetSystemEventLogRawRequest, opts ...Option) (*Action, error) {
a := &Action{}
a.GetSystemEventLogRawRequest = req
for _, opt := range opts {
err := opt(a)
if err != nil {
return nil, err
}
}

return a, nil
}

func (m Action) GetSystemEventLog(ctx context.Context) (result bmc.SystemEventLogEntries, err error) {
func (m Action) SystemEventLog(ctx context.Context) (result bmc.SystemEventLogEntries, err error) {
labels := prometheus.Labels{
"service": "diagnostic",
"action": "get_system_event_log",
"action": "system_event_log",
}

timer := prometheus.NewTimer(metrics.ActionDuration.With(labels))
defer timer.ObserveDuration()

tracer := otel.Tracer("pbnj")
ctx, span := tracer.Start(ctx, "diagnostic.GetSystemEventLog", trace.WithAttributes(
attribute.String("bmc.device", m.GetSystemEventLogRequest.GetAuthn().GetDirectAuthn().GetHost().GetHost()),
ctx, span := tracer.Start(ctx, "diagnostic.SystemEventLog", trace.WithAttributes(
attribute.String("bmc.device", m.SystemEventLogRequest.GetAuthn().GetDirectAuthn().GetHost().GetHost()),
))
defer span.End()

if v := m.GetSystemEventLogRequest.GetVendor(); v != nil {
if v := m.SystemEventLogRequest.GetVendor(); v != nil {
span.SetAttributes(attribute.String("bmc.vendor", v.GetName()))
}

host, user, password, parseErr := m.ParseAuth(m.GetSystemEventLogRequest.GetAuthn())
host, user, password, parseErr := m.ParseAuth(m.SystemEventLogRequest.GetAuthn())
if parseErr != nil {
span.SetStatus(codes.Error, "error parsing credentials: "+parseErr.Error())
return result, parseErr
Expand Down Expand Up @@ -102,8 +99,8 @@ func (m Action) GetSystemEventLog(ctx context.Context) (result bmc.SystemEventLo
sel, err := client.GetSystemEventLog(ctx)
log = m.Log.WithValues(logMetadata(client.GetMetadata())...)
meta = client.GetMetadata()
span.SetAttributes(attribute.StringSlice("bmc.get_system_event_log.providersAttempted", meta.ProvidersAttempted),
attribute.StringSlice("bmc.get_system_event_log.successfulOpenConns", meta.SuccessfulOpenConns))
span.SetAttributes(attribute.StringSlice("bmc.system_event_log.providersAttempted", meta.ProvidersAttempted),
attribute.StringSlice("bmc.system_event_log.successfulOpenConns", meta.SuccessfulOpenConns))
if err != nil {
log.Error(err, "error getting system event log")
span.SetStatus(codes.Error, "error getting system event log: "+err.Error())
Expand All @@ -122,26 +119,26 @@ func (m Action) GetSystemEventLog(ctx context.Context) (result bmc.SystemEventLo
return sel, nil
}

func (m Action) GetSystemEventLogRaw(ctx context.Context) (result string, err error) {
func (m Action) SystemEventLogRaw(ctx context.Context) (result string, err error) {
labels := prometheus.Labels{
"service": "diagnostic",
"action": "get_system_event_log_raw",
"action": "system_event_log_raw",
}

timer := prometheus.NewTimer(metrics.ActionDuration.With(labels))
defer timer.ObserveDuration()

tracer := otel.Tracer("pbnj")
ctx, span := tracer.Start(ctx, "diagnostic.GetSystemEventLogRaw", trace.WithAttributes(
attribute.String("bmc.device", m.GetSystemEventLogRawRequest.GetAuthn().GetDirectAuthn().GetHost().GetHost()),
ctx, span := tracer.Start(ctx, "diagnostic.SystemEventLogRaw", trace.WithAttributes(
attribute.String("bmc.device", m.SystemEventLogRawRequest.GetAuthn().GetDirectAuthn().GetHost().GetHost()),
))
defer span.End()

if v := m.GetSystemEventLogRawRequest.GetVendor(); v != nil {
if v := m.SystemEventLogRawRequest.GetVendor(); v != nil {
span.SetAttributes(attribute.String("bmc.vendor", v.GetName()))
}

host, user, password, parseErr := m.ParseAuth(m.GetSystemEventLogRawRequest.GetAuthn())
host, user, password, parseErr := m.ParseAuth(m.SystemEventLogRawRequest.GetAuthn())
if parseErr != nil {
span.SetStatus(codes.Error, "error parsing credentials: "+parseErr.Error())
return result, parseErr
Expand Down
20 changes: 10 additions & 10 deletions grpc/rpc/diagnostic.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,21 @@ func (d *DiagnosticService) ClearSystemEventLog(ctx context.Context, in *v1.Clea
return &v1.ClearSystemEventLogResponse{TaskId: taskID}, nil
}

func (d *DiagnosticService) GetSystemEventLog(ctx context.Context, in *v1.GetSystemEventLogRequest) (*v1.GetSystemEventLogResponse, error) {
func (d *DiagnosticService) SystemEventLog(ctx context.Context, in *v1.SystemEventLogRequest) (*v1.SystemEventLogResponse, error) {
l := logging.ExtractLogr(ctx)

Check warning on line 84 in grpc/rpc/diagnostic.go

View check run for this annotation

Codecov / codecov/patch

grpc/rpc/diagnostic.go#L83-L84

Added lines #L83 - L84 were not covered by tests

l.Info("start Get System Event Log request",
"username", in.Authn.GetDirectAuthn().GetUsername(),
"vendor", in.Vendor.GetName(),
)

Check warning on line 89 in grpc/rpc/diagnostic.go

View check run for this annotation

Codecov / codecov/patch

grpc/rpc/diagnostic.go#L86-L89

Added lines #L86 - L89 were not covered by tests

selgetter, err := diagnostic.NewSystemEventLogGetter(in, diagnostic.WithLogger(l))
selaction, err := diagnostic.NewSystemEventLogAction(in, diagnostic.WithLogger(l))
if err != nil {
l.Error(err, "error creating system event log getter")
l.Error(err, "error creating system event log action")
return nil, err

Check warning on line 94 in grpc/rpc/diagnostic.go

View check run for this annotation

Codecov / codecov/patch

grpc/rpc/diagnostic.go#L91-L94

Added lines #L91 - L94 were not covered by tests
}

entries, err := selgetter.GetSystemEventLog(ctx)
entries, err := selaction.SystemEventLog(ctx)
if err != nil {
l.Error(err, "error getting system event log")
return nil, err

Check warning on line 100 in grpc/rpc/diagnostic.go

View check run for this annotation

Codecov / codecov/patch

grpc/rpc/diagnostic.go#L97-L100

Added lines #L97 - L100 were not covered by tests
Expand All @@ -111,32 +111,32 @@ func (d *DiagnosticService) GetSystemEventLog(ctx context.Context, in *v1.GetSys
})

Check warning on line 111 in grpc/rpc/diagnostic.go

View check run for this annotation

Codecov / codecov/patch

grpc/rpc/diagnostic.go#L105-L111

Added lines #L105 - L111 were not covered by tests
}

return &v1.GetSystemEventLogResponse{
return &v1.SystemEventLogResponse{
Events: events,
}, nil

Check warning on line 116 in grpc/rpc/diagnostic.go

View check run for this annotation

Codecov / codecov/patch

grpc/rpc/diagnostic.go#L114-L116

Added lines #L114 - L116 were not covered by tests
}

func (d *DiagnosticService) GetSystemEventLogRaw(ctx context.Context, in *v1.GetSystemEventLogRawRequest) (*v1.GetSystemEventLogRawResponse, error) {
func (d *DiagnosticService) SystemEventLogRaw(ctx context.Context, in *v1.SystemEventLogRawRequest) (*v1.SystemEventLogRawResponse, error) {
l := logging.ExtractLogr(ctx)

Check warning on line 120 in grpc/rpc/diagnostic.go

View check run for this annotation

Codecov / codecov/patch

grpc/rpc/diagnostic.go#L119-L120

Added lines #L119 - L120 were not covered by tests

l.Info("start Get System Event Log request",
"username", in.Authn.GetDirectAuthn().GetUsername(),
"vendor", in.Vendor.GetName(),
)

Check warning on line 125 in grpc/rpc/diagnostic.go

View check run for this annotation

Codecov / codecov/patch

grpc/rpc/diagnostic.go#L122-L125

Added lines #L122 - L125 were not covered by tests

rawselgetter, err := diagnostic.NewSystemEventLogRawGetter(in, diagnostic.WithLogger(l))
rawselaction, err := diagnostic.NewSystemEventLogAction(in, diagnostic.WithLogger(l))
if err != nil {
l.Error(err, "error creating raw system event log getter")
l.Error(err, "error creating raw system event log action")
return nil, err

Check warning on line 130 in grpc/rpc/diagnostic.go

View check run for this annotation

Codecov / codecov/patch

grpc/rpc/diagnostic.go#L127-L130

Added lines #L127 - L130 were not covered by tests
}

eventlog, err := rawselgetter.GetSystemEventLogRaw(ctx)
eventlog, err := rawselaction.SystemEventLogRaw(ctx)
if err != nil {
l.Error(err, "error getting raw system event log")
return nil, err

Check warning on line 136 in grpc/rpc/diagnostic.go

View check run for this annotation

Codecov / codecov/patch

grpc/rpc/diagnostic.go#L133-L136

Added lines #L133 - L136 were not covered by tests
}

return &v1.GetSystemEventLogRawResponse{
return &v1.SystemEventLogRawResponse{
Log: eventlog,
}, nil

Check warning on line 141 in grpc/rpc/diagnostic.go

View check run for this annotation

Codecov / codecov/patch

grpc/rpc/diagnostic.go#L139-L141

Added lines #L139 - L141 were not covered by tests
}

0 comments on commit b8d642c

Please sign in to comment.