Skip to content

Commit a76724c

Browse files
authored
feat: ftl call -v prints out more info (just request key for now) (#4830)
- It can be helpful to know the request key to then understand what happened as part of the call (via the timeline) - Goose will make use of this - We will probably want more info in the future so i made the flag not request key specific - Verb router now includes the request key in the call response it creates
1 parent 7396f67 commit a76724c

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

cmd/ftl/cmd_call.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/block/ftl/common/reflection"
1919
"github.com/block/ftl/internal/log"
2020
"github.com/block/ftl/internal/rpc"
21+
"github.com/block/ftl/internal/rpc/headers"
2122
"github.com/block/ftl/internal/schema/schemaeventsource"
2223
status "github.com/block/ftl/internal/terminal"
2324
)
@@ -26,6 +27,7 @@ type callCmd struct {
2627
Wait time.Duration `short:"w" help:"Wait up to this elapsed time for the FTL cluster to become available." default:"1m"`
2728
Verb reflection.Ref `arg:"" required:"" help:"Full path of Verb to call." predictor:"verbs"`
2829
Request string `arg:"" optional:"" help:"JSON5 request payload." default:"{}"`
30+
Verbose bool `flag:"" short:"v" help:"Print verbose information."`
2931
}
3032

3133
func (c *callCmd) Run(
@@ -50,7 +52,7 @@ func (c *callCmd) Run(
5052

5153
logger.Debugf("Calling %s", c.Verb)
5254

53-
return callVerb(ctx, verbClient, schemaClient, c.Verb, requestJSON)
55+
return callVerb(ctx, verbClient, schemaClient, c.Verb, requestJSON, c.Verbose)
5456
}
5557

5658
func callVerb(
@@ -59,6 +61,7 @@ func callVerb(
5961
schemaClient *schemaeventsource.EventSource,
6062
verb reflection.Ref,
6163
requestJSON []byte,
64+
verbose bool,
6265
) error {
6366
logger := log.FromContext(ctx)
6467
// otherwise, we have a match so call the verb
@@ -78,6 +81,17 @@ func callVerb(
7881
if err != nil {
7982
return err
8083
}
84+
85+
if verbose {
86+
requestKey, ok, err := headers.GetRequestKey(resp.Header())
87+
if err != nil {
88+
return fmt.Errorf("could not get request key: %w", err)
89+
}
90+
if ok {
91+
fmt.Printf("RequestKey: %s\n", requestKey)
92+
}
93+
}
94+
8195
switch resp := resp.Msg.Response.(type) {
8296
case *ftlv1.CallResponse_Error_:
8397
if resp.Error.Stack != nil && logger.GetLevel() <= log.Debug {

cmd/ftl/cmd_replay.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import (
2020
)
2121

2222
type replayCmd struct {
23-
Wait time.Duration `short:"w" help:"Wait up to this elapsed time for the FTL cluster to become available." default:"1m"`
24-
Verb reflection.Ref `arg:"" required:"" help:"Full path of Verb to call." predictor:"verbs"`
23+
Wait time.Duration `short:"w" help:"Wait up to this elapsed time for the FTL cluster to become available." default:"1m"`
24+
Verb reflection.Ref `arg:"" required:"" help:"Full path of Verb to call." predictor:"verbs"`
25+
Verbose bool `flag:"" short:"v" help:"Print verbose information."`
2526
}
2627

2728
func (c *replayCmd) Run(
@@ -98,5 +99,5 @@ func (c *replayCmd) Run(
9899
logger.Infof("Calling %s with body:", c.Verb)
99100
status.PrintJSON(ctx, []byte(requestJSON))
100101
logger.Infof("Response:")
101-
return callVerb(ctx, verbClient, eventSource, c.Verb, []byte(requestJSON))
102+
return callVerb(ctx, verbClient, eventSource, c.Verb, []byte(requestJSON), c.Verbose)
102103
}

internal/routing/verb_routing.go

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func (s *VerbCallRouter) Call(ctx context.Context, req *connect.Request[ftlv1.Ca
8585
callEvent.Response = result.Ok(resp.Msg)
8686
s.timelineClient.Publish(ctx, callEvent)
8787
observability.Calls.Request(ctx, req.Msg.Verb, start, optional.None[string]())
88+
headers.SetRequestKey(resp.Header(), requestKey)
8889
return resp, nil
8990
}
9091

0 commit comments

Comments
 (0)