Metricbeat 8 sql module leaks connections when using prepared statements

We recently went from Metricbeat 7.14 to 8.14
We have found idle metricbeat connections piling up in mysql.

Problem: We use the sql module to run queries on mysql. The queries use prepared statements. Since going to metricbeat 8, the connections leak, maybe a difference in the GO driver. The queries still work but the connections stay until we hit the mysql connection limit.

Duplicate: spin up a mysql 8.0 instance and use this sql.yml to query it.
Check connections to mysql

sample sql.yml:

# Module: sql
# Docs: https://www.elastic.co/guide/en/beats/metricbeat/8.14/metricbeat-module-sql.html

- module: sql
  metricsets:
    - query
  period: 10s
  hosts: ["metricbeat:password(127.0.0.1:3306)/?multiStatements=true"]
  driver: "mysql"
  sql_query: |
    SET @schema_name = 'mysql';
    SET @sql = CONCAT(
    'SELECT TABLE_NAME, TABLE_TYPE ',
    'FROM information_schema.tables ',
    'WHERE TABLE_SCHEMA = \'', @schema_name, '\''
    );
    PREPARE stmt FROM @sql;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
  sql_response_format: table

1 Like

I tried converting my query into a stored procedure hoping we could use the queries that way (still using prepared statements for dynamic sql, just in a proc instead)
and then called the proc with metricbeat sql.
Same results unfortunately.