Skip to content

Commit

Permalink
modify format
Browse files Browse the repository at this point in the history
Signed-off-by: zychen5186 <[email protected]>
  • Loading branch information
zychen5186 committed Jun 20, 2024
1 parent c340779 commit 8973141
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 50 deletions.
18 changes: 9 additions & 9 deletions flyteadmin/pkg/manager/mocks/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,24 @@ import (
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin"
)

type GetDomainsFunc func(ctx context.Context, request admin.GetDomainRequest) *admin.GetDomainsResponse
type CreateProjectFunc func(ctx context.Context, request admin.ProjectRegisterRequest) (*admin.ProjectRegisterResponse, error)
type ListProjectFunc func(ctx context.Context, request admin.ProjectListRequest) (*admin.Projects, error)
type UpdateProjectFunc func(ctx context.Context, request admin.Project) (*admin.ProjectUpdateResponse, error)
type GetProjectFunc func(ctx context.Context, request admin.ProjectGetRequest) (*admin.Project, error)
type GetDomainsFunc func(ctx context.Context, request admin.GetDomainRequest) *admin.GetDomainsResponse

type MockProjectManager struct {
getDomainsFunc GetDomainsFunc
listProjectFunc ListProjectFunc
createProjectFunc CreateProjectFunc
updateProjectFunc UpdateProjectFunc
getProjectFunc GetProjectFunc
getDomainsFunc GetDomainsFunc
}

func (m *MockProjectManager) SetCreateProject(createProjectFunc CreateProjectFunc) {
m.createProjectFunc = createProjectFunc
}

func (m *MockProjectManager) GetDomains(ctx context.Context, request admin.GetDomainRequest) *admin.GetDomainsResponse {
if m.getDomainsFunc != nil {
return m.getDomainsFunc(ctx, request)
}
return nil
}

func (m *MockProjectManager) CreateProject(ctx context.Context, request admin.ProjectRegisterRequest) (*admin.ProjectRegisterResponse, error) {
if m.createProjectFunc != nil {
return m.createProjectFunc(ctx, request)
Expand Down Expand Up @@ -67,3 +60,10 @@ func (m *MockProjectManager) GetProject(ctx context.Context, request admin.Proje
}
return nil, nil
}

func (m *MockProjectManager) GetDomains(ctx context.Context, request admin.GetDomainRequest) *admin.GetDomainsResponse {
if m.getDomainsFunc != nil {
return m.getDomainsFunc(ctx, request)
}
return nil
}
22 changes: 11 additions & 11 deletions flyteadmin/pkg/rpc/adminservice/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ type nodeExecutionEndpointMetrics struct {
getDynamicNodeWorkflow util.RequestMetrics
}

type domainEndpointMetrics struct {
scope promutils.Scope

get util.RequestMetrics
}

type projectEndpointMetrics struct {
scope promutils.Scope

Expand All @@ -70,6 +64,12 @@ type projectEndpointMetrics struct {
get util.RequestMetrics
}

type domainEndpointMetrics struct {
scope promutils.Scope

get util.RequestMetrics
}

type attributeEndpointMetrics struct {
scope promutils.Scope

Expand Down Expand Up @@ -122,8 +122,8 @@ type AdminMetrics struct {
launchPlanEndpointMetrics launchPlanEndpointMetrics
namedEntityEndpointMetrics namedEntityEndpointMetrics
nodeExecutionEndpointMetrics nodeExecutionEndpointMetrics
domainEndpointMetrics domainEndpointMetrics
projectEndpointMetrics projectEndpointMetrics
domainEndpointMetrics domainEndpointMetrics
projectAttributesEndpointMetrics attributeEndpointMetrics
projectDomainAttributesEndpointMetrics attributeEndpointMetrics
workflowAttributesEndpointMetrics attributeEndpointMetrics
Expand Down Expand Up @@ -179,17 +179,17 @@ func InitMetrics(adminScope promutils.Scope) AdminMetrics {
listChildren: util.NewRequestMetrics(adminScope, "list_children_node_executions"),
getDynamicNodeWorkflow: util.NewRequestMetrics(adminScope, "get_dynamic_node_workflow"),
},
domainEndpointMetrics: domainEndpointMetrics{
scope: adminScope,
get: util.NewRequestMetrics(adminScope, "get_domain"),
},
projectEndpointMetrics: projectEndpointMetrics{
scope: adminScope,
register: util.NewRequestMetrics(adminScope, "register_project"),
list: util.NewRequestMetrics(adminScope, "list_projects"),
update: util.NewRequestMetrics(adminScope, "update_project"),
get: util.NewRequestMetrics(adminScope, "get_project"),
},
domainEndpointMetrics: domainEndpointMetrics{
scope: adminScope,
get: util.NewRequestMetrics(adminScope, "get_domain"),
},
projectAttributesEndpointMetrics: attributeEndpointMetrics{
scope: adminScope,
update: util.NewRequestMetrics(adminScope, "update_project_attrs"),
Expand Down
28 changes: 14 additions & 14 deletions flyteadmin/pkg/rpc/adminservice/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ func (m *AdminService) RegisterProject(ctx context.Context, request *admin.Proje
return response, nil
}

func (m *AdminService) GetDomains(ctx context.Context, request *admin.GetDomainRequest) (*admin.GetDomainsResponse, error) {
defer m.interceptPanic(ctx, request)
if request == nil {
return nil, status.Errorf(codes.InvalidArgument, "Incorrect request, nil requests not allowed")
}
var response *admin.GetDomainsResponse
m.Metrics.domainEndpointMetrics.get.Time(func() {
response = m.ProjectManager.GetDomains(ctx, *request)
})

m.Metrics.domainEndpointMetrics.get.Success()
return response, nil
}

func (m *AdminService) ListProjects(ctx context.Context, request *admin.ProjectListRequest) (*admin.Projects, error) {
defer m.interceptPanic(ctx, request)
if request == nil {
Expand Down Expand Up @@ -95,3 +81,17 @@ func (m *AdminService) GetProject(ctx context.Context, request *admin.ProjectGet
m.Metrics.projectEndpointMetrics.get.Success()
return response, nil
}

func (m *AdminService) GetDomains(ctx context.Context, request *admin.GetDomainRequest) (*admin.GetDomainsResponse, error) {
defer m.interceptPanic(ctx, request)
if request == nil {
return nil, status.Errorf(codes.InvalidArgument, "Incorrect request, nil requests not allowed")

Check warning on line 88 in flyteadmin/pkg/rpc/adminservice/project.go

View check run for this annotation

Codecov / codecov/patch

flyteadmin/pkg/rpc/adminservice/project.go#L85-L88

Added lines #L85 - L88 were not covered by tests
}
var response *admin.GetDomainsResponse
m.Metrics.domainEndpointMetrics.get.Time(func() {
response = m.ProjectManager.GetDomains(ctx, *request)
})

Check warning on line 93 in flyteadmin/pkg/rpc/adminservice/project.go

View check run for this annotation

Codecov / codecov/patch

flyteadmin/pkg/rpc/adminservice/project.go#L90-L93

Added lines #L90 - L93 were not covered by tests

m.Metrics.domainEndpointMetrics.get.Success()
return response, nil

Check warning on line 96 in flyteadmin/pkg/rpc/adminservice/project.go

View check run for this annotation

Codecov / codecov/patch

flyteadmin/pkg/rpc/adminservice/project.go#L95-L96

Added lines #L95 - L96 were not covered by tests
}
28 changes: 14 additions & 14 deletions flyteadmin/tests/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,6 @@ import (
"github.com/flyteorg/flyte/flytestdlib/utils"
)

func TestGetDomains(t *testing.T) {
ctx := context.Background()
client, conn := GetTestAdminServiceClient()
defer conn.Close()

domains, err := client.GetDomains(ctx, &admin.GetDomainRequest{})
assert.Nil(t, err)
assert.NotEmpty(t, domains.Domains)
for _, domain := range domains.Domains {
assert.Contains(t, []string{"development", "domain", "staging", "production"}, domain.Id)
assert.Contains(t, []string{"development", "domain", "staging", "production"}, domain.Name)
}
}

func TestCreateProject(t *testing.T) {
truncateAllTablesForTestingOnly()
ctx := context.Background()
Expand Down Expand Up @@ -241,3 +227,17 @@ func TestUpdateProjectLabels_BadLabels(t *testing.T) {
// Assert that update went through without an error.
assert.EqualError(t, err, "rpc error: code = InvalidArgument desc = invalid label value [#bar]: [a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue', or 'my_value', or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')]")
}

func TestGetDomains(t *testing.T) {
ctx := context.Background()
client, conn := GetTestAdminServiceClient()
defer conn.Close()

domains, err := client.GetDomains(ctx, &admin.GetDomainRequest{})
assert.Nil(t, err)
assert.NotEmpty(t, domains.Domains)
for _, domain := range domains.Domains {
assert.Contains(t, []string{"development", "domain", "staging", "production"}, domain.Id)
assert.Contains(t, []string{"development", "domain", "staging", "production"}, domain.Name)
}
}
3 changes: 1 addition & 2 deletions flyteidl/protos/flyteidl/admin/project.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ option go_package = "github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin
import "flyteidl/admin/common.proto";

// Empty request for GetDomain
message GetDomainRequest {
}
message GetDomainRequest {}

// Namespace within a project commonly used to differentiate between different service instances.
// e.g. "production", "development", etc.
Expand Down

0 comments on commit 8973141

Please sign in to comment.