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

Conversation

0yukali0
Copy link
Contributor

What is this PR for?

Validate the user resource usage and group resource usage from the REST API.

What type of PR is it?

  • - Bug Fix
  • - Improvement
  • - Feature
  • - Documentation
  • - Hot Fix
  • - Refactoring

Todos

  • - Task

What is the Jira issue?

https://issues.apache.org/jira/browse/YUNIKORN-1901

How should this be tested?

Screenshots (if appropriate)

Questions:

  • - The licenses files need update.
  • - There is breaking changes for older versions.
  • - It needs documentation.

@0yukali0 0yukali0 self-assigned this Aug 15, 2023
@codecov
Copy link

codecov bot commented Aug 15, 2023

Codecov Report

Merging #654 (440cbbb) into master (37194fc) will increase coverage by 0.02%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master     #654      +/-   ##
==========================================
+ Coverage   71.87%   71.89%   +0.02%     
==========================================
  Files          49       49              
  Lines        7956     7956              
==========================================
+ Hits         5718     5720       +2     
+ Misses       2041     2039       -2     
  Partials      197      197              

see 1 file with indirect coverage changes

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

@0yukali0 0yukali0 closed this Aug 15, 2023
@0yukali0 0yukali0 reopened this Aug 15, 2023
Copy link
Contributor

@craigcondit craigcondit left a comment

Choose a reason for hiding this comment

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

user_qauta_tracing should be user_quota_tracing ; needs to be updated everywhere.

@0yukali0
Copy link
Contributor Author

user_qauta_tracing should be user_quota_tracing ; needs to be updated everywhere.
Hi @craigcondit .
Thanks for the review.
I am going to fix the wrong word problem later.

test/e2e/framework/helpers/yunikorn/rest_api_utils.go Outdated Show resolved Hide resolved
test/e2e/framework/helpers/yunikorn/rest_api_utils.go Outdated Show resolved Hide resolved
test/e2e/framework/helpers/yunikorn/rest_api_utils.go Outdated Show resolved Hide resolved
test/e2e/user_quota_tracing/user_qauta_tracing_test.go Outdated Show resolved Hide resolved
test/e2e/user_quota_tracing/user_qauta_tracing_test.go Outdated Show resolved Hide resolved
test/e2e/user_quota_tracing/user_qauta_tracing_test.go Outdated Show resolved Hide resolved
test/e2e/user_quota_tracing/user_qauta_tracing_test.go Outdated Show resolved Hide resolved
test/e2e/user_quota_tracing/user_qauta_tracing_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@manirajv06 manirajv06 left a comment

Choose a reason for hiding this comment

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

looks good.

Some comments has been addressed partially. please check those.

@manirajv06
Copy link
Contributor

Now that #634 has gone in, you will need to rebase and resolve conflicts.

Ω(ns1.Status.Phase).To(Equal(v1.NamespaceActive))
})

It("User qauta trace with 3 users and 2 groups", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: "qauta"

Comment on lines 92 to 95
{"teacher-app-01", queuePath[1], users[0], []string{groups[0]}},
{"students-app-01", queuePath[2], users[1], []string{groups[1]}},
{"assistant-app-01", queuePath[2], users[2], []string{groups[1]}},
{"assistant-app-02", queuePath[1], users[2], []string{groups[0]}},
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.

If these are strings which do not change inside the slice, I'd prefer having them them referenced as literals rather than slice elements. This is difficult to interpret. Extract them to const if that helps.

Comment on lines 150 to 162
for group, quota := range expectedGroups.Groups {
By(fmt.Sprintf("GroupTracker: Check group resource usage of %s in each queue", group))
groupUsage, getGroupErr := restClient.GetGroupResourceUsage(DEFAULT_PARTITION, group)
Ω(getGroupErr).NotTo(HaveOccurred())
Ω(groupUsage.Applications).To(Equal(quota.RunningApplications), "running application IDs are not expected")
for queuePath, queueQuota := range quota.Queues {
queue, getQueueErr := yunikorn.GetQueueResourceUsage(groupUsage.Queues, queuePath)
Ω(getQueueErr).NotTo(HaveOccurred())
Ω(queue.RunningApplications).To(Equal(queueQuota.RunningApplications))
usedResource.ParseResourceUsage(yunikorn.ParseResource(queue.ResourceUsage))
Ω(usedResource).To(Equal(queueQuota.Resources))
}
}
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.

I'm wondering if using functions is better... because you're trying to avoid code duplication, which is good.
But perhaps having all these checks in a separate func is more readable, like:

type PerGroup struct {
  queuePath string
  runningApps []string
  resources map[string]int64
}

func checkGroup(group string, expected []PerGroup) {
  ... do things with "group" ...
 groupUsage := restClient.GetGroupResourceUsage(DEFAULT_PARTITION, group)
  for _, exp := range expected {
    checkTrackedDataInGroup(groupUsage, exp.queuePath, exp.runningApps, exp.resources)
  }
}

func checkTrackedDataInGroup(groupUsage *dao.GroupResourceUsageDAOInfo, queuePath string, expectedRunningApps []string,
expectedResource map[string]int64) {
 queue, getQueueErr := yunikorn.GetQueueResourceUsage(groupUsage.Queues, queuePath)
 Ω(getQueueErr).NotTo(HaveOccurred())
 Ω(queue.RunningApplications).To(Equal(expectedRunningApps))
 usedResource.ParseResourceUsage(yunikorn.ParseResource(queue.ResourceUsage))
 Ω(usedResource).To(Equal(expectedResource))
}

Then you call checkGroup() separately for each group, and you create []PerGroup inline with string literals:

checkGroup("group1", []PerGroup{
  {
    queuePath: "root.path1",
    runningApps: "app1", "app2", "app3",
    resources: map[string]int64{
      "cpu": 1,
      "memory": 100,
   },
  {
    queuePath: "root.path2",
    runningApps: "app4", "app5",
    resources: map[string]int64{
      "cpu": 2,
      "memory": 200,
   },
  }
})

I'm not saying it has to look like this (it might not even compile), but it's a start. It's much more obvious to see what we're trying to achieve.

The main idea here is to reduce nesting and the number of structs. I'm really having a hard time understanding what the code does with all these types.

Excuse me if it sounds like nitpicking, it's not my goal. But let's make these things easy to comprehend if possible :-).

Copy link
Contributor Author

@0yukali0 0yukali0 Sep 6, 2023

Choose a reason for hiding this comment

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

Hi @pbacsko , thanks for review.
Your suggestion is cool in order to reduce the code and make code readable.
I will try to adopt this suggestion to make this code better.
I am going to start the progress in this weekend.

Comment on lines +40 to +48
var _ = BeforeSuite(func() {
Ω(kClient.SetClient()).To(BeNil())
yunikorn.EnsureYuniKornConfigsPresent()
})

var _ = AfterSuite(func() {
yunikorn.RestoreConfigMapWrapper(oldConfigMap, annotation)
})
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?

Copy link
Contributor

@pbacsko pbacsko left a comment

Choose a reason for hiding this comment

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

I don't know if the test works properly or not... let's see after the rebase. I spotted a logical error regarding the userinfo annotation. That likely need to be fixed.

I mostly added comments regarding maintainability, the current code is difficult to understand. See tips.

@0yukali0
Copy link
Contributor Author

0yukali0 commented Sep 6, 2023

Now that #634 has gone in, you will need to rebase and resolve conflicts.

Understood, I will rebase in this weekend.

@0yukali0
Copy link
Contributor Author

The commit is updated but it still lack of the part of admincontroll.externalUser
I will update the code of that part in next weekend.

@wilfred-s wilfred-s self-requested a review October 17, 2023 04:56
@0yukali0 0yukali0 closed this Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants