MySQL Filter

In this example, we show how the MySQL filter can be used with the Envoy proxy. The Envoy proxy configuration includes a MySQL filter that parses queries and collects MySQL-specific metrics.

Running the Sandboxes

The following documentation runs through the setup of Envoy described above.

Step 1: Install Docker

Ensure that you have a recent versions of docker and docker-compose installed.

A simple way to achieve this is via the Docker Desktop.

Step 2: Clone the Envoy repo

If you have not cloned the Envoy repo, clone it with:

SSH

HTTPS

  1. git clone git@github.com:envoyproxy/envoy
  1. git clone https://github.com/envoyproxy/envoy.git

Step 3: Build the sandbox

Terminal 1

  1. $ pwd
  2. envoy/examples/mysql
  3. $ docker-compose pull
  4. $ docker-compose up --build -d
  5. $ docker-compose ps
  6. Name Command State Ports
  7. ------------------------------------------------------------------------------------------------------------------
  8. mysql_mysql_1 docker-entrypoint.sh mysqld Up 0.0.0.0:3306->3306/tcp
  9. mysql_proxy_1 /docker-entrypoint.sh /bin Up 10000/tcp, 0.0.0.0:1999->1999/tcp, 0.0.0.0:8001->8001/tcp

Step 4: Issue commands using mysql

Use mysql to issue some commands and verify they are routed via Envoy. Note that the current implementation of the protocol filter was tested with MySQL v5.5. It may, however, not work with other versions of MySQL due to differences in the protocol implementation.

Terminal 1

  1. $ docker run --rm -it --network envoymesh mysql:5.5 mysql -h envoy -P 1999 -u root
  2. ... snip ...
  3. mysql> CREATE DATABASE test;
  4. Query OK, 1 row affected (0.00 sec)
  5. mysql> USE test;
  6. Database changed
  7. mysql> CREATE TABLE test ( text VARCHAR(255) );
  8. Query OK, 0 rows affected (0.01 sec)
  9. mysql> SELECT COUNT(*) FROM test;
  10. +----------+
  11. | COUNT(*) |
  12. +----------+
  13. | 0 |
  14. +----------+
  15. 1 row in set (0.01 sec)
  16. mysql> INSERT INTO test VALUES ('hello, world!');
  17. Query OK, 1 row affected (0.00 sec)
  18. mysql> SELECT COUNT(*) FROM test;
  19. +----------+
  20. | COUNT(*) |
  21. +----------+
  22. | 1 |
  23. +----------+
  24. 1 row in set (0.00 sec)
  25. mysql> exit
  26. Bye

Step 5: Check egress stats

Check egress stats were updated.

Terminal 1

  1. $ curl -s http://localhost:8001/stats?filter=egress_mysql
  2. mysql.egress_mysql.auth_switch_request: 0
  3. mysql.egress_mysql.decoder_errors: 0
  4. mysql.egress_mysql.login_attempts: 1
  5. mysql.egress_mysql.login_failures: 0
  6. mysql.egress_mysql.protocol_errors: 0
  7. mysql.egress_mysql.queries_parse_error: 0
  8. mysql.egress_mysql.queries_parsed: 7
  9. mysql.egress_mysql.sessions: 1
  10. mysql.egress_mysql.upgraded_to_ssl: 0

Step 6: Check TCP stats

Check TCP stats were updated.

Terminal 1

  1. $ curl -s http://localhost:8001/stats?filter=mysql_tcp
  2. tcp.mysql_tcp.downstream_cx_no_route: 0
  3. tcp.mysql_tcp.downstream_cx_rx_bytes_buffered: 0
  4. tcp.mysql_tcp.downstream_cx_rx_bytes_total: 347
  5. tcp.mysql_tcp.downstream_cx_total: 1
  6. tcp.mysql_tcp.downstream_cx_tx_bytes_buffered: 0
  7. tcp.mysql_tcp.downstream_cx_tx_bytes_total: 702
  8. tcp.mysql_tcp.downstream_flow_control_paused_reading_total: 0
  9. tcp.mysql_tcp.downstream_flow_control_resumed_reading_total: 0
  10. tcp.mysql_tcp.idle_timeout: 0
  11. tcp.mysql_tcp.upstream_flush_active: 0
  12. tcp.mysql_tcp.upstream_flush_total: 0