Skip to content

Commit 9b1542a

Browse files
authored
feat: add invocationId to plugin interface (#262)
1 parent 1fe6881 commit 9b1542a

File tree

8 files changed

+30
-17
lines changed

8 files changed

+30
-17
lines changed

pkg/aspect/lint/bep.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func parseLinterMnemonicFromFilename(filename string) string {
132132
return s[len(s)-2]
133133
}
134134

135-
func (runner *LintBEPHandler) bepEventCallback(event *buildeventstream.BuildEvent, sn int64) error {
135+
func (runner *LintBEPHandler) bepEventCallback(event *buildeventstream.BuildEvent, sn int64, invocationId string) error {
136136
switch event.Payload.(type) {
137137

138138
case *buildeventstream.BuildEvent_WorkspaceInfo:

pkg/plugin/sdk/v1alpha4/plugin/grpc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (m *GRPCServer) BEPEventCallback(
7171
ctx context.Context,
7272
req *proto.BEPEventCallbackReq,
7373
) (*proto.BEPEventCallbackRes, error) {
74-
return &proto.BEPEventCallbackRes{}, m.Impl.BEPEventCallback(req.Event, req.SequenceNumber)
74+
return &proto.BEPEventCallbackRes{}, m.Impl.BEPEventCallback(req.Event, req.SequenceNumber, req.InvocationId)
7575
}
7676

7777
// Setup translates the gRPC call to the Plugin Setup implementation.
@@ -189,8 +189,8 @@ var _ Plugin = (*GRPCClient)(nil)
189189

190190
// BEPEventCallback is called from the Core to execute the Plugin
191191
// BEPEventCallback.
192-
func (m *GRPCClient) BEPEventCallback(event *buildeventstream.BuildEvent, sn int64) error {
193-
_, err := m.client.BEPEventCallback(context.Background(), &proto.BEPEventCallbackReq{Event: event, SequenceNumber: sn})
192+
func (m *GRPCClient) BEPEventCallback(event *buildeventstream.BuildEvent, sn int64, invocationId string) error {
193+
_, err := m.client.BEPEventCallback(context.Background(), &proto.BEPEventCallbackReq{Event: event, SequenceNumber: sn, InvocationId: invocationId})
194194
return err
195195
}
196196

pkg/plugin/sdk/v1alpha4/plugin/interface.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828

2929
// Plugin determines how an aspect Plugin should be implemented.
3030
type Plugin interface {
31-
BEPEventCallback(event *buildeventstream.BuildEvent, sn int64) error
31+
BEPEventCallback(event *buildeventstream.BuildEvent, sn int64, invocationId string) error
3232
CustomCommands() ([]*Command, error)
3333
PostBuildHook(
3434
isInteractiveMode bool,
@@ -88,7 +88,7 @@ func (*Base) Setup(*SetupConfig) error {
8888
}
8989

9090
// BEPEventCallback satisfies Plugin.BEPEventCallback.
91-
func (*Base) BEPEventCallback(*buildeventstream.BuildEvent, int64) error {
91+
func (*Base) BEPEventCallback(*buildeventstream.BuildEvent, int64, string) error {
9292
return nil
9393
}
9494

pkg/plugin/sdk/v1alpha4/proto/plugin.pb.go

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/plugin/sdk/v1alpha4/proto/plugin.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ service Plugin {
2020
message BEPEventCallbackReq {
2121
build_event_stream.BuildEvent event = 1;
2222
int64 sequence_number = 2;
23+
string invocation_id = 3;
2324
}
2425

2526
message BEPEventCallbackRes {}

pkg/plugin/system/bep/bes_backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (bb *besBackend) RegisterBesProxy(ctx context.Context, p besproxy.BESProxy)
212212

213213
// CallbackFn is the signature for the callback function used by the subscribers
214214
// of the Build Event Protocol events.
215-
type CallbackFn func(*buildeventstream.BuildEvent, int64) error
215+
type CallbackFn func(*buildeventstream.BuildEvent, int64, string) error
216216

217217
// RegisterSubscriber registers a new subscriber callback function to the
218218
// Build Event Protocol events.
@@ -285,7 +285,7 @@ func (bb *besBackend) SendEventsToSubscribers(c <-chan *buildv1.PublishBuildTool
285285
}
286286
s := subscribers.head
287287
for s != nil {
288-
if err := s.callback(buildEvent, req.GetOrderedBuildEvent().GetSequenceNumber()); err != nil {
288+
if err := s.callback(buildEvent, req.GetOrderedBuildEvent().GetSequenceNumber(), req.GetOrderedBuildEvent().GetStreamId().GetInvocationId()); err != nil {
289289
bb.errorsMutex.Lock()
290290
bb.errors.Insert(err)
291291
bb.errorsMutex.Unlock()

pkg/plugin/system/bep/bes_backend_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func TestPublishBuildToolEventStream(t *testing.T) {
362362
var anyBuildEvent anypb.Any
363363
anyBuildEvent.MarshalFrom(buildEvent)
364364
event := &buildv1.BuildEvent{Event: &buildv1.BuildEvent_BazelEvent{BazelEvent: &anyBuildEvent}}
365-
streamId := &buildv1.StreamId{BuildId: "1"}
365+
streamId := &buildv1.StreamId{BuildId: "1", InvocationId: "1bdca2c1-fa12-4097-b538-4707ce8fe50d"}
366366
orderedBuildEvent := &buildv1.OrderedBuildEvent{
367367
StreamId: streamId,
368368
SequenceNumber: 1,
@@ -398,23 +398,26 @@ func TestPublishBuildToolEventStream(t *testing.T) {
398398
}
399399
close(besBackend.ready)
400400
var calledSubscriber1, calledSubscriber2, calledSubscriber3 bool
401-
besBackend.RegisterSubscriber(func(evt *buildeventstream.BuildEvent, sn int64) error {
401+
besBackend.RegisterSubscriber(func(evt *buildeventstream.BuildEvent, sn int64, invocationId string) error {
402402
// g.Expect(evt).To(Equal(buildEvent))
403403
g.Expect(sn).To(Equal(orderedBuildEvent.SequenceNumber))
404+
g.Expect(invocationId).To(Equal(orderedBuildEvent.StreamId.InvocationId))
404405
calledSubscriber1 = true
405406
return nil
406407
}, false)
407408
expectedSubscriber2Err := fmt.Errorf("error from subscriber 2")
408-
besBackend.RegisterSubscriber(func(evt *buildeventstream.BuildEvent, sn int64) error {
409+
besBackend.RegisterSubscriber(func(evt *buildeventstream.BuildEvent, sn int64, invocationId string) error {
409410
// g.Expect(evt).To(Equal(buildEvent))
410411
g.Expect(sn).To(Equal(orderedBuildEvent.SequenceNumber))
412+
g.Expect(invocationId).To(Equal(orderedBuildEvent.StreamId.InvocationId))
411413
calledSubscriber2 = true
412414
return expectedSubscriber2Err
413415
}, false)
414416
expectedSubscriber3Err := fmt.Errorf("error from subscriber 3")
415-
besBackend.RegisterSubscriber(func(evt *buildeventstream.BuildEvent, sn int64) error {
417+
besBackend.RegisterSubscriber(func(evt *buildeventstream.BuildEvent, sn int64, invocationId string) error {
416418
// g.Expect(evt).To(Equal(buildEvent))
417419
g.Expect(sn).To(Equal(orderedBuildEvent.SequenceNumber))
420+
g.Expect(invocationId).To(Equal(orderedBuildEvent.StreamId.InvocationId))
418421
calledSubscriber3 = true
419422
return expectedSubscriber3Err
420423
}, false)

pkg/plugin/system/bep/bes_pipe.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func (bb *besPipe) streamBesEvents(ctx context.Context, conn *os.File) error {
228228

229229
seqId++
230230

231-
if err := bb.publishBesEvent(seqId, &event); err != nil {
231+
if err := bb.publishBesEvent(seqId, bb.besInvocationId, &event); err != nil {
232232
return fmt.Errorf("failed to publish BES event: %w", err)
233233
}
234234

@@ -243,14 +243,14 @@ func (bb *besPipe) streamBesEvents(ctx context.Context, conn *os.File) error {
243243
return nil
244244
}
245245

246-
func (bb *besPipe) publishBesEvent(seqId int64, event *buildeventstream.BuildEvent) error {
246+
func (bb *besPipe) publishBesEvent(seqId int64, invocationId string, event *buildeventstream.BuildEvent) error {
247247
eg := errgroup.Group{}
248248

249249
for s := bb.subscribers.head; s != nil; s = s.next {
250250
cb := s.callback
251251
eg.Go(
252252
func() error {
253-
return cb(event, seqId)
253+
return cb(event, seqId, invocationId)
254254
},
255255
)
256256
}

0 commit comments

Comments
 (0)