-
Notifications
You must be signed in to change notification settings - Fork 122
Description
Description: When the Add metadata toggle is enabled in the query editor, the plugin appends a comment to the SQL query containing context about the dashboard and user. However, the variable $__user is not being interpolated correctly by Grafana and appears as the literal string $__user in the ClickHouse query logs.
It appears that in modern Grafana versions, $__user is an object (containing login, email, id), and using it directly as a string often fails or requires specific dot notation (e.g., ${__user.login}).
Steps to Reproduce:
Create a panel in Grafana using the Altinity ClickHouse data source.
Toggle the Add metadata option to ON in the query editor.
Execute the query.
Check the ClickHouse query log (system.query_log) or inspect the generated SQL in Grafana's "Query Inspector".
Expected Behavior: The generated SQL comment should contain the actual username of the logged-in user. Example: /* grafana dashboard=MyDashboard, user=admin */
Actual Behavior: The generated SQL comment contains the literal variable string. Example: /* grafana dashboard=MyDashboard, user=$__user */
Relevant Code: This likely stems from how the metadata string is constructed in the query builder. If $__user is passed raw without braces or property accessors (like ${__user.login} ), newer Grafana versions may not replace it.
Workaround: Manually disabling "Add metadata" and adding a comment to the query works if specific properties are used: /* user=${__user.login} */ SELECT ...
Environment:
Grafana version: [12.3.0]
Plugin version: [3.4.8]
ClickHouse version: [25.8]
Possible Solution: Update the metadata generation logic to use ${__user.login} or ${__user.id} instead of the raw $__user variable, which provides better compatibility with recent Grafana versions.