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

Provide scaler for GitHub Actions Runner #1732

Closed
tomkerkhove opened this issue Apr 6, 2021 · 25 comments
Closed

Provide scaler for GitHub Actions Runner #1732

tomkerkhove opened this issue Apr 6, 2021 · 25 comments
Labels
feature All issues for new features that have been committed to help wanted Looking for support from community needs-discussion scaler

Comments

@tomkerkhove
Copy link
Member

Proposal

Provide scaler for GitHub Actions Runner
https://github.com/actions/runner

Scaler Source

GitHub Actions Runner queue

Scaling Mechanics

Automatically scale out based on the pending actions to run.

Authentication Source

TBD

@melisatanrverdi
Copy link
Contributor

Hi, I’ve been learning how to write a Keda scaler for a while. I wrote a basic scaler just to understand the scalers logic and wrote a blog about it, you can read my article here: https://melisatanrverdi.medium.com/how-do-i-cool-pods-with-keda-how-to-write-a-new-scaler-26b4671830bc
I am interested this issue now, could you please give more details about it?

@zroubalik
Copy link
Member

Great article! :)

@tomkerhove is the right person that could give you more info.

@tomkerkhove
Copy link
Member Author

The goal here is to autoscale self-hosted GitHub Actions runners to meet the current demand for it.

This would please a lot of people as per actions/runner#395.

In order to achieve that, we need to be able to get the related information:

@ghost
Copy link

ghost commented Apr 19, 2021

I've done something similar here https://github.com/devjoes/github-runner-autoscaler It's not a custom scaler. It's just a custom metrics APIService that you can point the ExternalMetrics scaler at and autoscale a stateful set up and down.

@tomkerkhove
Copy link
Member Author

That looks interesting, thanks for sharing! Feel free to send a PR to https://github.com/kedacore/external-scalers if you want.

However, this seems to rely on Prometheus which is a dependency we'd like to avoid. Can you share a bit on where you get the metrics from?

@ghost
Copy link

ghost commented Apr 27, 2021

Thanks! PR is here.

It doesn't rely on Prometheus, it just exports its own metrics which can be consumed by Prometheus if the user wants. Essentially it just exposes a custom metric like this:

kubectl get --raw '/apis/custom.metrics.k8s.io/v1beta1/namespaces/example-repo/Scaledactionrunners/example-repo/*' | jq .
{
  "kind": "MetricValueList",
  "apiVersion": "custom.metrics.k8s.io/v1beta1",
  "metadata": {
    "selfLink": "/apis/custom.metrics.k8s.io/v1beta1/namespaces/example-repo/Scaledactionrunners/example-repo/%2A"
  },
  "items": [
    {
      "describedObject": {
        "kind": "ScaledActionRunner",
        "namespace": "example-repo",
        "name": "example-repo",
        "apiVersion": "v1alpha1"
      },
      "metricName": "example-repo",
      "timestamp": "2021-04-13T10:14:35Z",
      "value": "2",
      "selector": {
        "matchLabels": {
          "cr_name": "example-repo",
          "cr_namespace": "example-repo",
          "cr_owner": "devjoes",
          "cr_repo": "example-repo",
          "wf_id": "7939907",
          "wf_name": "main",
          "wf_runs_on": "self-hosted",
          "wf_runs_on_self-hosted": "self-hosted"
        }
      }
    }
  ]
}

It then uses KEDA's metrics-api trigger to scale on items.0.value.

The operator in that repo just wraps up the creation of StatefulSets and ScaledObjects. But there is no reason why you couldn't just deploy the API server and CRDs and point KEDA at it if you wanted to.

@tomkerkhove
Copy link
Member Author

tomkerkhove commented May 4, 2021

Thanks for opening the PR!

So the statefulset is then in charge of getting the metrics with GitHub to see how many pending actions there are, is that correct?

@ghost
Copy link

ghost commented May 4, 2021

So the stateful set just runs https://github.com/myoung34/docker-github-actions-runner
The operator generates a ScaledObject with a trigger like this:

  triggers:
    - authenticationRef:
        kind: ClusterTriggerAuthentication
        name: metrics
      metadata:
        authMode: tls
        targetValue: '1'
        url: >-
          https://metrics.foo.svc/apis/custom.metrics.k8s.io/v1beta1/namespaces/example-repo/Scaledactionrunners/example-repo/*
        valueLocation: items.0.value
      type: metrics-api

This queries a deployment called metrics, it is that deployment that checks the queued jobs

@tomkerkhove
Copy link
Member Author

A-ha, now I'm starting to get it - Thanks!

Basically the runner itself has the metrics on the queued jobs, thanks!

@tomkerkhove
Copy link
Member Author

@tomkerkhove tomkerkhove added help wanted Looking for support from community Hacktoberfest labels Sep 28, 2021
@hieumoscow
Copy link

hieumoscow commented Oct 7, 2021

@tomkerkhove there is a queue depth API @nilofer from GitHub is focusing on, hopefully available next month after their internal hackfest. I could make a PR to provide native scaler for GitHub Action

@tomkerkhove
Copy link
Member Author

That would be a major help - Thanks!

@stale
Copy link

stale bot commented Jan 28, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale All issues that are marked as stale due to inactivity label Jan 28, 2022
@tomkerkhove tomkerkhove added the feature All issues for new features that have been committed to label Jan 28, 2022
@stale stale bot removed the stale All issues that are marked as stale due to inactivity label Jan 28, 2022
@tomkerkhove tomkerkhove moved this to Backlog in Roadmap - KEDA Core Feb 10, 2022
@tomkerkhove tomkerkhove moved this from To Do to Proposed in Roadmap - KEDA Core Feb 11, 2022
@chrisreddington
Copy link

Hey @tomkerkhove - Is there any progress on this one? Also interested, and happy to contribute if extra help is needed! Sounds like there are some limitations on the GitHub side to get this going though from what I'm reading.

@tomkerkhove
Copy link
Member Author

As far as I know, unless that changed, there is no simple way to get metrics today. GitHub advises to use actions-runner-controller/actions-runner-controller in their documentation.

However, @nilofer might have an update on an API to poll as I'd love to have one next to our Azure Pipelines scaler.

@Pwd9000-ML
Copy link

For anyone on this thread who is interested, I wrote a little post/tutorial on Autoscaling self hosted GitHub runner containers with Azure Container Apps (ACA)

@tomkerkhove
Copy link
Member Author

Nice workaround

@tomkerkhove
Copy link
Member Author

I've been in contact with GitHub related to github/roadmap#555

@Eldarrin
Copy link
Contributor

Needs some work, but I need a git scaler to sit alongside my azure pipelines scaler so writing one. It currently has the issue of if you have a lot of repos it will hit rate limits, so putting some code together to refine that bit.

@Eldarrin
Copy link
Contributor

@tomkerkhove this is working in my dev clusters now. I haven't done a webhook version, this is a scale to zero, pull awaiting jobs version. Would you like this submitting? If so, I'll document it.

@JorTurFer
Copy link
Member

do you have it working without webhooks? I mean, are you recovering the info using the rest API?
If yes, we'd love it

@Eldarrin
Copy link
Contributor

Yeah, all using the rest api. Will document it and submit a PR. Cheers, Andy

@tomkerkhove
Copy link
Member Author

Wonderful, thank you!

@zroubalik
Copy link
Member

Implemented

@github-project-automation github-project-automation bot moved this from Done to Ready To Ship in Roadmap - KEDA Core Mar 9, 2023
@avdhoot
Copy link

avdhoot commented Mar 9, 2023

FYI The new implementation of action-runner controller from github is promising.

@JorTurFer JorTurFer moved this from Ready To Ship to Done in Roadmap - KEDA Core Mar 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature All issues for new features that have been committed to help wanted Looking for support from community needs-discussion scaler
Projects
Archived in project
Development

No branches or pull requests

9 participants