Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YUNIKORN-1901] A basic example for the user tracing and the group tracing #654

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/e2e/framework/configmanager/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const (
ClustersPath = "ws/v1/clusters"
NodesPath = "ws/v1/partition/%s/nodes"
UserUsagePath = "ws/v1/partition/%s/usage/user/%s"
UsersUsagePath = "ws/v1/partition/%s/usage/users"
GroupUsagePath = "ws/v1/partition/%s/usage/group/%s"
GroupsUsagePath = "ws/v1/partition/%s/usage/groups"
HealthCheckPath = "ws/v1/scheduler/healthcheck"
ValidateConfPath = "ws/v1/validate-conf"

Expand Down
65 changes: 65 additions & 0 deletions test/e2e/framework/helpers/yunikorn/rest_api_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/wait"

"github.com/apache/yunikorn-core/pkg/common/resources"
"github.com/apache/yunikorn-core/pkg/webservice/dao"
"github.com/apache/yunikorn-k8shim/test/e2e/framework/configmanager"
)
Expand Down Expand Up @@ -407,6 +408,16 @@ func (c *RClient) GetUserUsage(partition string, userName string) (*dao.UserReso
return userUsage, err
}

func (c *RClient) GetUsersUsage(partition string) ([]*dao.UserResourceUsageDAOInfo, error) {
req, err := c.newRequest("GET", fmt.Sprintf(configmanager.UsersUsagePath, partition), nil)
if err != nil {
return nil, err
}
var usersUsage []*dao.UserResourceUsageDAOInfo
_, err = c.do(req, usersUsage)
return usersUsage, err
}

func (c *RClient) GetGroupUsage(partition string, groupName string) (*dao.GroupResourceUsageDAOInfo, error) {
req, err := c.newRequest("GET", fmt.Sprintf(configmanager.GroupUsagePath, partition, groupName), nil)
if err != nil {
Expand All @@ -416,3 +427,57 @@ func (c *RClient) GetGroupUsage(partition string, groupName string) (*dao.GroupR
_, err = c.do(req, &groupUsage)
return groupUsage, err
}

func (c *RClient) GetGroupsUsage(partition string) ([]*dao.GroupResourceUsageDAOInfo, error) {
req, err := c.newRequest("GET", fmt.Sprintf(configmanager.GroupsUsagePath, partition), nil)
if err != nil {
return nil, err
}
var groupsUsage []*dao.GroupResourceUsageDAOInfo
_, err = c.do(req, groupsUsage)
return groupsUsage, err
}

func GetUserUsageFromUsersUsage(users []*dao.UserResourceUsageDAOInfo, target string) (*dao.UserResourceUsageDAOInfo, error) {
for _, user := range users {
if user.UserName == target {
return user, nil
}
}
return nil, fmt.Errorf("UserUsage %s doesn't exist", target)
}

func GetGroupUsageFromGroupsUsage(groups []*dao.GroupResourceUsageDAOInfo, target string) (*dao.GroupResourceUsageDAOInfo, error) {
for _, group := range groups {
if group.GroupName == target {
return group, nil
}
}
return nil, fmt.Errorf("GroupUsage %s doesn't exist", target)
}

func GetQueueResourceUsage(root *dao.ResourceUsageDAOInfo, queueName string) (*dao.ResourceUsageDAOInfo, error) {
if root == nil {
return nil, fmt.Errorf("ResourceUsage not found: %s", queueName)
}

if queueName == "root" {
return root, nil
}

var allSubQueues = root.Children
for _, subQ := range allSubQueues {
if subQ.QueuePath == queueName {
return subQ, nil
}
}
return nil, fmt.Errorf("ResourceUsage not found: %s", queueName)
}

func ParseResource(res *resources.Resource) map[string]int64 {
result := make(map[string]int64)
for key, value := range res.Resources {
result[key] = int64(value)
}
return result
}
48 changes: 48 additions & 0 deletions test/e2e/user_quota_tracing/user_quota_tracing_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package user_quota_tracing_test

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"

"github.com/apache/yunikorn-k8shim/test/e2e/framework/configmanager"
"github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/common"
"github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/k8s"
"github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/yunikorn"
)

func init() {
configmanager.YuniKornTestConfig.ParseFlags()
}

var oldConfigMap = new(v1.ConfigMap)
var annotation = "ann-" + common.RandSeq(10)
var kClient = k8s.KubeCtl{} //nolint
var RestClient = yunikorn.RClient{}

var _ = BeforeSuite(func() {
Ω(kClient.SetClient()).To(BeNil())
yunikorn.EnsureYuniKornConfigsPresent()
})

var _ = AfterSuite(func() {
yunikorn.RestoreConfigMapWrapper(oldConfigMap, annotation)
})
Comment on lines +41 to +48
Copy link
Contributor

@pbacsko pbacsko Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing something... Don't you need a TestXXX(t *testing.T) function here?

Loading