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

Adding filter by status flag to Challenges #20

Merged
merged 3 commits into from
Oct 22, 2024

Conversation

wololowarrior
Copy link

@wololowarrior wololowarrior commented Oct 18, 2024

Issues

  • Unable to list challenges from labctl based on status, like if it was attempted or solved by the user or still a todo.
  • Unable to filter on multiple categories.

What does this PR do?

  • Adding a --status flag to labctl challenge catalog , values are todo,attempted,solved
  • Using combination of categories or status.

More

  • Status can be clubbed together with existing flag viz category
  • Multiple categories can be specified like
    • ./labctl challenge catalog --category linux,containers
    • ./labctl challenge catalog --category linux,containers --status attempted

Examples

hgupta@Harshils-MacBook-Pro labctl % ./labctl challenge catalog --status solved --category linux
- name: run-multiple-containers-in-one-cgroup
  title: Limit CPU and Memory Usage of a Docker Compose Application
  description: |
    Run a multi-container Docker Compose application limiting its total CPU and memory usage without specifying the individual container's limits.
  categories:
  - containers
  - linux
  tags:
  - docker
  - docker-compose
  - cgroups
  - systemd
  url: https://labs.iximiuz.com/challenges/run-multiple-containers-in-one-cgroup
  attempted: 54
  completed: 23
- name: linux-network-namespace
  title: Create a Linux Network Namespace
  description: |
    Learn how to create fully isolated virtual network environment using Linux network namespaces.
  categories:
  - linux
  - containers
  - networking
  tags:
  - netns
  - nsenter
  - unshare
  - ip
  url: https://labs.iximiuz.com/challenges/linux-network-namespace
  attempted: 424
  completed: 293

@wololowarrior wololowarrior changed the title Adding filter by status flag Adding filter by status flag to Challenges Oct 18, 2024
Copy link
Owner

@iximiuz iximiuz left a comment

Choose a reason for hiding this comment

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

Great contribution! Thank you for your effort! I'll be happy to merge it - let's just clean it up a tiny bit.

}

func (c *Client) ListChallenges(ctx context.Context, opts *ListChallengesOptions) ([]*Challenge, error) {
var challenges []*Challenge
query := url.Values{}
if opts.Category != "" {
query.Set("category", opts.Category)
if opts.Category != nil {
Copy link
Owner

Choose a reason for hiding this comment

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

It's possible to iterate over a nil slice in Go - the if check is redundant.

&opts.category,
"category",
"",
`Category to filter by - one of linux, containers, kubernetes, ... (an empty string means all)`,
[]string{},
Copy link
Owner

Choose a reason for hiding this comment

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

The an empty string means all part is probably a leftover from the previous implementation.

Copy link
Author

Choose a reason for hiding this comment

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

Done

&opts.status,
"status",
[]string{},
`status to filter by - one or multiple status like todo, attempted, solved ... (empty means all))`,
Copy link
Owner

Choose a reason for hiding this comment

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

Same as above - probably no need to add empty means all

@jedrekdomanski
Copy link
Contributor

Is there a typo in the PR description in available statuses?

Adding a --status flag to labctl challenge catalog , values are todo,attempted,status

and in the example you mention status 'solved'

./labctl challenge catalog --status solved --category linux

I also wonder if you should return all challenges if you provide an invalid status vs none.

@wololowarrior
Copy link
Author

Is there a typo in the PR description in available statuses?

Adding a --status flag to labctl challenge catalog , values are todo,attempted,status

and in the example you mention status 'solved'

./labctl challenge catalog --status solved --category linux

I also wonder if you should return all challenges if you provide an invalid status vs none.

Thanks @jedrekdomanski for reviewing
Ah yes it was a typo.
And yep makes sense to return all challenges in case of invalid status. Will figure out a way.

@jedrekdomanski
Copy link
Contributor

Thanks @jedrekdomanski for reviewing Ah yes it was a typo. And yep makes sense to return all challenges in case of invalid status. Will figure out a way.

I may have misexpressed myself. What I wanted to say was that I feel like it doesn't make sense to return all challenges in case of an invalid status, which is happening now. What about we raise an error if an invalid status is supplied to avoid confusion? Right now you return all challenges even if you provide an invalid status which might be misleading.

@wololowarrior
Copy link
Author

Thanks @jedrekdomanski for reviewing Ah yes it was a typo. And yep makes sense to return all challenges in case of invalid status. Will figure out a way.

I may have misexpressed myself. What I wanted to say was that I feel like it doesn't make sense to return all challenges in case of an invalid status, which is happening now. What about we raise an error if an invalid status is supplied to avoid confusion? Right now you return all challenges even if you provide an invalid status which might be misleading.

@jedrekdomanski This is what i see if an invalid status is provided. Returning empty on invalid seems like the behaviour of the rest api.

hgupta@Harshils-MacBook-Pro labctl % ./labctl challenge catalog  --category kubernetes --status attempted1         
[]
hgupta@Harshils-MacBook-Pro labctl % ./labctl challenge catalog  --category kubernetes --status attem     
[]

@wololowarrior
Copy link
Author

wololowarrior commented Oct 18, 2024

Ah i see whats happening, its returning when labctl isnt logged in!
Seems like status isn't considered at all when labctl is not logged in. But should the cli throw an error or the backend. I feel like backend can return invalid status code/message.

@wololowarrior wololowarrior force-pushed the add-more-filter-flags-to-catalog branch from d9e9856 to 0099902 Compare October 21, 2024 06:02
@wololowarrior wololowarrior requested a review from iximiuz October 22, 2024 17:21
@iximiuz iximiuz merged commit 52c6c8e into iximiuz:main Oct 22, 2024
@iximiuz
Copy link
Owner

iximiuz commented Oct 22, 2024

Looks great! Thank you, @wololowarrior, for your time and effort!

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.

3 participants