GithubHelp home page GithubHelp logo

isabella232 / flagger-k6-webhook Goto Github PK

View Code? Open in Web Editor NEW

This project forked from grafana/flagger-k6-webhook

0.0 0.0 0.0 2.92 MB

Using k6 to do load testing of the canary before rolling out traffic

License: Apache License 2.0

Dockerfile 0.77% Makefile 1.29% Go 90.17% Jsonnet 3.80% Smarty 3.98%

flagger-k6-webhook's Introduction

flagger-k6-webhook

Using k6 to do load testing of the canary before rolling out traffic

Here's a demo (sped up):

Demo

Configuration

Here's what the Canary webhook can look like. This is pre-rollout webhook, so it happens before any traffic is placed on the canary. If the webhook passes the thresholds, the rest of the Flagger analysis and promotion process occurs

See the k6 docs for a full description of options available in scripts

apiVersion: flagger.app/v1beta1
kind: Canary
...
spec:
  analysis:
    ...
    webhooks:
    - name: k6-load-test
      timeout: 5m
      type: pre-rollout
      url: http://k6-loadtester.flagger/launch-test
      metadata:
        script: |
          import http from 'k6/http';
          import { sleep } from 'k6';
          export const options = {
            vus: 2,
            duration: '30s',
            thresholds: {
                http_req_duration: ['p(95)<50']
            },
            ext: {
              loadimpact: {
                name: '<cluster>/<your_service>',
                projectID: <project id>, # Optional, will use the default project otherwise
              },
            },
          };

          export default function () {
            http.get('http://<your_service>-canary.<namespace>:80/');
            sleep(0.10);
          }
        upload_to_cloud: "true"
        slack_channels: "channel1,channel2"
        notification_context: "My Cluster: `dev-us-east-1`" # Additional context to be added to the end of messages
        min_failure_delay: "2m" # Fail all successive runs after a failure (keyed to the namespace + name + phase) within the given duration (defaults to 2m). This prevents reruns. Set this to a duration slightly above the testing interval
        wait_for_results: "true" # Wait until the K6 analysis is completed before returning. This is required to fail/succeed on thresholds (defaults to true)
        env_vars: "{\"KEY\": \"value\"}" # Injects additional environment variables at runtime
        kubernetes_secrets: "{\"TEST_VAR\": \"other-namespace/secret-name/secret-key\"}" # Injects additional environment variables from secrets, at runtime

Injecting secrets and configuration

Use the k6 environment variables feature to inject configurations and secrets to your script. To do so, mount your configs as environment variables onto the load tester and reference them with ${__ENV.<VAR_NAME>}

You can also refer to other secrets by using the kubernetes_secrets setting in metadata. This is useful if your secrets are not located in the same namespace as the load tester or if you wish to limit the amount of secret to mount to the load tester. Note that you will need to assign a Kubernetes service account that can read the secrets in question to the load tester deployment

Using K6 Cloud

In order to send results to K6 cloud, the following conditions must be met:

  1. The script itself must support it. As shown above, in the ext.loadimpact, your script must define a test name and, optionally, a project ID
  2. You must pass the upload_to_cloud: "true" attribute in your Canary's metadata
  3. A K6_CLOUD_TOKEN environment variable must be set on the load tester's deployment

Once all of this is setup, results will be streamed to the cloud

How to deploy

Deploy this as a Service + Deployment beside Flagger:

  • Set the K6_CLOUD_TOKEN environment variable if any of your tests will be uploaded to k6 cloud
  • Set the SLACK_TOKEN environment variable to allow slack updates

See the example directory for a full example on how the loadtester can be deployed along with a Canary referencing it

How to deploy using Helm

helm repo add [repo/chart name]

helm upgrade -i k6-loadtester [repo/chart name]
--namespace=flagger
--set webhook.vars.K6_CLOUD_TOKEN=token
--set webhook.vars.SLACK_TOKEN=slack_token

flagger-k6-webhook's People

Contributors

julienduchesne avatar ashdertest avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.