Giter Club home page Giter Club logo

load-balancer-testing-api's Introduction

ci

Load Balancer Testing API

A basic REST API written in Python using FastAPI that I use for testing load balancers in my day job. It features a separate front-end UI and back-end API that can be run independently or in the same process.

Running

To run from the command line first install the dependencies: pip install -r requirements.txt, then run python app\main.py

To run via docker docker run -it -p 80:80 maxanderson95/load-balancer-testing-api:latest

You can also deploy the included manifests. This requires a pre-configured ingress controller.

kubectl apply -f https://raw.githubusercontent.com/MaxAnderson95/load-balancer-testing-api/main/manifests/deployment.yaml
kubectl apply -f https://raw.githubusercontent.com/MaxAnderson95/load-balancer-testing-api/main/manifests/service.yaml
kubectl apply -f https://raw.githubusercontent.com/MaxAnderson95/load-balancer-testing-api/main/manifests/ingress.yaml

Configuration

You can specify configuration using environment variables.

  • To specify the logging level: API_logging.level="DEBUG". The default is INFO.

  • To specify the instance id (essentially a friendly name for the instance): API_server.instance_id="HQ-01". The default is auto generated.

  • To specify the port the server runs on: API_server.port="8080". The default is 80.

  • To specify the server "mode": API_server.mode="FULL". The default is FULL, and the other options are UI and API.

Logging and Data

When a request is made to any route, it will respond with a json object in the following format:

{
	"server_details": {
		"server_instance_id": "D2SRCA",
		"server_mode": "API",
		"server_listening_port": 80
	},
	"request_details": {
		"client_ip": "10.1.1.50",
		"x-forwarded-for_header": "172.12.12.12",
		"request_path": "/api/v1"
	}
}

Also, an INFO level log message will be printed to STDOUT with similar information:

[2022-03-18 18:01:15,979][main ][INFO ] Instance: 'D2SRCA', METHOD: 'GET', PATH: '/testroute' CLIENT: '10.1.1.50', XFF: '172.12.12.12'

If the word "health" is found anywhere in the request path, the log message will be at DEBUG level instead, and the response object will contain a new key value pair of "status": "UP, mimicking the response of the health monitor in Spring Boot framework.

Server Modes

Three server modes are available. These are: API, UI, and FULL. They are set using an environment variable with the default being FULL if the environment variable is not set.

  • When the server is in API mode, it simply responds to GET and HEAD requests at any route and returns a sample response.

  • When the server is in UI mode, it serves a static HTML page and Javascript file. On load, the webpage will attempt to make a call to /api and return the server_instance_id as text in the HTML body. It will also attempt to get a joke from /api/joke which itself gets a joke from a 3rd party joke API.

    Also note, calls with the word health anywhere in the path will return a JSON response with a key value pair of "status": "UP", mimicking the response of the health monitor in Spring Boot framework.

  • When the server is in FULL mode (Fullstack mode), it is the equivalent of having API and UI mode enabled at the same time.

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.