WL#11891: HTTP component to MySQL Router
Motivation
For integration with external tools for
- healthcheck
- monitoring
- management
- ...
MySQL Router needs interface that is:
- easy to interface with for applications
- easy to use for users
In principle the MySQL Protocol could be used for this task, but the HTTP protocol fits the needs of this task better.
HTTP
Using HTTP as underlying protocol allows to:
- encrypt the traffic with TLS
- authorize the users
allow to use existing tools and frameworks tested and validated by the web community to
- easily interface with browsers for user-interfaces
- easily expose REST endpoints to applications (document with tools like https://swagger.io/)
Goal
Add a tiny HTTP server library to MySQL Router to allow to expose REST endpoints and a web-interface.
Requirements
- FR1
- communication MUST be encrypted by default
- FR2
- it MUST be possible to limit access to authenticated users
- FR3
- it MUST be possible to deliver data for humans
- FR4
- it MUST be possible to deliver machine parsable data
Protocol Evaluation
There are several option on how to expose monitoring information:
- a SQL based interface over MySQL classic or xprotocol
- a REST based interface based on HTTP and JSON
Both allow to:
- provide secure access (authentication)
- encrypted transportation (TLS)
- compression if needed
Implementations
The HTTP protocol server implementation can be taken from
- libevent's HTTP library
which is already part of the Routers dependencies.
Session State
One of the differentiators between HTTP and MySQL protocols is statefulness:
- HTTP is stateless
- MySQL protocols are stateful
Conclusion
As state isn't needed, going with HTTP opens many interesting options down the road:
- a integrated, browser based internal live reporting interface
- simple administration via HTTP CRUD operations
- simple integration the typical user, web-environment
Implementation
http_server module
http_server module provides:
- APIs for other plugins to register and unregister URL routes
- HTTP handling
Configuration
config-section: http_server
options
- bind_address
- IPv4 address to bind to for "port". Default: 0.0.0.0
- port
- TCP port to listen for HTTP requests on. Default: 8081
- static_folder
- base directory for static file requests. Default: empty. If empty, no static files will served.
libevent
Using libevent's HTTP component
- http://www.wangafu.net/~nickm/libevent-2.0/doxygen/html/http_8h.html
- https://github.com/libevent/libevent/blob/master/sample/http-server.c
removes the need to write a HTTP server library. libevent is already a dependency of the MySQL Router.