1
0
mirror of https://github.com/moby/buildkit.git synced 2025-04-18 18:04:03 +03:00

exporter: allow session exporter to access refs

Expose existing Gateway API file access function to the
session exporter callback so it can make better decisions.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi 2025-04-10 23:36:22 -07:00
parent 79124b8aba
commit c66c687542
No known key found for this signature in database
GPG Key ID: AFA9DE5F8AB7AF39
9 changed files with 196 additions and 86 deletions

View File

@ -53,7 +53,8 @@ func (c *Client) Build(ctx context.Context, opt SolveOpt, product string, buildF
return err
}
gwClient.caps = g.BuildOpts().Caps
caps := g.BuildOpts().Caps
gwClient.caps = &caps
if err := g.Run(ctx, buildFunc); err != nil {
return errors.Wrap(err, "failed to run Build function")
@ -72,10 +73,14 @@ func (c *Client) gatewayClientForBuild(buildid string) *gatewayClientForBuild {
}
}
func (c *Client) GatewayClientForBuild(buildid string) gatewayapi.LLBBridgeClient {
return c.gatewayClientForBuild(buildid)
}
type gatewayClientForBuild struct {
gateway gatewayapi.LLBBridgeClient
buildID string
caps apicaps.CapSet
caps *apicaps.CapSet
}
func (g *gatewayClientForBuild) ResolveImageConfig(ctx context.Context, in *gatewayapi.ResolveImageConfigRequest, opts ...grpc.CallOption) (*gatewayapi.ResolveImageConfigResponse, error) {
@ -99,29 +104,35 @@ func (g *gatewayClientForBuild) ReadFile(ctx context.Context, in *gatewayapi.Rea
}
func (g *gatewayClientForBuild) ReadDir(ctx context.Context, in *gatewayapi.ReadDirRequest, opts ...grpc.CallOption) (*gatewayapi.ReadDirResponse, error) {
if err := g.caps.Supports(gatewayapi.CapReadDir); err != nil {
return nil, err
if g.caps != nil {
if err := g.caps.Supports(gatewayapi.CapReadDir); err != nil {
return nil, err
}
}
ctx = buildid.AppendToOutgoingContext(ctx, g.buildID)
return g.gateway.ReadDir(ctx, in, opts...)
}
func (g *gatewayClientForBuild) StatFile(ctx context.Context, in *gatewayapi.StatFileRequest, opts ...grpc.CallOption) (*gatewayapi.StatFileResponse, error) {
if err := g.caps.Supports(gatewayapi.CapStatFile); err != nil {
return nil, err
if g.caps != nil {
if err := g.caps.Supports(gatewayapi.CapStatFile); err != nil {
return nil, err
}
}
ctx = buildid.AppendToOutgoingContext(ctx, g.buildID)
return g.gateway.StatFile(ctx, in, opts...)
}
func (g *gatewayClientForBuild) Evaluate(ctx context.Context, in *gatewayapi.EvaluateRequest, opts ...grpc.CallOption) (*gatewayapi.EvaluateResponse, error) {
if err := g.caps.Supports(gatewayapi.CapGatewayEvaluate); err != nil {
if err2 := g.caps.Supports(gatewayapi.CapStatFile); err2 != nil {
return nil, err
if g.caps != nil {
if err := g.caps.Supports(gatewayapi.CapGatewayEvaluate); err != nil {
if err2 := g.caps.Supports(gatewayapi.CapStatFile); err2 != nil {
return nil, err
}
ctx = buildid.AppendToOutgoingContext(ctx, g.buildID)
_, err := g.gateway.StatFile(ctx, &gatewayapi.StatFileRequest{Ref: in.Ref, Path: "."}, opts...)
return &gatewayapi.EvaluateResponse{}, err
}
ctx = buildid.AppendToOutgoingContext(ctx, g.buildID)
_, err := g.gateway.StatFile(ctx, &gatewayapi.StatFileRequest{Ref: in.Ref, Path: "."}, opts...)
return &gatewayapi.EvaluateResponse{}, err
}
ctx = buildid.AppendToOutgoingContext(ctx, g.buildID)
return g.gateway.Evaluate(ctx, in, opts...)
@ -138,32 +149,40 @@ func (g *gatewayClientForBuild) Return(ctx context.Context, in *gatewayapi.Retur
}
func (g *gatewayClientForBuild) Inputs(ctx context.Context, in *gatewayapi.InputsRequest, opts ...grpc.CallOption) (*gatewayapi.InputsResponse, error) {
if err := g.caps.Supports(gatewayapi.CapFrontendInputs); err != nil {
return nil, err
if g.caps != nil {
if err := g.caps.Supports(gatewayapi.CapFrontendInputs); err != nil {
return nil, err
}
}
ctx = buildid.AppendToOutgoingContext(ctx, g.buildID)
return g.gateway.Inputs(ctx, in, opts...)
}
func (g *gatewayClientForBuild) NewContainer(ctx context.Context, in *gatewayapi.NewContainerRequest, opts ...grpc.CallOption) (*gatewayapi.NewContainerResponse, error) {
if err := g.caps.Supports(gatewayapi.CapGatewayExec); err != nil {
return nil, err
if g.caps != nil {
if err := g.caps.Supports(gatewayapi.CapGatewayExec); err != nil {
return nil, err
}
}
ctx = buildid.AppendToOutgoingContext(ctx, g.buildID)
return g.gateway.NewContainer(ctx, in, opts...)
}
func (g *gatewayClientForBuild) ReleaseContainer(ctx context.Context, in *gatewayapi.ReleaseContainerRequest, opts ...grpc.CallOption) (*gatewayapi.ReleaseContainerResponse, error) {
if err := g.caps.Supports(gatewayapi.CapGatewayExec); err != nil {
return nil, err
if g.caps != nil {
if err := g.caps.Supports(gatewayapi.CapGatewayExec); err != nil {
return nil, err
}
}
ctx = buildid.AppendToOutgoingContext(ctx, g.buildID)
return g.gateway.ReleaseContainer(ctx, in, opts...)
}
func (g *gatewayClientForBuild) ExecProcess(ctx context.Context, opts ...grpc.CallOption) (gatewayapi.LLBBridge_ExecProcessClient, error) {
if err := g.caps.Supports(gatewayapi.CapGatewayExec); err != nil {
return nil, err
if g.caps != nil {
if err := g.caps.Supports(gatewayapi.CapGatewayExec); err != nil {
return nil, err
}
}
ctx = buildid.AppendToOutgoingContext(ctx, g.buildID)
return g.gateway.ExecProcess(ctx, opts...)

View File

@ -2315,6 +2315,7 @@ func testOCILayoutSource(t *testing.T, sb integration.Sandbox) {
}
func testSessionExporter(t *testing.T, sb integration.Sandbox) {
integration.SkipOnPlatform(t, "windows")
workers.CheckFeatureCompat(t, sb, workers.FeatureOCIExporter, workers.FeatureOCILayout)
c, err := New(context.TODO(), sb.Address())
require.NoError(t, err)
@ -2332,10 +2333,7 @@ func testSessionExporter(t *testing.T, sb integration.Sandbox) {
st = busybox.Run(llb.Shlex(cmd), llb.Dir("/wd")).AddMount("/wd", st)
}
cmdPrefix := integration.UnixOrWindows(
`sh -c "echo -n`,
`cmd /C "echo`,
)
cmdPrefix := `sh -c "echo -n`
run(fmt.Sprintf(`%s first > foo"`, cmdPrefix))
run(fmt.Sprintf(`%s second > bar"`, cmdPrefix))
@ -2347,9 +2345,26 @@ func testSessionExporter(t *testing.T, sb integration.Sandbox) {
attachable = append(attachable, target)
buildID := identity.NewID()
outW := bytes.NewBuffer(nil)
exporterCalled := false
exporter := exporterprovider.New(func(ctx context.Context, md map[string][]byte) ([]*exporter.ExporterRequest, error) {
exporter := exporterprovider.New(func(ctx context.Context, md map[string][]byte, refs []string) ([]*exporter.ExporterRequest, error) {
require.Len(t, refs, 1)
g := c.GatewayClientForBuild(buildID)
resp, err := g.ReadDir(sb.Context(), &gatewaypb.ReadDirRequest{
Ref: refs[0],
DirPath: "/",
})
if err != nil {
return nil, err
}
t.Logf("readdir: %v", resp)
require.Equal(t, 2, len(resp.Entries))
require.Equal(t, "bar", resp.Entries[0].Path)
require.Equal(t, "foo", resp.Entries[1].Path)
exporterCalled = true
target.Add(filesync.WithFSSync(0, fixedWriteCloser(nopWriteCloser{outW})))
return []*exporter.ExporterRequest{
@ -2364,9 +2379,14 @@ func testSessionExporter(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)
attachable = append(attachable, exporter)
_, err = c.Solve(sb.Context(), def, SolveOpt{
_, err = c.Build(sb.Context(), SolveOpt{
EnableSessionExporter: true,
Session: attachable,
Ref: buildID,
}, "", func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
return c.Solve(ctx, gateway.SolveRequest{
Definition: def.ToPB(),
})
}, nil)
require.NoError(t, err)

View File

@ -891,10 +891,18 @@ func (lbf *llbBridgeForwarder) Solve(ctx context.Context, req *pb.SolveRequest)
func (lbf *llbBridgeForwarder) getImmutableRef(ctx context.Context, id string) (cache.ImmutableRef, error) {
lbf.mu.Lock()
ref, ok := lbf.refs[id]
lbf.mu.Unlock()
if !ok {
return nil, errors.Errorf("no such ref: %s", id)
if lbf.result != nil {
if r, ok := lbf.result.FindRef(id); ok {
ref = r
}
}
if ref == nil {
lbf.mu.Unlock()
return nil, errors.Errorf("no such ref: %s, all %+v", id, maps.Keys(lbf.refs))
}
}
lbf.mu.Unlock()
if ref == nil {
return nil, errors.Errorf("empty ref: %s", id)
}

View File

@ -1,21 +0,0 @@
package exporter
import (
"context"
"github.com/moby/buildkit/session"
"github.com/pkg/errors"
)
func New(ctx context.Context, c session.Caller, result map[string][]byte) ([]*ExporterRequest, error) {
client := NewExporterClient(c.Conn())
res, err := client.FindExporters(ctx, &FindExportersRequest{
Metadata: result,
})
if err != nil {
return nil, errors.WithStack(err)
}
return res.Exporters, nil
}

View File

@ -26,6 +26,7 @@ type FindExportersRequest struct {
unknownFields protoimpl.UnknownFields
Metadata map[string][]byte `protobuf:"bytes,1,rep,name=metadata,proto3" json:"metadata,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
Refs []string `protobuf:"bytes,2,rep,name=refs,proto3" json:"refs,omitempty"`
}
func (x *FindExportersRequest) Reset() {
@ -65,6 +66,13 @@ func (x *FindExportersRequest) GetMetadata() map[string][]byte {
return nil
}
func (x *FindExportersRequest) GetRefs() []string {
if x != nil {
return x.Refs
}
return nil
}
type FindExportersResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -170,44 +178,45 @@ var file_github_com_moby_buildkit_session_exporter_exporter_proto_rawDesc = []by
0x79, 0x2f, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x6b, 0x69, 0x74, 0x2f, 0x73, 0x65, 0x73, 0x73, 0x69,
0x6f, 0x6e, 0x2f, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x2f, 0x65, 0x78, 0x70, 0x6f,
0x72, 0x74, 0x65, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x10, 0x6d, 0x6f, 0x62, 0x79,
0x2e, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x22, 0xa5, 0x01, 0x0a,
0x2e, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x22, 0xb9, 0x01, 0x0a,
0x14, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x73, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x50, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74,
0x61, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x34, 0x2e, 0x6d, 0x6f, 0x62, 0x79, 0x2e, 0x65,
0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x69, 0x6e, 0x64, 0x45,
0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e,
0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x6d,
0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x64,
0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61,
0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65,
0x3a, 0x02, 0x38, 0x01, 0x22, 0x58, 0x0a, 0x15, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x78, 0x70, 0x6f,
0x72, 0x74, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3f, 0x0a,
0x09, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b,
0x32, 0x21, 0x2e, 0x6d, 0x6f, 0x62, 0x79, 0x2e, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72,
0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x52, 0x09, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x73, 0x22, 0xa3,
0x01, 0x0a, 0x0f, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65,
0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x42, 0x0a, 0x05, 0x41, 0x74, 0x74, 0x72, 0x73, 0x18,
0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2c, 0x2e, 0x6d, 0x6f, 0x62, 0x79, 0x2e, 0x65, 0x78, 0x70,
0x6f, 0x72, 0x74, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65,
0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x41, 0x74, 0x74, 0x72, 0x73, 0x45, 0x6e,
0x74, 0x72, 0x79, 0x52, 0x05, 0x41, 0x74, 0x74, 0x72, 0x73, 0x1a, 0x38, 0x0a, 0x0a, 0x41, 0x74,
0x74, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61,
0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65,
0x3a, 0x02, 0x38, 0x01, 0x32, 0x6c, 0x0a, 0x08, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72,
0x12, 0x60, 0x0a, 0x0d, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72,
0x73, 0x12, 0x26, 0x2e, 0x6d, 0x6f, 0x62, 0x79, 0x2e, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65,
0x72, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65,
0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x6d, 0x6f, 0x62, 0x79,
0x2e, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x69, 0x6e,
0x64, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x42, 0x2b, 0x5a, 0x29, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d,
0x2f, 0x6d, 0x6f, 0x62, 0x79, 0x2f, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x6b, 0x69, 0x74, 0x2f, 0x73,
0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x2f, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x62,
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x65, 0x66, 0x73, 0x18,
0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x72, 0x65, 0x66, 0x73, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d,
0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03,
0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14,
0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76,
0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x58, 0x0a, 0x15, 0x46, 0x69, 0x6e, 0x64,
0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x12, 0x3f, 0x0a, 0x09, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x73, 0x18, 0x01,
0x20, 0x03, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x6d, 0x6f, 0x62, 0x79, 0x2e, 0x65, 0x78, 0x70, 0x6f,
0x72, 0x74, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x09, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65,
0x72, 0x73, 0x22, 0xa3, 0x01, 0x0a, 0x0f, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01,
0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x42, 0x0a, 0x05, 0x41, 0x74,
0x74, 0x72, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2c, 0x2e, 0x6d, 0x6f, 0x62, 0x79,
0x2e, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x78, 0x70,
0x6f, 0x72, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x41, 0x74, 0x74,
0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x41, 0x74, 0x74, 0x72, 0x73, 0x1a, 0x38,
0x0a, 0x0a, 0x41, 0x74, 0x74, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03,
0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14,
0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76,
0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, 0x6c, 0x0a, 0x08, 0x45, 0x78, 0x70, 0x6f,
0x72, 0x74, 0x65, 0x72, 0x12, 0x60, 0x0a, 0x0d, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x78, 0x70, 0x6f,
0x72, 0x74, 0x65, 0x72, 0x73, 0x12, 0x26, 0x2e, 0x6d, 0x6f, 0x62, 0x79, 0x2e, 0x65, 0x78, 0x70,
0x6f, 0x72, 0x74, 0x65, 0x72, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x78, 0x70,
0x6f, 0x72, 0x74, 0x65, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e,
0x6d, 0x6f, 0x62, 0x79, 0x2e, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x2e, 0x76, 0x31,
0x2e, 0x46, 0x69, 0x6e, 0x64, 0x45, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x72, 0x73, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x2b, 0x5a, 0x29, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62,
0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6d, 0x6f, 0x62, 0x79, 0x2f, 0x62, 0x75, 0x69, 0x6c, 0x64, 0x6b,
0x69, 0x74, 0x2f, 0x73, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x2f, 0x65, 0x78, 0x70, 0x6f, 0x72,
0x74, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (

View File

@ -10,6 +10,7 @@ service Exporter {
message FindExportersRequest{
map<string, bytes> metadata = 1;
repeated string refs = 2;
}
message FindExportersResponse {
@ -19,4 +20,4 @@ message FindExportersResponse {
message ExporterRequest {
string Type = 1;
map<string, string> Attrs = 2;
}
}

View File

@ -33,6 +33,11 @@ func (m *FindExportersRequest) CloneVT() *FindExportersRequest {
}
r.Metadata = tmpContainer
}
if rhs := m.Refs; rhs != nil {
tmpContainer := make([]string, len(rhs))
copy(tmpContainer, rhs)
r.Refs = tmpContainer
}
if len(m.unknownFields) > 0 {
r.unknownFields = make([]byte, len(m.unknownFields))
copy(r.unknownFields, m.unknownFields)
@ -109,6 +114,15 @@ func (this *FindExportersRequest) EqualVT(that *FindExportersRequest) bool {
return false
}
}
if len(this.Refs) != len(that.Refs) {
return false
}
for i, vx := range this.Refs {
vy := that.Refs[i]
if vx != vy {
return false
}
}
return string(this.unknownFields) == string(that.unknownFields)
}
@ -213,6 +227,15 @@ func (m *FindExportersRequest) MarshalToSizedBufferVT(dAtA []byte) (int, error)
i -= len(m.unknownFields)
copy(dAtA[i:], m.unknownFields)
}
if len(m.Refs) > 0 {
for iNdEx := len(m.Refs) - 1; iNdEx >= 0; iNdEx-- {
i -= len(m.Refs[iNdEx])
copy(dAtA[i:], m.Refs[iNdEx])
i = protohelpers.EncodeVarint(dAtA, i, uint64(len(m.Refs[iNdEx])))
i--
dAtA[i] = 0x12
}
}
if len(m.Metadata) > 0 {
for k := range m.Metadata {
v := m.Metadata[k]
@ -354,6 +377,12 @@ func (m *FindExportersRequest) SizeVT() (n int) {
n += mapEntrySize + 1 + protohelpers.SizeOfVarint(uint64(mapEntrySize))
}
}
if len(m.Refs) > 0 {
for _, s := range m.Refs {
l = len(s)
n += 1 + l + protohelpers.SizeOfVarint(uint64(l))
}
}
n += len(m.unknownFields)
return n
}
@ -553,6 +582,38 @@ func (m *FindExportersRequest) UnmarshalVT(dAtA []byte) error {
}
m.Metadata[mapkey] = mapvalue
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Refs", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return protohelpers.ErrIntOverflow
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return protohelpers.ErrInvalidLength
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return protohelpers.ErrInvalidLength
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Refs = append(m.Refs, string(dAtA[iNdEx:postIndex]))
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := protohelpers.Skip(dAtA[iNdEx:])

View File

@ -9,7 +9,7 @@ import (
"google.golang.org/grpc/status"
)
type Callback func(ctx context.Context, md map[string][]byte) ([]*exporter.ExporterRequest, error)
type Callback func(ctx context.Context, md map[string][]byte, refs []string) ([]*exporter.ExporterRequest, error)
func New(cb Callback) *Exporter {
return &Exporter{
@ -29,7 +29,7 @@ func (e *Exporter) FindExporters(ctx context.Context, in *exporter.FindExporters
if e.cb == nil {
return nil, status.Errorf(codes.Unavailable, "no exporter callback registered")
}
res, err := e.cb(ctx, in.Metadata)
res, err := e.cb(ctx, in.Metadata, in.Refs)
if err != nil {
return nil, err
}

View File

@ -684,7 +684,20 @@ func (s *Solver) getSessionExporters(ctx context.Context, sessionID string, id i
return nil, err
}
res, err := sessionexporter.New(ctx, caller, inp.Metadata)
client := sessionexporter.NewExporterClient(caller.Conn())
var ids []string
if err := inp.EachRef(func(ref cache.ImmutableRef) error {
ids = append(ids, ref.ID())
return nil
}); err != nil {
return nil, err
}
res, err := client.FindExporters(ctx, &sessionexporter.FindExportersRequest{
Metadata: inp.Metadata,
Refs: ids,
})
if err != nil {
switch grpcerrors.Code(err) {
case codes.Unavailable, codes.Unimplemented:
@ -700,7 +713,7 @@ func (s *Solver) getSessionExporters(ctx context.Context, sessionID string, id i
}
var out []exporter.ExporterInstance
for i, req := range res {
for i, req := range res.Exporters {
exp, err := w.Exporter(req.Type, s.sm)
if err != nil {
return nil, err