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

feat(Scaler): Adds Loki Scaler #3700

Merged
merged 25 commits into from
Oct 20, 2022
Merged

Conversation

neelanjan00
Copy link
Contributor

@neelanjan00 neelanjan00 commented Sep 27, 2022

Provide a description of what has been changed

  • Adds Loki scaler for autoscaling based on Loki LogQL queries

Checklist

  • When introducing a new scaler, I agree with the scaling governance policy
  • Commits are signed with Developer Certificate of Origin (DCO - learn more)
  • Tests have been added
  • A PR is opened to update the documentation on (repo) (if applicable)
  • Changelog has been updated and is aligned with our changelog requirements

Relates to #3699

Relates to kedacore/keda-docs#948

@neelanjan00 neelanjan00 requested a review from a team as a code owner September 27, 2022 17:45
Copy link
Member

@JorTurFer JorTurFer left a comment

Choose a reason for hiding this comment

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

First, thanks a ton for this awesome contribution! 🙇
In general looks good, I have left some comments inline. Apart from that, could you add an e2e test for this scaler?
All e2e test are in /tests folder and there is also a readme explaining how to add them :)

CHANGELOG.md Outdated Show resolved Hide resolved
config/manager/kustomization.yaml Outdated Show resolved Hide resolved
config/metrics-server/kustomization.yaml Outdated Show resolved Hide resolved
pkg/generated/clientset/versioned/fake/register.go Outdated Show resolved Hide resolved
pkg/generated/clientset/versioned/scheme/register.go Outdated Show resolved Hide resolved
pkg/scalers/loki_scaler.go Outdated Show resolved Hide resolved
pkg/scalers/loki_scaler.go Outdated Show resolved Hide resolved
pkg/scalers/loki_scaler.go Outdated Show resolved Hide resolved
pkg/scalers/loki_scaler.go Outdated Show resolved Hide resolved
@neelanjan00
Copy link
Contributor Author

Hi @JorTurFer, thanks for reviewing the PR, I have resolved all the points that you commented upon.

Regarding the addition of an E2E suite for the scaler, I have been trying to understand how it can be achieved by taking reference from the other scaler's tests and the provided README. While I have a rudimentary idea of how it can be done for Loki scaler, I would still like to discuss it through first.

Here's what I have understood so far regarding the pre-requisites:

  1. Create helper functions for installing and cleaning up Loki in k8s.
  2. Create an application deployment to be scaled using the scaler.
  3. Create Jobs to simulate the event on which the application deployment should be scaled.

The logic of the test is about validating whether activation/scale-up/scale-down is occurring or not.

Based on my understanding I have a few doubts:

  1. How can we install/uninstall Loki for the test without using k8s manifests? The docs page doesn't provide any information about using k8s manifests, only Helm is supported here: https://grafana.com/docs/loki/latest/installation/
  2. Are there any special requirements for the demo application deployment container and the Job container to be used?

@JorTurFer
Copy link
Member

There are several e2e test were resources are installed/removed during the tests, for instance in this test we install/remove Hashicorp Vault.
WRT to how to install loki, you can use helm, there are other e2e tests which use helm to install deps.
Finally, wrt to the requirements, we don't have any special requirement to this, you can use whatever you want but we try to keep it simpler as possible.
If you need to create a new image to be used in the test, you can do it but in that case we prefer to have the code in our test-tools repo and use our own image (to avoid issues in the future if the upstream deletes them). In that case, the requirement is that the code should be in golang if it's possible. As an example about how to add a new image, I merged this PR last week adding and image for event hub e2e tests

@JorTurFer
Copy link
Member

WRT the e2e test itself, you are right, the process should be something like:

  1. Create the namespace, install deps (loki) and spawn the needed resources
  2. TestActivation
  3. TestScaleUp
  4. TestScaleDown
  5. Clean up the resources

You can check any already existing e2e test to validate the process or ping us if you have any doubt 😄

@v-shenoy
Copy link
Contributor

v-shenoy commented Oct 8, 2022

By the way, there are still some kustomization / generated files that are edited in this PR.

CHANGELOG.md Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
pkg/scalers/loki_scaler.go Outdated Show resolved Hide resolved
tests/scalers/loki/loki_test.go Outdated Show resolved Hide resolved
tests/scalers/loki/loki_test.go Outdated Show resolved Hide resolved
tests/scalers/loki/loki_test.go Outdated Show resolved Hide resolved
@neelanjan00
Copy link
Contributor Author

neelanjan00 commented Oct 10, 2022

Hey @JorTurFer, thank you so much for all the helpful feedback. I should mention that this PR is still a WIP, still trying to get the E2E to work, it's failing due to some mysterious FQDN issue. I will slowly resolve all of the issues by the end of this week (hopefully). Thank you so much once again for all the help! 🙏🏽

…dded create namespace function, minor fixes

Signed-off-by: Neelanjan Manna <[email protected]>
Signed-off-by: Neelanjan Manna <[email protected]>
@neelanjan00
Copy link
Contributor Author

neelanjan00 commented Oct 10, 2022

Resolved all the issues. However still facing issues with the execution of the E2E test itself: I am able to use the scaler otherwise manually, but when run through E2E, the test application doesn't scale up. I have checked for all the possible causes that may be responsible but in vain, including the operator pod logs and metrics-server pod logs. What would you suggest, @JorTurFer?

@neelanjan00
Copy link
Contributor Author

Attaching E2E logs for reference.
loki-e2e.log

@JorTurFer
Copy link
Member

JorTurFer commented Oct 10, 2022

/run-e2e loki*
Update: You can check the progress here

@v-shenoy
Copy link
Contributor

Were you able to check the scaling manually @neelanjan00?
You can also manually check the metric that KEDA is fetching and ensure that it is correct.
https://keda.sh/docs/2.8/operate/metrics-server/

@neelanjan00
Copy link
Contributor Author

Were you able to check the scaling manually @neelanjan00?
You can also manually check the metric that KEDA is fetching and ensure that it is correct.
https://keda.sh/docs/2.8/operate/metrics-server/

Yes I am able to run the scaler manually.

@JorTurFer
Copy link
Member

I have reviewed the execution log and there isn't any error so I guess that the issue is in the e2e test logic side. Let me pull your code and take a look deeper

…he substring being searched in the query

Signed-off-by: Neelanjan Manna <[email protected]>
Signed-off-by: Neelanjan Manna <[email protected]>
@JorTurFer
Copy link
Member

JorTurFer commented Oct 12, 2022

/run-e2e loki*
Update: You can check the progress here

Copy link
Member

@JorTurFer JorTurFer left a comment

Choose a reason for hiding this comment

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

Looking good, only some nits inline

pkg/scalers/loki_scaler.go Outdated Show resolved Hide resolved
tests/scalers/loki/loki_test.go Outdated Show resolved Hide resolved
tests/scalers/loki/loki_test.go Outdated Show resolved Hide resolved
tests/scalers/loki/loki_test.go Outdated Show resolved Hide resolved
@JorTurFer
Copy link
Member

JorTurFer commented Oct 12, 2022

/run-e2e loki*
Update: You can check the progress here

Copy link
Member

@JorTurFer JorTurFer left a comment

Choose a reason for hiding this comment

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

LGTM!
Thanks for this awesome contribution!
Let's wait till @zroubalik or @v-shenoy takes a look too

Copy link
Contributor

@v-shenoy v-shenoy left a comment

Choose a reason for hiding this comment

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

I am not an expert when it comes to Loki, but LGTM. Nice work!

Left some minor comments on the docs PR.

@neelanjan00
Copy link
Contributor Author

I am not an expert when it comes to Loki, but LGTM. Nice work!

Left some minor comments on the docs PR.

Thanks for the review, I have updated the docs PR as well based on your comments.

@JorTurFer JorTurFer merged commit 6e38c5e into kedacore:main Oct 20, 2022
26tanishabanik pushed a commit to 26tanishabanik/keda that referenced this pull request Nov 1, 2022
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