diff --git a/weed/command/command.go b/weed/command/command.go index 8025dcd4f..1bc12c64e 100644 --- a/weed/command/command.go +++ b/weed/command/command.go @@ -38,6 +38,7 @@ var Commands = []*Command{ cmdMqBroker, cmdMqKafkaGateway, cmdPushdown, + cmdPushdownPing, cmdS3, cmdScaffold, cmdServer, diff --git a/weed/command/pushdown_ping.go b/weed/command/pushdown_ping.go new file mode 100644 index 000000000..2912d39c2 --- /dev/null +++ b/weed/command/pushdown_ping.go @@ -0,0 +1,71 @@ +package command + +import ( + "context" + "fmt" + "os" + "time" + + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + + "github.com/seaweedfs/seaweedfs/weed/glog" + pb "github.com/seaweedfs/seaweedfs/weed/pb/parquet_pushdown_pb" + "github.com/seaweedfs/seaweedfs/weed/security" + "github.com/seaweedfs/seaweedfs/weed/util" +) + +var ( + pushdownPingOptions PushdownPingOptions +) + +type PushdownPingOptions struct { + target *string + timeout *time.Duration + useTLS *bool +} + +func init() { + cmdPushdownPing.Run = runPushdownPing + pushdownPingOptions.target = cmdPushdownPing.Flag.String("server", "localhost:18888", "pushdown daemon gRPC address") + pushdownPingOptions.timeout = cmdPushdownPing.Flag.Duration("timeout", 5*time.Second, "RPC deadline") + pushdownPingOptions.useTLS = cmdPushdownPing.Flag.Bool("tls", false, "dial with TLS using grpc.client config") +} + +var cmdPushdownPing = &Command{ + UsageLine: "pushdown.ping [-server=]", + Short: " ping a running pushdown daemon (M0 smoke test)", + Long: `ping a running pushdown daemon. + + Calls the SeaweedParquetPushdown.Ping RPC and prints the daemon's + reported version and trust mode. Used as a deployment smoke test + and by the M0 integration test.`, +} + +func runPushdownPing(cmd *Command, args []string) bool { + util.LoadSecurityConfiguration() + + dialOpt := grpc.WithTransportCredentials(insecure.NewCredentials()) + if *pushdownPingOptions.useTLS { + dialOpt = security.LoadClientTLS(util.GetViper(), "grpc.client") + } + + ctx, cancel := context.WithTimeout(context.Background(), *pushdownPingOptions.timeout) + defer cancel() + + conn, err := grpc.NewClient(*pushdownPingOptions.target, dialOpt) + if err != nil { + glog.Errorf("dial %s: %v", *pushdownPingOptions.target, err) + return false + } + defer conn.Close() + + resp, err := pb.NewSeaweedParquetPushdownClient(conn).Ping(ctx, &pb.PingRequest{}) + if err != nil { + glog.Errorf("ping %s: %v", *pushdownPingOptions.target, err) + return false + } + + fmt.Fprintf(os.Stdout, "ok: server=%s version=%q trust=%q\n", *pushdownPingOptions.target, resp.Version, resp.TrustMode) + return true +}