Skip to content

Commit

Permalink
Add domain matric, add test in flyteadmin and flytectl
Browse files Browse the repository at this point in the history
Signed-off-by: zychen5186 <[email protected]>
  • Loading branch information
zychen5186 committed Jun 7, 2024
1 parent 409f14e commit b268533
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 15 deletions.
11 changes: 11 additions & 0 deletions flyteadmin/pkg/rpc/adminservice/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ type nodeExecutionEndpointMetrics struct {
getDynamicNodeWorkflow util.RequestMetrics
}

type domainEndpointMetrics struct {
scope promutils.Scope

get util.RequestMetrics
}

type projectEndpointMetrics struct {
scope promutils.Scope

Expand Down Expand Up @@ -116,6 +122,7 @@ type AdminMetrics struct {
launchPlanEndpointMetrics launchPlanEndpointMetrics
namedEntityEndpointMetrics namedEntityEndpointMetrics
nodeExecutionEndpointMetrics nodeExecutionEndpointMetrics
domainEndpointMetrics domainEndpointMetrics
projectEndpointMetrics projectEndpointMetrics
projectAttributesEndpointMetrics attributeEndpointMetrics
projectDomainAttributesEndpointMetrics attributeEndpointMetrics
Expand Down Expand Up @@ -172,6 +179,10 @@ 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"),
Expand Down
4 changes: 2 additions & 2 deletions flyteadmin/pkg/rpc/adminservice/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ func (m *AdminService) GetDomains(ctx context.Context, request *admin.GetDomainR
return nil, status.Errorf(codes.InvalidArgument, "Incorrect request, nil requests not allowed")

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

View check run for this annotation

Codecov / codecov/patch

flyteadmin/pkg/rpc/adminservice/project.go#L31-L34

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

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

View check run for this annotation

Codecov / codecov/patch

flyteadmin/pkg/rpc/adminservice/project.go#L36-L39

Added lines #L36 - L39 were not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

flyteadmin/pkg/rpc/adminservice/project.go#L41-L42

Added lines #L41 - L42 were not covered by tests
}

Expand Down
14 changes: 14 additions & 0 deletions flyteadmin/tests/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ 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 project.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
2 changes: 1 addition & 1 deletion flytectl/pkg/ext/domain_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin"
)

func (a *AdminFetcherExtClient) GetDomain(ctx context.Context) (*admin.Domains, error) {
func (a *AdminFetcherExtClient) GetDomains(ctx context.Context) (*admin.Domains, error) {
domains, err := a.AdminServiceClient().GetDomains(ctx, &admin.GetDomainRequest{})
if err != nil {
return nil, err

Check warning on line 12 in flytectl/pkg/ext/domain_fetcher.go

View check run for this annotation

Codecov / codecov/patch

flytectl/pkg/ext/domain_fetcher.go#L12

Added line #L12 was not covered by tests
Expand Down
35 changes: 35 additions & 0 deletions flytectl/pkg/ext/domain_fetcher_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ext

import (
"testing"

"github.com/flyteorg/flyte/flyteidl/clients/go/admin/mocks"
"github.com/flyteorg/flyte/flyteidl/gen/pb-go/flyteidl/admin"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestAdminFetcherExtClient_GetDomains(t *testing.T) {
domain1 := &admin.Domain{
Id: "development",
Name: "development",
}
domain2 := &admin.Domain{
Id: "staging",
Name: "staging",
}
domain3 := &admin.Domain{
Id: "production",
Name: "production",
}
domains := &admin.Domains{
Domains: []*admin.Domain{domain1, domain2, domain3},
}

adminClient := new(mocks.AdminServiceClient)
adminFetcherExt := AdminFetcherExtClient{AdminClient: adminClient}

adminClient.OnGetDomainsMatch(mock.Anything, mock.Anything).Return(domains, nil)
_, err := adminFetcherExt.GetDomains(ctx)
assert.Nil(t, err)
}
2 changes: 1 addition & 1 deletion flytectl/pkg/ext/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type AdminFetcherExtInterface interface {
// GetProjectByID fetches a single project by its identifier. If project does not exist, an error will be returned
GetProjectByID(ctx context.Context, projectID string) (*admin.Project, error)

GetDomain(ctx context.Context) (*admin.Domains, error)
GetDomains(ctx context.Context) (*admin.Domains, error)
}

// AdminFetcherExtClient is used for interacting with extended features used for fetching data from admin service
Expand Down
22 changes: 11 additions & 11 deletions flytectl/pkg/ext/mocks/admin_fetcher_ext_interface.go

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

0 comments on commit b268533

Please sign in to comment.