fix(osctl): Revert "display non-fatal errors from ps/stats in osctl (#724)" (#727)

This reverts commit f200eb7a8a0b7c2d29710f695000eb7680ce8b7d.

grpc can't send back both response and an error.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
This commit is contained in:
Andrey Smirnov 2019-06-07 22:50:05 +03:00 committed by GitHub
parent 532a53bfaf
commit fb320a894b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 21 deletions

View File

@ -38,17 +38,11 @@ var psCmd = &cobra.Command{
}
reply, err := c.Processes(globalCtx, namespace)
if reply == nil && err != nil {
// fatal error
if err != nil {
helpers.Fatalf("error getting process list: %s", err)
}
processesRender(reply)
if err != nil {
// some errors encountered, but not fatal
fmt.Fprintf(os.Stderr, "errors while listing processes: %s", err)
}
})
},
}

View File

@ -37,17 +37,11 @@ var statsCmd = &cobra.Command{
namespace = constants.SystemContainerdNamespace
}
reply, err := c.Stats(globalCtx, namespace)
if reply == nil && err != nil {
// fatal error
if err != nil {
helpers.Fatalf("error getting stats: %s", err)
}
statsRender(reply)
if err != nil {
// some errors encountered, but not fatal
fmt.Fprintf(os.Stderr, "errors while getting stats: %s", err)
}
})
},
}

View File

@ -10,6 +10,7 @@ import (
"context"
"encoding/gob"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
@ -87,6 +88,8 @@ func (r *Registrator) Processes(ctx context.Context, in *proto.ProcessesRequest)
if pods == nil {
return nil, err
}
// TODO: only some failed, need to handle it better via client
log.Println(err.Error())
}
processes := []*proto.Process{}
@ -104,12 +107,13 @@ func (r *Registrator) Processes(ctx context.Context, in *proto.ProcessesRequest)
}
}
return &proto.ProcessesReply{Processes: processes}, err
return &proto.ProcessesReply{Processes: processes}, nil
}
// Stats implements the proto.OSDServer interface.
// nolint: gocyclo
func (r *Registrator) Stats(ctx context.Context, in *proto.StatsRequest) (*proto.StatsReply, error) {
func (r *Registrator) Stats(ctx context.Context, in *proto.StatsRequest) (reply *proto.StatsReply, err error) {
inspector, err := containers.NewInspector(ctx, in.Namespace)
if err != nil {
return nil, err
@ -123,6 +127,8 @@ func (r *Registrator) Stats(ctx context.Context, in *proto.StatsRequest) (*proto
if pods == nil {
return nil, err
}
// TODO: only some failed, need to handle it better via client
log.Println(err.Error())
}
stats := []*proto.Stat{}
@ -133,15 +139,15 @@ func (r *Registrator) Stats(ctx context.Context, in *proto.StatsRequest) (*proto
continue
}
anydata, e := typeurl.UnmarshalAny(container.Metrics.Data)
if e != nil {
err = multierror.Append(err, e)
anydata, err := typeurl.UnmarshalAny(container.Metrics.Data)
if err != nil {
log.Println(err)
continue
}
data, ok := anydata.(*cgroups.Metrics)
if !ok {
err = multierror.Append(err, errors.New("failed to convert metric data to cgroups.Metrics"))
log.Println(errors.New("failed to convert metric data to cgroups.Metrics"))
continue
}
@ -165,7 +171,9 @@ func (r *Registrator) Stats(ctx context.Context, in *proto.StatsRequest) (*proto
}
return &proto.StatsReply{Stats: stats}, err
reply = &proto.StatsReply{Stats: stats}
return reply, nil
}
// Restart implements the proto.OSDServer interface.