All Projects → buildkite → buildkite-agent-scaler

buildkite / buildkite-agent-scaler

Licence: MIT License
📈A lambda for scaling an AutoScalingGroup based on Buildkite metrics

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects
Makefile
30231 projects

Projects that are alternatives of or similar to buildkite-agent-scaler

twitter
A serverless social network that's under development with some cool stuff, such as Serverless Framework, AppSync, GraphQL, Lambda, DynamoDB, Cognito, Kinesis Firehose, and Algolia ☁️
Stars: ✭ 29 (+16%)
Mutual labels:  lambda
extract-css
Extract all CSS from a webpage, packaged as a Now V2 Lambda
Stars: ✭ 23 (-8%)
Mutual labels:  lambda
zappa-blog
A blog about Zappa, powered by Zappa. Zappa zappa zappa. Zappa.
Stars: ✭ 17 (-32%)
Mutual labels:  lambda
serverless-contact-form
Email contact form using the Serverless framework on AWS Lambda
Stars: ✭ 39 (+56%)
Mutual labels:  lambda
zero-administration-inference-with-aws-lambda-for-hugging-face
Zero administration inference with AWS Lambda for 🤗
Stars: ✭ 19 (-24%)
Mutual labels:  lambda
example-step-functions-integration-api-gateway
Example application using the new Step Functions integration with API Gateway. It developers to call API Gateway REST APIs and API Gateway from a Step Functions workflow.
Stars: ✭ 17 (-32%)
Mutual labels:  lambda
bksr
Run and test your Buildkite pipeline steps locally, just as they'd run in CI (discontinued)
Stars: ✭ 22 (-12%)
Mutual labels:  buildkite
Remute
C# library to create new immutable object applying lambda expressions to the existing immutable object
Stars: ✭ 57 (+128%)
Mutual labels:  lambda
spring-boot-lambda
No description or website provided.
Stars: ✭ 44 (+76%)
Mutual labels:  lambda
aws lambda ftp function
AWS Lambda Function to connect to FTP, download files and save them to S3 bucket
Stars: ✭ 55 (+120%)
Mutual labels:  lambda
herman
Herman is a tool to simplify deployment of AWS Services using ECS and Lambda, and the provisioning of various AWS services.
Stars: ✭ 33 (+32%)
Mutual labels:  lambda
junit-annotate-buildkite-plugin
📈 Summarise your test failures as a build annotation
Stars: ✭ 18 (-28%)
Mutual labels:  buildkite
s3-lambda-transcribe-audio-to-text-s3
Transcribe your audio to text with this serverless component
Stars: ✭ 84 (+236%)
Mutual labels:  lambda
cfn-encrypt
🔑🔐☁️ Cloudformation custom resource that enables creation of KMS encrypted strings and SSM secure parameters
Stars: ✭ 13 (-48%)
Mutual labels:  lambda
aws-pipeline
Build a CI/CD for Microservices and Serverless Functions in AWS ☁️
Stars: ✭ 32 (+28%)
Mutual labels:  lambda
spotify-lambda
λ🎵AWS Lambda functions for Spotify tracking
Stars: ✭ 12 (-52%)
Mutual labels:  lambda
serverless-plugin-lambda-dead-letter
serverless plugin that can configure a lambda with a dead letter queue or topic
Stars: ✭ 42 (+68%)
Mutual labels:  lambda
lambda-cron
LambdaCron - serverless cron tool
Stars: ✭ 22 (-12%)
Mutual labels:  lambda
lambda-string
Lambda-string (LS) is a helping java agent that inject configurable toString method into lambdas with some useful meta-information.
Stars: ✭ 34 (+36%)
Mutual labels:  lambda
instance-watcher
Get notified for Instances mistakenly left running across all AWS regions for specific AWS Account
Stars: ✭ 90 (+260%)
Mutual labels:  lambda

Buildkite Agent Scaler

An AWS lambda function that handles the scaling of an Amazon Autoscaling Group (ASG) based on metrics provided by the Buildkite Agent Metrics API.

In practice, we've seen 300% faster initial scale-ups with this lambda vs native AutoScaling rules. 🚀

Why?

The Elastic CI Stack depends on being able to scale up quickly from zero instances in response to scheduled Buildkite jobs. Amazon's AutoScaling primatives have a number of limitations that we wanted more granular control over:

  • The median time for a scaling event to be triggered was 2 minutes, due to needing two samples with a minimum period of 60 seconds between.
  • Scaling can either be by a fixed rate, a fixed step size or tracking, but tracking doesn't work well with custom metrics like we use.

How does it work?

The lambda (or cli version) polls the Buildkite Metrics API every 10 seconds, and based on the results sets the DesiredCount to exactly what is needed. This allows much faster scale up.

Gracefully scaling in

Whilst the lambda does support scaling in via setting DesiredCount, Amazon ASGs appear to not send Lifecycle Hooks before terminating instances, so jobs in progress are interrupted.

Instead, in the Elastic CI Stack we run the scaler with scale-in disabled (DISABLE_SCALE_IN) and rely on the recent addition in buildkite-agent v3.10.0 of --disconnect-after-idle-timeout in the Agent combined with a systemd PostStop script to terminate the instance and atomically decrease the DesiredCount after the agent has been idle for a time period. We've found it to work really well, and is less complicated than relying on lifecycled and Lifecycle Hooks.

See the forum post for more details.

Publishing Cloudwatch Metrics

The scaler collects it's own metrics and doesn't require the buildkite-agent-metrics. It supports optionally publishing the metrics it collects back to Cloudwatch, although it only supports a subset of the metrics that the buildkite-agent-metrics binary collects:

  • Buildkite > (Org, Queue) > ScheduledJobsCount
  • Buildkite > (Org, Queue) > RunningJobCount

Running as an AWS Lambda

An AWS Lambda bundle is created and published as part of the build process. The lambda will require the following IAM permissions:

  • cloudwatch:PutMetricData
  • autoscaling:DescribeAutoScalingGroups
  • autoscaling:SetDesiredCapacity

It's entrypoint is handler, it requires a go1.x environment and requires the following env vars:

  • BUILDKITE_AGENT_TOKEN or BUILDKITE_AGENT_TOKEN_SSM_KEY
  • BUILDKITE_QUEUE
  • AGENTS_PER_INSTANCE
  • ASG_NAME

If BUILDKITE_AGENT_TOKEN_SSM_KEY is set, the token will be read from AWS Systems Manager Parameter Store GetParameter which can also read from AWS Secrets Manager.

aws lambda create-function \
  --function-name buildkite-agent-scaler \
  --memory 128 \
  --role arn:aws:iam::account-id:role/execution_role \
  --runtime go1.x \
  --zip-file fileb://handler.zip \
  --handler handler

Running locally for development

$ aws-vault exec my-profile -- go run . \
  --asg-name elastic-runners-AgentAutoScaleGroup-XXXXX
  --agent-token "$BUILDKITE_AGENT_TOKEN"

Copyright

Copyright (c) 2014-2019 Buildkite Pty Ltd. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].