Skip to content

Source code for `Making Envoy contributions Feasible for Everyone` talk at `KubeCon 2020`

Notifications You must be signed in to change notification settings

yskopets/kubecon2020

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

Source code for Making Envoy contributions Feasible for Everyone talk at KubeCon 2020.

Slides

How To's

Pre-requirements

Install NodeJS

See instructions on NodeJS.

Install NPM dependencies

$ make npm

Install GetEnvoy

$ curl -L https://getenvoy.io/cli | bash -s -- -b /usr/local/bin

Fetch build of Envoy with WebAssembly support

$ getenvoy fetch wasm:nightly

How To test

Start Envoy

To start Envoy, run:

$ make run

To make sample requests, run:

$ make requests

To inspect Envoy metrics:

$ make stats

Walkthrough

Walkthrough: Getting Started

assemblyscript/filter.ts:

import { HttpFilter, log } from "./sdk";

export class ApiValidator extends HttpFilter {
  constructor(_config: string) {
    super();
    log.info("hello world!");
  }
}

Walkthrough: Data model

assemblyscript/model.ts:

export class ApiSpec {
  operations: Array<Operation>
}

export class Operation {
  method: string
  path:   string
}

Walkthrough: Configuration

assemblyscript/filter.ts:

import { HttpFilter } from "./sdk";
import { ApiSpec } from "./model";

export class ApiValidator extends HttpFilter {
  private spec: ApiSpec

  constructor(config: string) {
    super();
    this.spec = ApiSpec.parse(config);
  }
}

Walkthrough: Request validation

assemblyscript/filter.ts:

import { HttpFilter, log, ops } from "./sdk";
import { ApiSpec } from "./model";

export class ApiValidator extends HttpFilter {
  private spec: ApiSpec

  constructor(config: string) { 
    super();
    this.spec = ApiSpec.parse(config);
  }

  onExchangeComplete(): void {
    let method = ops.getRequestHeader(":method")
    let path   = ops.getRequestHeader(":path")

    if (!this.spec.contains(method, path)) {
      log.warn("unknown API: " + method + " " + path);
    }
  }
}

Walkthrough: Metrics

assemblyscript/filter.ts:

import { HttpFilter, Stats, log, ops } from "./sdk";
import { ApiSpec } from "./model";

export class ApiValidator extends HttpFilter {
  private spec: ApiSpec

  constructor(config: string) { 
    super();
    this.spec = ApiSpec.parse(config);
  }

  onExchangeComplete(): void {
    let method = ops.getRequestHeader(":method")
    let path   = ops.getRequestHeader(":path")

    if (!this.spec.contains(method, path)) {
      log.warn("unknown API: " + method + " " + path);
    }

    if (!this.spec.contains(method, path)) {
      Stats.counter("api_validator.violations_total").inc();
    }
  }
}

About

Source code for `Making Envoy contributions Feasible for Everyone` talk at `KubeCon 2020`

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published