Skip to content

Commit 216ee42

Browse files
committed
control: send current timestamp header with event streams
Status and ListenHistory API return events with one-sided timestamp for events that have not been completed yet. Because client and server may not have exactly the same time the client can't really be sure what these values mean without knowing the current server time as well. Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 64cdc0a commit 216ee42

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

control/control.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"golang.org/x/sync/errgroup"
4545
"google.golang.org/grpc"
4646
"google.golang.org/grpc/codes"
47+
"google.golang.org/grpc/metadata"
4748
"google.golang.org/grpc/status"
4849
)
4950

@@ -248,6 +249,9 @@ func (c *Controller) Export(ctx context.Context, req *tracev1.ExportTraceService
248249
}
249250

250251
func (c *Controller) ListenBuildHistory(req *controlapi.BuildHistoryRequest, srv controlapi.Control_ListenBuildHistoryServer) error {
252+
if err := sendTimestampHeader(srv); err != nil {
253+
return err
254+
}
251255
return c.history.Listen(srv.Context(), req, func(h *controlapi.BuildHistoryEvent) error {
252256
if err := srv.Send(h); err != nil {
253257
return err
@@ -438,6 +442,9 @@ func (c *Controller) Solve(ctx context.Context, req *controlapi.SolveRequest) (*
438442
}
439443

440444
func (c *Controller) Status(req *controlapi.StatusRequest, stream controlapi.Control_StatusServer) error {
445+
if err := sendTimestampHeader(stream); err != nil {
446+
return err
447+
}
441448
ch := make(chan *client.SolveStatus, 8)
442449

443450
eg, ctx := errgroup.WithContext(stream.Context())
@@ -647,3 +654,9 @@ func (cs *roContentStore) Update(ctx context.Context, info content.Info, fieldpa
647654
func (cs *roContentStore) Abort(ctx context.Context, ref string) error {
648655
return errors.Errorf("read-only content store")
649656
}
657+
658+
const timestampKey = "buildkit-current-timestamp"
659+
660+
func sendTimestampHeader(srv grpc.ServerStream) error {
661+
return srv.SendHeader(metadata.Pairs(timestampKey, time.Now().Format(time.RFC3339Nano)))
662+
}

0 commit comments

Comments
 (0)