From 27daebbffb8b2ed25d6fbafd72d326d21969eaad Mon Sep 17 00:00:00 2001 From: Jeremy Shih Date: Fri, 18 Oct 2024 16:54:08 +0800 Subject: [PATCH] feat(run): add requester id in list model run response --- go.mod | 2 +- go.sum | 4 ++-- pkg/handler/mock_service_test.go | 4 ++-- pkg/handler/public.go | 2 +- pkg/repository/repository_test.go | 2 +- pkg/service/service.go | 18 +++++++++++------- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 61f75d37..5da82282 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.21.0 github.com/iancoleman/strcase v0.3.0 - github.com/instill-ai/protogen-go v0.3.3-alpha.0.20241012090311-e872dc0b511d + github.com/instill-ai/protogen-go v0.3.3-alpha.0.20241018065636-3056758898b9 github.com/instill-ai/usage-client v0.3.0-alpha github.com/instill-ai/x v0.4.0-alpha.0.20240923052503-fd243919e005 github.com/jackc/pgx/v5 v5.6.0 diff --git a/go.sum b/go.sum index 5cb478c4..8040b18d 100644 --- a/go.sum +++ b/go.sum @@ -229,8 +229,8 @@ github.com/hjson/hjson-go/v4 v4.0.0 h1:wlm6IYYqHjOdXH1gHev4VoXCaW20HdQAGCxdOEEg2 github.com/hjson/hjson-go/v4 v4.0.0/go.mod h1:KaYt3bTw3zhBjYqnXkYywcYctk0A2nxeEFTse3rH13E= github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI= github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= -github.com/instill-ai/protogen-go v0.3.3-alpha.0.20241012090311-e872dc0b511d h1:jf2RQtRFNxnPMkjTD0AAqXDXO8lHYOrWU3Hrr+yGEzY= -github.com/instill-ai/protogen-go v0.3.3-alpha.0.20241012090311-e872dc0b511d/go.mod h1:rf0UY7VpEgpaLudYEcjx5rnbuwlBaaLyD4FQmWLtgAY= +github.com/instill-ai/protogen-go v0.3.3-alpha.0.20241018065636-3056758898b9 h1:HSYe6H5PVl2QTlC4Z9j8Wmz7f1D1DywJkRnUlF+9t6o= +github.com/instill-ai/protogen-go v0.3.3-alpha.0.20241018065636-3056758898b9/go.mod h1:rf0UY7VpEgpaLudYEcjx5rnbuwlBaaLyD4FQmWLtgAY= github.com/instill-ai/usage-client v0.3.0-alpha h1:yY5eNn5zINqy8wpOogiNmrVYzJKnd1KMnMxlYBpr7Tk= github.com/instill-ai/usage-client v0.3.0-alpha/go.mod h1:8lvtZulkhQ7t8alttb2KkLKYoCp5u4oatzDbfFlEld0= github.com/instill-ai/x v0.4.0-alpha.0.20240923052503-fd243919e005 h1:6iUpJs545Ivvv2joJCQoawRPr2YRPjux22k7t+gWg6s= diff --git a/pkg/handler/mock_service_test.go b/pkg/handler/mock_service_test.go index 115b9e48..f47cc1fb 100644 --- a/pkg/handler/mock_service_test.go +++ b/pkg/handler/mock_service_test.go @@ -479,10 +479,10 @@ func (mr *MockServiceMockRecorder) ListModelRuns(arg0, arg1, arg2 interface{}) * } // ListModelRunsByRequester mocks base method. -func (m *MockService) ListModelRunsByRequester(arg0 context.Context, arg1 *modelv1alpha.ListModelRunsByCreditOwnerRequest) (*modelv1alpha.ListModelRunsByCreditOwnerResponse, error) { +func (m *MockService) ListModelRunsByRequester(arg0 context.Context, arg1 *modelv1alpha.ListModelRunsByRequesterRequest) (*modelv1alpha.ListModelRunsByRequesterResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "ListModelRunsByRequester", arg0, arg1) - ret0, _ := ret[0].(*modelv1alpha.ListModelRunsByCreditOwnerResponse) + ret0, _ := ret[0].(*modelv1alpha.ListModelRunsByRequesterResponse) ret1, _ := ret[1].(error) return ret0, ret1 } diff --git a/pkg/handler/public.go b/pkg/handler/public.go index e5b98a8c..200efaee 100644 --- a/pkg/handler/public.go +++ b/pkg/handler/public.go @@ -1140,7 +1140,7 @@ func (h *PublicHandler) ListModelRuns(ctx context.Context, req *modelpb.ListMode return resp, nil } -func (h *PublicHandler) ListModelRunsByCreditOwner(ctx context.Context, req *modelpb.ListModelRunsByCreditOwnerRequest) (*modelpb.ListModelRunsByCreditOwnerResponse, error) { +func (h *PublicHandler) ListModelRunsByRequester(ctx context.Context, req *modelpb.ListModelRunsByRequesterRequest) (*modelpb.ListModelRunsByRequesterResponse, error) { eventName := "ListModelRunsByRequester" diff --git a/pkg/repository/repository_test.go b/pkg/repository/repository_test.go index 21baf3be..9fe272fc 100644 --- a/pkg/repository/repository_test.go +++ b/pkg/repository/repository_test.go @@ -132,7 +132,7 @@ func MockNamespaceModel(t *testing.T, repo repository.Repository) *datamodel.Mod return models[0] } -func TestRepository_ListModelRunsByCreditOwner(t *testing.T) { +func TestRepository_ListModelRunsByRequester(t *testing.T) { c := qt.New(t) s, err := miniredis.Run() diff --git a/pkg/service/service.go b/pkg/service/service.go index 24167131..3bd2214f 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -102,7 +102,7 @@ type Service interface { CreateModelRun(ctx context.Context, triggerUID uuid.UUID, userUID uuid.UUID, modelUID uuid.UUID, version string, inputJSON []byte) (runLog *datamodel.ModelRun, err error) UpdateModelRunWithError(ctx context.Context, runLog *datamodel.ModelRun, err error) *datamodel.ModelRun ListModelRuns(ctx context.Context, req *modelpb.ListModelRunsRequest, filter filtering.Filter) (*modelpb.ListModelRunsResponse, error) - ListModelRunsByRequester(ctx context.Context, req *modelpb.ListModelRunsByCreditOwnerRequest) (*modelpb.ListModelRunsByCreditOwnerResponse, error) + ListModelRunsByRequester(ctx context.Context, req *modelpb.ListModelRunsByRequesterRequest) (*modelpb.ListModelRunsByRequesterResponse, error) } type service struct { @@ -766,8 +766,9 @@ func (s *service) ListModelRuns(ctx context.Context, req *modelpb.ListModelRunsR } runnerIDMap := make(map[string]struct{}) - for _, trigger := range runs { - runnerIDMap[trigger.RunnerUID.String()] = struct{}{} + for _, run := range runs { + runnerIDMap[run.RunnerUID.String()] = struct{}{} + runnerIDMap[run.RequesterUID.String()] = struct{}{} } runnerMap := make(map[string]*string) @@ -784,6 +785,7 @@ func (s *service) ListModelRuns(ctx context.Context, req *modelpb.ListModelRunsR for i, run := range runs { pbModelRun = convertModelRunToPB(run) pbModelRun.RunnerId = runnerMap[run.RunnerUID.String()] + pbModelRun.RequesterId = runnerMap[run.RequesterUID.String()] if CanViewPrivateData(run.RequesterUID.String(), requesterUID) { pbModelRun.TaskInputs, pbModelRun.TaskOutputs, err = parseMetadataToStructArr(metadataMap, run) @@ -804,7 +806,7 @@ func (s *service) ListModelRuns(ctx context.Context, req *modelpb.ListModelRunsR }, nil } -func (s *service) ListModelRunsByRequester(ctx context.Context, req *modelpb.ListModelRunsByCreditOwnerRequest) (*modelpb.ListModelRunsByCreditOwnerResponse, error) { +func (s *service) ListModelRunsByRequester(ctx context.Context, req *modelpb.ListModelRunsByRequesterRequest) (*modelpb.ListModelRunsByRequesterResponse, error) { pageSize := s.pageSizeInRange(req.GetPageSize()) page := s.pageInRange(req.GetPage()) @@ -849,8 +851,9 @@ func (s *service) ListModelRunsByRequester(ctx context.Context, req *modelpb.Lis } runnerIDMap := make(map[string]struct{}) - for _, trigger := range runs { - runnerIDMap[trigger.RunnerUID.String()] = struct{}{} + for _, run := range runs { + runnerIDMap[run.RunnerUID.String()] = struct{}{} + runnerIDMap[run.RequesterUID.String()] = struct{}{} } runnerMap := make(map[string]*string) @@ -868,10 +871,11 @@ func (s *service) ListModelRunsByRequester(ctx context.Context, req *modelpb.Lis for i, run := range runs { pbModelRun = convertModelRunToPB(run) pbModelRun.RunnerId = runnerMap[run.RunnerUID.String()] + pbModelRun.RequesterId = runnerMap[run.RequesterUID.String()] pbModelRuns[i] = pbModelRun } - return &modelpb.ListModelRunsByCreditOwnerResponse{ + return &modelpb.ListModelRunsByRequesterResponse{ Runs: pbModelRuns, TotalSize: int32(totalSize), PageSize: pageSize,