From dd6eb647f3e29cb45443101676d05fa155c88c69 Mon Sep 17 00:00:00 2001 From: Ran Mishael <106548467+ranlavanet@users.noreply.github.com> Date: Mon, 5 Feb 2024 21:52:26 +0100 Subject: [PATCH] adding header prints (#1195) --- protocol/chainlib/common.go | 12 ++++++++++++ protocol/chainlib/grpc.go | 22 ++++++++++++++++------ protocol/chainlib/jsonRPC.go | 8 +++++++- protocol/chainlib/rest.go | 16 ++++++++++++++-- protocol/chainlib/tendermintRPC.go | 15 +++++++++++++-- protocol/rpcconsumer/rpcconsumer_server.go | 1 + 6 files changed, 63 insertions(+), 11 deletions(-) diff --git a/protocol/chainlib/common.go b/protocol/chainlib/common.go index 49f6e5d105..8800b8c304 100644 --- a/protocol/chainlib/common.go +++ b/protocol/chainlib/common.go @@ -327,3 +327,15 @@ func createAndSetupBaseAppListener(cmdFlags common.ConsumerCmdFlags, healthCheck return app } + +func truncateAndPadString(s string, maxLength int) string { + // Truncate to a maximum length + if len(s) > maxLength { + s = s[:maxLength] + } + + // Pad with empty strings if the length is less than the specified maximum length + s = fmt.Sprintf("%-*s", maxLength, s) + + return s +} diff --git a/protocol/chainlib/grpc.go b/protocol/chainlib/grpc.go index d8ddf60c07..c3a05f3137 100644 --- a/protocol/chainlib/grpc.go +++ b/protocol/chainlib/grpc.go @@ -13,12 +13,12 @@ import ( "sync" "time" + "github.com/gogo/protobuf/jsonpb" "github.com/lavanet/lava/protocol/chainlib/extensionslib" + "github.com/lavanet/lava/protocol/chainlib/grpcproxy" dyncodec "github.com/lavanet/lava/protocol/chainlib/grpcproxy/dyncodec" "github.com/lavanet/lava/protocol/parser" - - "github.com/gogo/protobuf/jsonpb" - "github.com/lavanet/lava/protocol/chainlib/grpcproxy" + protocoltypes "github.com/lavanet/lava/x/protocol/types" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -283,8 +283,6 @@ func (apil *GrpcChainListener) Serve(ctx context.Context, cmdFlags common.Consum return } - utils.LavaFormatInfo("gRPC PortalStart") - lis := GetListenerWithRetryGrpc("tcp", apil.endpoint.NetworkAddress) apiInterface := apil.endpoint.ApiInterface sendRelayCallback := func(ctx context.Context, method string, reqBody []byte) ([]byte, metadata.MD, error) { @@ -297,7 +295,11 @@ func (apil *GrpcChainListener) Serve(ctx context.Context, cmdFlags common.Consum dappID := extractDappIDFromGrpcHeader(metadataValues) grpcHeaders := convertToMetadataMapOfSlices(metadataValues) - utils.LavaFormatInfo("GRPC Got Relay ", utils.Attribute{Key: "GUID", Value: ctx}, utils.Attribute{Key: "method", Value: method}) + utils.LavaFormatInfo("in <<< GRPC Relay ", + utils.LogAttr("GUID", ctx), + utils.LogAttr("method", method), + utils.LogAttr("headers", grpcHeaders), + ) metricsData := metrics.NewRelayAnalytics(dappID, apil.endpoint.ChainID, apiInterface) consumerIp := common.GetIpFromGrpcContext(ctx) relayResult, err := apil.relaySender.SendRelay(ctx, method, string(reqBody), "", dappID, consumerIp, metricsData, grpcHeaders) @@ -345,6 +347,14 @@ func (apil *GrpcChainListener) Serve(ctx context.Context, cmdFlags common.Consum serveExecutor = func() error { return httpServer.Serve(lis) } } + fmt.Printf(fmt.Sprintf(` + ┌───────────────────────────────────────────────────┐ + │ Lava's Grpc Server │ + │ %s│ + │ Lavap Version: %s│ + └───────────────────────────────────────────────────┘ + +`, truncateAndPadString(apil.endpoint.NetworkAddress, 36), truncateAndPadString(protocoltypes.DefaultVersion.ConsumerTarget, 21))) if err := serveExecutor(); !errors.Is(err, http.ErrServerClosed) { utils.LavaFormatFatal("Portal failed to serve", err, utils.Attribute{Key: "Address", Value: lis.Addr()}, utils.Attribute{Key: "ChainID", Value: apil.endpoint.ChainID}) } diff --git a/protocol/chainlib/jsonRPC.go b/protocol/chainlib/jsonRPC.go index c5c8798284..5fc32f052f 100644 --- a/protocol/chainlib/jsonRPC.go +++ b/protocol/chainlib/jsonRPC.go @@ -405,7 +405,6 @@ func (apil *JsonRPCChainListener) Serve(ctx context.Context, cmdFlags common.Con guid := utils.GenerateUniqueIdentifier() ctx = utils.WithUniqueIdentifier(ctx, guid) msgSeed := strconv.FormatUint(guid, 10) - utils.LavaFormatInfo("in <<<", utils.Attribute{Key: "GUID", Value: ctx}, utils.Attribute{Key: "seed", Value: msgSeed}, utils.Attribute{Key: "msg", Value: fiberCtx.Body()}, utils.Attribute{Key: "dappID", Value: dappID}) if test_mode { apil.logger.LogTestMode(fiberCtx) } @@ -413,6 +412,13 @@ func (apil *JsonRPCChainListener) Serve(ctx context.Context, cmdFlags common.Con consumerIp := fiberCtx.Get(common.IP_FORWARDING_HEADER_NAME, fiberCtx.IP()) metadataValues := fiberCtx.GetReqHeaders() headers := convertToMetadataMap(metadataValues) + utils.LavaFormatInfo("in <<<", + utils.LogAttr("GUID", ctx), + utils.LogAttr("seed", msgSeed), + utils.LogAttr("msg", fiberCtx.Body()), + utils.LogAttr("dappID", dappID), + utils.LogAttr("headers", headers), + ) relayResult, err := apil.relaySender.SendRelay(ctx, "", string(fiberCtx.Body()), http.MethodPost, dappID, consumerIp, metricsData, headers) reply := relayResult.GetReply() go apil.logger.AddMetricForHttp(metricsData, err, fiberCtx.GetReqHeaders()) diff --git a/protocol/chainlib/rest.go b/protocol/chainlib/rest.go index 9b8a9f4173..ea89b74244 100644 --- a/protocol/chainlib/rest.go +++ b/protocol/chainlib/rest.go @@ -289,7 +289,13 @@ func (apil *RestChainListener) Serve(ctx context.Context, cmdFlags common.Consum // contentType := string(c.Context().Request.Header.ContentType()) dappID := extractDappIDFromFiberContext(fiberCtx) analytics := metrics.NewRelayAnalytics(dappID, chainID, apiInterface) - utils.LavaFormatInfo("in <<<", utils.Attribute{Key: "GUID", Value: ctx}, utils.Attribute{Key: "path", Value: path}, utils.Attribute{Key: "dappID", Value: dappID}, utils.Attribute{Key: "msgSeed", Value: msgSeed}) + utils.LavaFormatInfo("in <<<", + utils.LogAttr("GUID", ctx), + utils.LogAttr("path", path), + utils.LogAttr("dappID", dappID), + utils.LogAttr("msgSeed", msgSeed), + utils.LogAttr("headers", restHeaders), + ) requestBody := string(fiberCtx.Body()) relayResult, err := apil.relaySender.SendRelay(ctx, path+query, requestBody, http.MethodPost, dappID, fiberCtx.Get(common.IP_FORWARDING_HEADER_NAME, fiberCtx.IP()), analytics, restHeaders) reply := relayResult.GetReply() @@ -346,7 +352,13 @@ func (apil *RestChainListener) Serve(ctx context.Context, cmdFlags common.Consum msgSeed = strconv.FormatUint(guid, 10) } defer cancel() // incase there's a problem make sure to cancel the connection - utils.LavaFormatInfo("in <<<", utils.Attribute{Key: "GUID", Value: ctx}, utils.Attribute{Key: "path", Value: path}, utils.Attribute{Key: "dappID", Value: dappID}, utils.Attribute{Key: "msgSeed", Value: msgSeed}) + utils.LavaFormatInfo("in <<<", + utils.LogAttr("GUID", ctx), + utils.LogAttr("path", path), + utils.LogAttr("dappID", dappID), + utils.LogAttr("msgSeed", msgSeed), + utils.LogAttr("headers", restHeaders), + ) relayResult, err := apil.relaySender.SendRelay(ctx, path+query, "", fiberCtx.Method(), dappID, fiberCtx.Get(common.IP_FORWARDING_HEADER_NAME, fiberCtx.IP()), analytics, restHeaders) reply := relayResult.GetReply() go apil.logger.AddMetricForHttp(analytics, err, fiberCtx.GetReqHeaders()) diff --git a/protocol/chainlib/tendermintRPC.go b/protocol/chainlib/tendermintRPC.go index fececd7af0..629867e808 100644 --- a/protocol/chainlib/tendermintRPC.go +++ b/protocol/chainlib/tendermintRPC.go @@ -432,9 +432,15 @@ func (apil *TendermintRpcChainListener) Serve(ctx context.Context, cmdFlags comm ctx = utils.WithUniqueIdentifier(ctx, guid) defer cancel() // incase there's a problem make sure to cancel the connection msgSeed := strconv.FormatUint(guid, 10) - utils.LavaFormatInfo("in <<<", utils.Attribute{Key: "GUID", Value: ctx}, utils.Attribute{Key: "seed", Value: msgSeed}, utils.Attribute{Key: "msg", Value: fiberCtx.Body()}, utils.Attribute{Key: "dappID", Value: dappID}) metadataValues := fiberCtx.GetReqHeaders() headers := convertToMetadataMap(metadataValues) + utils.LavaFormatInfo("in <<<", + utils.LogAttr("GUID", ctx), + utils.LogAttr("seed", msgSeed), + utils.LogAttr("msg", fiberCtx.Body()), + utils.LogAttr("dappID", dappID), + utils.LogAttr("headers", headers), + ) relayResult, err := apil.relaySender.SendRelay(ctx, "", string(fiberCtx.Body()), "", dappID, fiberCtx.Get(common.IP_FORWARDING_HEADER_NAME, fiberCtx.IP()), metricsData, headers) reply := relayResult.GetReply() go apil.logger.AddMetricForHttp(metricsData, err, fiberCtx.GetReqHeaders()) @@ -482,10 +488,15 @@ func (apil *TendermintRpcChainListener) Serve(ctx context.Context, cmdFlags comm guid := utils.GenerateUniqueIdentifier() ctx = utils.WithUniqueIdentifier(ctx, guid) defer cancel() // incase there's a problem make sure to cancel the connection - utils.LavaFormatInfo("urirpc in <<<", utils.Attribute{Key: "GUID", Value: ctx}, utils.Attribute{Key: "msg", Value: path}, utils.Attribute{Key: "dappID", Value: dappID}) metricsData := metrics.NewRelayAnalytics(dappID, chainID, apiInterface) metadataValues := fiberCtx.GetReqHeaders() headers := convertToMetadataMap(metadataValues) + utils.LavaFormatInfo("urirpc in <<<", + utils.LogAttr("GUID", ctx), + utils.LogAttr("msg", path), + utils.LogAttr("dappID", dappID), + utils.LogAttr("headers", headers), + ) relayResult, err := apil.relaySender.SendRelay(ctx, path+query, "", "", dappID, fiberCtx.Get(common.IP_FORWARDING_HEADER_NAME, fiberCtx.IP()), metricsData, headers) msgSeed := strconv.FormatUint(guid, 10) reply := relayResult.GetReply() diff --git a/protocol/rpcconsumer/rpcconsumer_server.go b/protocol/rpcconsumer/rpcconsumer_server.go index 325de3070a..f99820b4df 100644 --- a/protocol/rpcconsumer/rpcconsumer_server.go +++ b/protocol/rpcconsumer/rpcconsumer_server.go @@ -874,6 +874,7 @@ func (rpccs *RPCConsumerServer) HandleDirectiveHeadersForMessage(chainMessage ch timeout, err := time.ParseDuration(timeoutStr) if err == nil { // set an override timeout + utils.LavaFormatDebug("User indicated to set the timeout using flag", utils.LogAttr("timeout", timeoutStr)) chainMessage.TimeoutOverride(timeout) } }