Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidS-ovm committed Nov 2, 2023
1 parent a51355c commit 7835bc0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 65 deletions.
70 changes: 8 additions & 62 deletions cmd/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 0 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7835bc0

Please sign in to comment.