Dirty Reads in Custom Metrics

How to execute custom queries as dirty reads.

scrape_count:
  query: |
    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
    SELECT COUNT(1) AS count, DATE(updated_at) AS update_date
    FROM db.table
    WHERE updated_at >= (SELECT DATE(MAX(updated_at)) - INTERVAL 20 DAY FROM db.table)
    GROUP BY update_date
    ORDER BY update_date DESC
    LIMIT 10;
  metrics:
    - count:
        usage: "GAUGE"
        description: "Scrape Count"
    - update_date:
        usage: "LABEL"
        description: "Update Date"

I’ve added this yml file, but it result into no data in the dashboard.
Does pmm custom metrics support dirty reads?

Hi @CosmicOppai,

I’m not able to try it now, so this can fail, but have you tried using one line and enclosing everything in quotes? I’m not sure PMM currently accepts multiple statements in the query field, but we can check the code if your tests fail, to see how it’s being handled.

@Agustin_G
I tried keeping everything in one line inside the quotes, but it’s not working

@Agustin_G
is it possible to set isolation level for the entire session?

Hi,
Not that I know of (unless you change defaults in MySQL itself, but this will of course impact your application too).
You can create a new feature request for it, if you really need it. I don’t think it’s a bad idea. You can do it via the following link:
https://perconadev.atlassian.net/jira/software/c/projects/PMM/issues/?filter=allissues