diff --git a/flyteadmin/pkg/manager/mocks/project.go b/flyteadmin/pkg/manager/mocks/project.go index dfe2c82bc9f..8e2c334891b 100644 --- a/flyteadmin/pkg/manager/mocks/project.go +++ b/flyteadmin/pkg/manager/mocks/project.go @@ -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) @@ -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 +} diff --git a/flyteadmin/pkg/rpc/adminservice/metrics.go b/flyteadmin/pkg/rpc/adminservice/metrics.go index f5904830b5c..65c6b741f38 100644 --- a/flyteadmin/pkg/rpc/adminservice/metrics.go +++ b/flyteadmin/pkg/rpc/adminservice/metrics.go @@ -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 @@ -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 @@ -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 @@ -179,10 +179,6 @@ 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"), @@ -190,6 +186,10 @@ func InitMetrics(adminScope promutils.Scope) AdminMetrics { 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"), diff --git a/flyteadmin/pkg/rpc/adminservice/project.go b/flyteadmin/pkg/rpc/adminservice/project.go index 50add1cd6f6..5e7352ad93a 100644 --- a/flyteadmin/pkg/rpc/adminservice/project.go +++ b/flyteadmin/pkg/rpc/adminservice/project.go @@ -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 { @@ -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") + } + var response *admin.GetDomainsResponse + m.Metrics.domainEndpointMetrics.get.Time(func() { + response = m.ProjectManager.GetDomains(ctx, *request) + }) + + m.Metrics.domainEndpointMetrics.get.Success() + return response, nil +} diff --git a/flyteadmin/tests/project_test.go b/flyteadmin/tests/project_test.go index 5dadceae51f..80820042719 100644 --- a/flyteadmin/tests/project_test.go +++ b/flyteadmin/tests/project_test.go @@ -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() @@ -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) + } +} diff --git a/flyteidl/protos/flyteidl/admin/project.proto b/flyteidl/protos/flyteidl/admin/project.proto index cfb110e7d22..c77e54a330a 100644 --- a/flyteidl/protos/flyteidl/admin/project.proto +++ b/flyteidl/protos/flyteidl/admin/project.proto @@ -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.