Skip to content

Instantly share code, notes, and snippets.

@elee
Created February 7, 2023 05:56
Show Gist options
  • Save elee/b90c2aee0b1a7110621e921a709c1683 to your computer and use it in GitHub Desktop.
Save elee/b90c2aee0b1a7110621e921a709c1683 to your computer and use it in GitHub Desktop.
envoy mysql example
admin:
address:
socket_address:
protocol: TCP
address: 0.0.0.0
port_value: 9901
stats_sinks:
- name: envoy.stat_sinks.dog_statsd
typed_config:
"@type": type.googleapis.com/envoy.config.metrics.v3.DogStatsdSink
max_bytes_per_datagram: 8192
prefix: migration_sidecar
address:
socket_address:
address: 127.0.0.1
port_value: 8126
static_resources:
listeners:
- name: mysql_listener
address:
socket_address:
address: 0.0.0.0
# 3308 is the replica port already
port_value: 3309
filter_chains:
- filters:
- name: envoy.filters.network.mysql_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.mysql_proxy.v3.MySQLProxy
stat_prefix: mysql_stat
access_log: "/tmp/foo.log"
- name: envoy.filters.network.tcp_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
stat_prefix: mysql_tcp
cluster: mysql_master
access_log:
- name: "envoy.access_loggers.file"
typed_config:
"@type": type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
path: "/tmp/envoy_mysql_listener.log"
log_format:
json_format:
jelly: '%DYNAMIC_METADATA(envoy.filters.network.mysql_proxy)%'
clusters:
- name: mysql_master
type: STRICT_DNS
load_assignment:
cluster_name: mysql_master
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 3306
@elee
Copy link
Author

elee commented Feb 7, 2023

Run verbosely

$ docker run  --network host --mount type=bind,source="$(pwd)"/envoy-mysql-access.yaml,target=/etc/envoy/envoy.yaml,readonly --mount type=bind,source=/tmp,target=/tmp envoyproxy/envoy-contrib:v1.25.0 envoy -c /etc/envoy/envoy.yaml -l trace

Run quietly with

$ docker run  --network host --mount type=bind,source="$(pwd)"/envoy-mysql-access.yaml,target=/etc/envoy/envoy.yaml,readonly --mount type=bind,source=/tmp,target=/tmp envoyproxy/envoy-contrib:v1.25.0

I was expecting to see /tmp/envoy_mysql_listener.log to contain the dynamic metadata described in the filter docs: https://www.envoyproxy.io/docs/envoy/latest/configuration/listeners/network_filters/mysql_proxy_filter#dynamic-metadata

Name Type Description
<table.db> string The resource name in table.db format. The resource name defaults to the table being accessed if the database cannot be inferred.
[] list A list of strings representing the operations executed on the resource. Operations can be one of insert/update/select/drop/delete/create/alter/show.

But I guess this is not possible given the final filter in the filter chain is tcp ? https://www.envoyproxy.io/docs/envoy/latest/configuration/observability/access_log/usage#config-access-log-format-dynamic-metadata

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment