mirror of https://github.com/linkerd/linkerd2.git
Add --verbose option to CLI (#154)
* Use stdout as writer for tap command fixes #136 Signed-off-by: Phil Calcado <phil@buoyant.io> * Add --log-level to command line Signed-off-by: Phil Calcado <phil@buoyant.io>
This commit is contained in:
parent
4daa007256
commit
612bd0f7a0
|
@ -2,11 +2,11 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/pkg/browser"
|
||||
"github.com/runconduit/conduit/pkg/k8s"
|
||||
"github.com/runconduit/conduit/pkg/shell"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/runconduit/conduit/controller/api/public"
|
||||
pb "github.com/runconduit/conduit/controller/gen/public"
|
||||
"github.com/runconduit/conduit/pkg/k8s"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
@ -13,15 +14,25 @@ var cfgFile string
|
|||
var controlPlaneNamespace string
|
||||
var apiAddr string // An empty value means "use the Kubernetes configuration"
|
||||
var kubeconfigPath string
|
||||
var logLevel string
|
||||
|
||||
var RootCmd = &cobra.Command{
|
||||
Use: "conduit",
|
||||
Short: "conduit manages the Conduit service mesh",
|
||||
Long: `conduit manages the Conduit service mesh.`,
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
// set global log level
|
||||
level, err := log.ParseLevel(logLevel)
|
||||
if err != nil {
|
||||
log.Fatalf("invalid log-level: %s", logLevel)
|
||||
}
|
||||
log.SetLevel(level)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
RootCmd.PersistentFlags().StringVarP(&controlPlaneNamespace, "conduit-namespace", "n", "conduit", "namespace in which Conduit is installed")
|
||||
RootCmd.PersistentFlags().StringVar(&logLevel, "log-level", log.FatalLevel.String(), "log level, must be one of: panic, fatal, error, warn, info, debug")
|
||||
}
|
||||
|
||||
// TODO: decide if we want to use viper
|
||||
|
|
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/runconduit/conduit/controller/util"
|
||||
"github.com/runconduit/conduit/pkg/k8s"
|
||||
"github.com/runconduit/conduit/pkg/shell"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"google.golang.org/grpc/codes"
|
||||
)
|
||||
|
@ -127,6 +128,7 @@ func renderTap(w io.Writer, tapClient pb.Api_TapClient) error {
|
|||
|
||||
func writeTapEventsToBuffer(tapClient pb.Api_TapClient, w *tabwriter.Writer) error {
|
||||
for {
|
||||
log.Debug("Waiting for data...")
|
||||
event, err := tapClient.Recv()
|
||||
if err == io.EOF {
|
||||
break
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
common "github.com/runconduit/conduit/controller/gen/common"
|
||||
pb "github.com/runconduit/conduit/controller/gen/public"
|
||||
"github.com/runconduit/conduit/pkg/k8s"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/metadata"
|
||||
|
@ -64,6 +65,7 @@ func (c *grpcOverHttpClient) ListPods(ctx context.Context, req *pb.Empty, _ ...g
|
|||
|
||||
func (c *grpcOverHttpClient) Tap(ctx context.Context, req *pb.TapRequest, _ ...grpc.CallOption) (pb.Api_TapClient, error) {
|
||||
url := c.endpointNameToPublicApiUrl("Tap")
|
||||
log.Debugf("Making streaming gRPC-over-HTTP call to [%s]", url.String())
|
||||
rsp, err := c.post(ctx, url, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -71,6 +73,7 @@ func (c *grpcOverHttpClient) Tap(ctx context.Context, req *pb.TapRequest, _ ...g
|
|||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
log.Debug("Closing response body after context marked as done")
|
||||
rsp.Body.Close()
|
||||
}()
|
||||
|
||||
|
@ -93,11 +96,13 @@ func (c tapClient) RecvMsg(interface{}) error { return nil }
|
|||
func (c *grpcOverHttpClient) apiRequest(ctx context.Context, endpoint string, req proto.Message, rsp proto.Message) error {
|
||||
url := c.endpointNameToPublicApiUrl(endpoint)
|
||||
|
||||
log.Debugf("Making gRPC-over-HTTP call to [%s]", url.String())
|
||||
httpRsp, err := c.post(ctx, url, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debugf("gRPC-over-HTTP call returned status [%s] and content length [%d]", httpRsp.Status, httpRsp.ContentLength)
|
||||
clientSideErrorStatusCode := httpRsp.StatusCode >= 400 && httpRsp.StatusCode <= 499
|
||||
if clientSideErrorStatusCode {
|
||||
return fmt.Errorf("POST to Conduit API endpoint [%s] returned HTTP status [%s]", url, httpRsp.Status)
|
||||
|
|
|
@ -2,10 +2,10 @@ package cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/runconduit/conduit/proxy-init/iptables"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ func main() {
|
|||
staticDir := flag.String("static-dir", "app/dist", "directory to search for static files")
|
||||
uuid := flag.String("uuid", "", "unqiue Conduit install id")
|
||||
reload := flag.Bool("reload", true, "reloading set to true or false")
|
||||
logLevel := flag.String("log-level", "info", "log level, must be one of: panic, fatal, error, warn, info, debug")
|
||||
logLevel := flag.String("log-level", log.InfoLevel.String(), "log level, must be one of: panic, fatal, error, warn, info, debug")
|
||||
webpackDevServer := flag.String("webpack-dev-server", "", "use webpack to serve static assets; frontend will use this instead of static-dir")
|
||||
|
||||
flag.Parse()
|
||||
|
|
Loading…
Reference in New Issue