Skip to content

Commit

Permalink
feat(run): add requester id in list model run response
Browse files Browse the repository at this point in the history
  • Loading branch information
joremysh committed Oct 18, 2024
1 parent a753fe4 commit 27daebb
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions pkg/handler/mock_service_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/handler/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion pkg/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
18 changes: 11 additions & 7 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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())

Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit 27daebb

Please sign in to comment.