From 7835bc0bda32b8426fc3e54c97818f2f92de78ec Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Thu, 2 Nov 2023 17:52:01 +0100 Subject: [PATCH] Cleanup --- cmd/request.go | 70 ++++++-------------------------------------------- cmd/root.go | 3 --- 2 files changed, 8 insertions(+), 65 deletions(-) diff --git a/cmd/request.go b/cmd/request.go index d27978a3..57026c74 100644 --- a/cmd/request.go +++ b/cmd/request.go @@ -130,13 +130,6 @@ func Request(ctx context.Context, ready chan bool) int { )) defer span.End() - // Construct the request - req, err := createInitialRequest() - if err != nil { - log.WithContext(ctx).WithError(err).Error("Failed to create initial request") - return 1 - } - gatewayUrl := viper.GetString("gateway-url") if gatewayUrl == "" { gatewayUrl = fmt.Sprintf("%v/api/gateway", viper.GetString("url")) @@ -178,14 +171,6 @@ func Request(ctx context.Context, ready chan bool) int { } defer c.Close(ctx) - // Log the request in JSON - b, err := json.MarshalIndent(req, "", " ") - if err != nil { - log.WithContext(ctx).WithFields(lf).WithError(err).Error("Failed to marshal request for logging") - return 1 - } - - log.WithContext(ctx).WithFields(lf).Infof("Request:\n%v", string(b)) q, err := createQuery() if err != nil { log.WithContext(ctx).WithFields(lf).WithError(err).Error("Failed to create query") @@ -198,6 +183,14 @@ func Request(ctx context.Context, ready chan bool) int { } log.WithContext(ctx).WithFields(lf).WithError(err).Info("received items") + // Log the request in JSON + b, err := json.MarshalIndent(q, "", " ") + if err != nil { + log.WithContext(ctx).WithFields(lf).WithError(err).Error("Failed to marshal query for logging") + return 1 + } + log.WithContext(ctx).WithFields(lf).Infof("Query:\n%v", string(b)) + err = c.Wait(ctx, uuid.UUIDs{uuid.UUID(q.UUID)}) if err != nil { log.WithContext(ctx).WithFields(lf).WithError(err).Error("queries failed") @@ -255,53 +248,6 @@ func createQuery() (*sdp.Query, error) { }, nil } -func createInitialRequest() (*sdp.GatewayRequest, error) { - req := &sdp.GatewayRequest{ - MinStatusInterval: minStatusInterval, - } - - switch viper.GetString("request-type") { - case "query": - q, err := createQuery() - if err != nil { - return nil, err - } - - req.RequestType = &sdp.GatewayRequest_Query{ - Query: q, - } - case "load-bookmark": - bookmarkUUID, err := uuid.Parse(viper.GetString("bookmark-uuid")) - if err != nil { - return nil, err - } - msgID := uuid.New() - req.RequestType = &sdp.GatewayRequest_LoadBookmark{ - LoadBookmark: &sdp.LoadBookmark{ - UUID: bookmarkUUID[:], - MsgID: msgID[:], - IgnoreCache: viper.GetBool("ignore-cache"), - }, - } - case "load-snapshot": - snapshotUUID, err := uuid.Parse(viper.GetString("snapshot-uuid")) - if err != nil { - return nil, err - } - msgID := uuid.New() - req.RequestType = &sdp.GatewayRequest_LoadSnapshot{ - LoadSnapshot: &sdp.LoadSnapshot{ - UUID: snapshotUUID[:], - MsgID: msgID[:], - }, - } - default: - return nil, fmt.Errorf("request type %v not supported", viper.GetString("request-type")) - } - - return req, nil -} - func init() { rootCmd.AddCommand(requestCmd) diff --git a/cmd/root.go b/cmd/root.go index 2b1a1faa..a5bc7911 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -24,13 +24,10 @@ import ( "github.com/spf13/viper" "github.com/uptrace/opentelemetry-go-extra/otellogrus" "golang.org/x/oauth2" - "google.golang.org/protobuf/types/known/durationpb" ) var logLevel string -var minStatusInterval = durationpb.New(250 * time.Millisecond) - //go:generate sh -c "echo -n $(git describe --tags --long) > commit.txt" //go:embed commit.txt var cliVersion string