The Trino datasource allows to query and visualize Trino data from within Grafana.
To run a locally built, unsigned copy of the plugin, see DEVELOPMENT.md.
- In Grafana, go to Connections > Data sources and click Add new data source.
- Select Trino.
- Set URL to the Trino coordinator, for example
http://trino.example.com:8080. - Configure authentication, if your Trino cluster requires it.
- Click Save & test.
Open Explore, or add a panel to a dashboard, select the Trino data source and run a query, for example:
SELECT * FROM tpch.tiny.orders LIMIT 10The tpch catalog is only available if it's configured in Trino.
Authentication is configured in the data source settings. The options below can be combined, except where noted.
Under Auth, enable Basic auth and set User and Password. Trino
only accepts passwords over HTTPS, unless it's configured to allow them over
HTTP. With an http:// URL, the password is sent unencrypted, so only set one
when Trino sits behind a proxy that terminates TLS. Versions up to 1.2.0 never
sent the password over HTTP, and a Trino without password authentication
rejects one with 401 Unauthorized: remove the password from such a data
source. The password is not sent when the request already carries an access
token, a forwarded OAuth identity or an OAuth client token.
The basic auth user is also the Trino session user, even without a password.
Without basic auth, the session user is grafana, or with
Kerberos the user Trino maps the principal to. When Trino authenticates a
request with a token or certificate and its principal differs from the session
user, Trino's access control must allow impersonating that user. The
impersonation options below change the session user.
Under Auth:
- TLS Client Auth sends a client certificate and key, for Trino's certificate authentication.
- With CA Cert verifies the Trino server certificate against a custom CA.
- Skip TLS Verify disables server certificate verification.
Set Access token in the Trino section to send a static bearer token, such
as a JWT, with every request. It can't be combined with the OAuth client
credentials flow. With an http:// URL, the token is sent unencrypted, and
Trino ignores it unless Trino sits behind a proxy that terminates TLS. The
same goes for the OAuth client token and the forwarded OAuth identity.
In the OAuth Trino Authentication section, set Token URL, Client id and Client secret. All three are required. The plugin gets an access token from the token URL using the OAuth 2.0 client credentials flow, and sends it to Trino. The flow can't be combined with a basic auth password, which would be sent to the token URL too; a basic auth user without a password still sets the session user.
Impersonation user, if set, is sent as the Trino session user. Trino must allow the token's principal to impersonate that user. When impersonation of the signed-in user is enabled, the impersonation user only applies to anonymous users.
If Grafana users sign in with OAuth, enable Forward OAuth Identity under Auth to send the signed-in user's OAuth access token to Trino as a bearer token, instead of the configured access token. Trino must be configured to accept tokens from the same identity provider. The forwarded token is not used when the OAuth client credentials flow is configured, because the token from that flow replaces it.
Enable Enable Kerberos in the Kerberos Authentication section to
authenticate to a Trino cluster secured with
Kerberos. Trino only
accepts Kerberos over HTTPS, so the URL must use https://. The data source
logs in with a keytab; everything it needs is stored with the data source, and
nothing is read from the Grafana server's filesystem or environment:
- Principal and Realm name the principal to log in as.
- Config is the content of a krb5.conf, which lists the KDCs of the realm and maps hosts to realms.
- Keytab is the keytab file holding the principal's key, uploaded from your machine and stored encrypted, like a password.
- Remote service name, Service principal pattern and Use canonical
hostname name the coordinator's service principal,
trino@<host>by default. The host is first resolved to its canonical name through reverse DNS; turn off Use canonical hostname when that name differs from the one in the service principal, as it does in Docker, which appends the network name.
The data source logs in when it is saved or loaded and renews its ticket from the keytab, so a KDC that is unreachable at that point fails Save & test.
Kerberos can't be combined with a basic auth password, an access token, the
OAuth client credentials flow or Forward OAuth Identity, which would replace
the Kerberos credentials. Without basic auth, queries run as the Trino user the
principal maps to, instead of grafana. A basic auth user without a password,
or impersonation of the signed-in user, sets
another session user, which the principal must be allowed to impersonate.
Enable Impersonate logged in user in the Trino section to run queries as
the Grafana user, instead of the data source's user. Impersonate as selects
whether the user's Login or Email becomes the Trino session user. With
Email, users without an email run as their login. Alert and recording rules
run as Grafana's grafana_scheduler user, which has no email. Trino must allow
the authenticated user to impersonate other users, including
grafana_scheduler. To keep alert rules off the data source, deny
impersonating grafana_scheduler in Trino.
If Grafana already stores the short username as the login, select Login and
leave Remove username suffix empty. Generic OAuth can map that login with
login_attribute_path, LDAP with servers.attributes.username, and SAML with
assertion_attribute_login.
Use Remove username suffix when the selected login or email includes a domain
that Trino usernames omit. For example, when an OAuth provider supplies
alice@example.com as the login, enter @example.com to send alice. The suffix
is matched literally, ignoring case, and only one trailing occurrence is removed.
Leave the setting empty to send the selected login or email as stored. Provision
it as jsonData.impersonationStripSuffix.
Trino must allow the resulting username. Choose a suffix that preserves the
intended user identities: alice and alice@example.com will both run as
alice. Removing the entire username fails the query instead of falling back
to the data source's account. This setting does not change authentication
credentials, Grafana logins, or other data sources.
Anonymous users are not impersonated, and run as the data source's user, or the OAuth impersonation user if set.
Roles in the Trino section sets authorization roles per catalog, as
catalog:role pairs separated by semicolons. Use system for system roles, for
example system:admin;hive:analyst.
Client Tags in the Trino section is a comma-separated list of tags sent with every query, used for example to select a Trino resource group. Queries can add more tags in the query editor.
The plugin stops reading the results of a query after row_limit rows, set in
the [dataproxy] section of Grafana's configuration, 1000000 by default, like
Grafana's built-in SQL data sources do. It then cancels the query in Trino, and
the panel shows a warning that the results were limited.
This keeps a query that returns far more rows than a panel can display, such as
raw data over a time range much longer than intended, from exhausting the
memory of the Grafana server. Queries aggregating data over long time ranges
return few rows and are not affected. To read more rows, raise row_limit.
Grafana passes row_limit to plugins since version 11.0. On earlier versions,
the limit is 1000000.
When Grafana has the secure SOCKS proxy enabled, as in Grafana Cloud with Private Data Source Connect, enable Secure Socks Proxy to reach a Trino cluster in a private network. The toggle is only shown when the proxy is enabled.
Custom HTTP headers are not supported, and the data source fails to load if any are set.
- Authentication with basic auth, TLS client certificates, access tokens, OAuth client credentials, the signed-in user's forwarded OAuth identity or Kerberos
- Raw SQL editor only, no query builder yet
- Macros
- Client tags support, used to identify resource groups. Tags can be set on the data source, and extended with additional tags in the query editor.
- Asynchronous queries, so long-running queries are not bound to a single HTTP request
ARRAY,MAPandROWcolumns rendered as JSON.- Trimming edges of time series, to hide incomplete first and last time buckets. Set "Trim edges" in the query editor to drop that many rows from the start and the end of every result with a time column, after ordering it by the first time column. Leave it empty to keep all rows.
- Impersonation of the signed-in Grafana user, by login or email.
- A row limit, cancelling queries that return more rows than Grafana's
row_limit.
By default a query is answered over one HTTP request, held open from the moment the panel runs until the last row arrives. Any proxy or load balancer in front of Grafana gets a say in how long that may take, and a long-running query is often cut short by an idle timeout even though Trino was still working on it.
Enabling Asynchronous queries in the data source settings switches to a polling flow: the plugin starts the query, immediately returns a handle, and the browser polls for its status every few seconds until the results are ready. Each request is short, so timeouts no longer apply, and a dropped connection no longer throws away the work the cluster has already done. The data still arrives in one piece at the end; the query does not get faster and results are not streamed in progressively.
Alerting and expression queries always use the synchronous flow, because there is no browser to poll on their behalf.
A few things are worth knowing before turning it on:
- Keep the dashboard's refresh interval longer than the query takes to run. Each refresh cancels the query still in flight and starts a new one, so a dashboard that refreshes faster than its queries finish never shows a result at all, and keeps the cluster busy with work it then throws away. The synchronous flow behaves the same way, but asynchronous queries tend to be enabled for exactly the queries where the two intervals are close enough to collide.
- Results are held in the plugin's memory between polls. Peak memory is the same as the synchronous flow, bounded by the row limit, but it is held for longer.
- Grafana's query caching (Enterprise and Cloud) doesn't apply to asynchronous queries, because every asynchronous request skips the cache. A data source that relies on that cache to avoid rerunning expensive queries reruns them on every refresh, and for every viewer, once asynchronous queries are on.
- If you run more than one Grafana instance behind a load balancer, enable session affinity (sticky sessions). A poll routed to a different instance cannot see the query, because the connection to Trino and the rows read so far live in the instance that started it. Polls that land on the wrong instance fail with an error saying so.
ARRAY, MAP and ROW values are returned as JSON fields, with ROW values
converted to objects keyed by field name. Unnamed fields, and fields whose
names collide after lower-casing, are keyed by position as _col<N>; rows with
no named fields at all stay positional arrays. In the table panel, hover a cell and click the eye icon to
open the value in a formatted, collapsible JSON viewer. Explore on Grafana 11.6
through 12.3 does not show the eye icon; dashboard table panels do.
Row field names are returned in lower case, so quoted mixed-case field names
such as "Word Start" appear as word start.
The plugin expands macros in the query before sending it to Trino. Macro names
start with $__, for example $__timeFilter(created_at).
The time range boundaries are converted to UTC and rendered without a time
zone. The expansions below assume the dashboard time range is
2023-01-01 00:00:00 to 2023-01-02 00:00:00 UTC.
| Macro | Expands to |
|---|---|
$__timeFilter(col) |
col BETWEEN TIMESTAMP '2023-01-01 00:00:00' AND TIMESTAMP '2023-01-02 00:00:00' |
$__timeFilter(col, 'yyyy-MM-dd') |
parse_datetime(col,'yyyy-MM-dd') BETWEEN TIMESTAMP '2023-01-01 00:00:00' AND TIMESTAMP '2023-01-02 00:00:00' |
$__dateFilter(col) |
col BETWEEN date '2023-01-01' AND date '2023-01-02' |
$__unixEpochFilter(col) |
col BETWEEN 1672531200 AND 1672617600 |
$__timeFrom() |
TIMESTAMP '2023-01-01 00:00:00' |
$__timeTo() |
TIMESTAMP '2023-01-02 00:00:00' |
$__timeGroup(col, '1h') |
FROM_UNIXTIME(FLOOR(TO_UNIXTIME(col)/3600)*3600) |
$__timeGroup(col, '1d', 'yyyy-MM-dd') |
FROM_UNIXTIME(FLOOR(TO_UNIXTIME(parse_datetime(col,'yyyy-MM-dd'))/86400)*86400) |
$__unixEpochGroup(col, '1h') |
FROM_UNIXTIME(FLOOR(col/3600)*3600) |
$__parseTime('2023-01-01 12:00:00') |
TIMESTAMP '2023-01-01 12:00:00' |
$__parseTime(col, 'yyyy-MM-dd') |
parse_datetime(col,'yyyy-MM-dd') |
$__interval |
The panel's interval, for example 1m |
$__interval_ms |
The panel's interval in milliseconds, for example 60000 |
Notes:
$__timeFilter,$__dateFilterand$__unixEpochFilterinclude both boundaries.$__unixEpochFilterand$__unixEpochGroupexpect a column with the number of seconds since the Unix epoch.- The interval in
$__timeGroupand$__unixEpochGroupcan be quoted or not, and uses Grafana's interval syntax, like30s,5m,1h,1dor1w. Use$__intervalto follow the panel's interval, for example$__timeGroup(col, $__interval). - The optional format argument of
$__timeFilter,$__timeGroupand$__parseTimeis a quotedparse_datetimepattern. The pattern'yyyy-MM-dd HH:mm:ss'is special: it's expanded to aTIMESTAMPprefix instead, so it only works with string literals, such as$__parseTime('2023-01-01 12:00:00', 'yyyy-MM-dd HH:mm:ss'), not with columns. $__timeFrom()and$__timeTo()ignore any arguments.
Time series of the total order value per week, from the tpch catalog:
SELECT
$__timeGroup(orderdate, '1w') AS time,
sum(totalprice) AS value
FROM tpch.tiny.orders
WHERE $__timeFilter(orderdate)
GROUP BY 1
ORDER BY 1is sent to Trino as:
SELECT
FROM_UNIXTIME(FLOOR(TO_UNIXTIME(orderdate)/604800)*604800) AS time,
sum(totalprice) AS value
FROM tpch.tiny.orders
WHERE orderdate BETWEEN TIMESTAMP '2023-01-01 00:00:00' AND TIMESTAMP '2023-01-02 00:00:00'
GROUP BY 1
ORDER BY 1Filter a DATE column, such as a partition column, by day:
SELECT orderstatus, count(*) AS orders
FROM tpch.tiny.orders
WHERE $__dateFilter(orderdate)
GROUP BY 1SELECT orderstatus, count(*) AS orders
FROM tpch.tiny.orders
WHERE orderdate BETWEEN date '2023-01-01' AND date '2023-01-02'
GROUP BY 1Use the boundaries separately, for example to exclude the end of the range:
SELECT *
FROM events
WHERE event_time >= $__timeFrom() AND event_time < $__timeTo()SELECT *
FROM events
WHERE event_time >= TIMESTAMP '2023-01-01 00:00:00' AND event_time < TIMESTAMP '2023-01-02 00:00:00'Group and filter a column with Unix timestamps in seconds:
SELECT
$__unixEpochGroup(created_epoch, '1h') AS time,
count(*) AS value
FROM events
WHERE $__unixEpochFilter(created_epoch)
GROUP BY 1
ORDER BY 1SELECT
FROM_UNIXTIME(FLOOR(created_epoch/3600)*3600) AS time,
count(*) AS value
FROM events
WHERE created_epoch BETWEEN 1672531200 AND 1672617600
GROUP BY 1
ORDER BY 1Group and filter a VARCHAR column with dates like 2023-01-01:
SELECT
$__timeGroup(event_day, '1d', 'yyyy-MM-dd') AS time,
count(*) AS value
FROM events
WHERE $__timeFilter(event_day, 'yyyy-MM-dd')
GROUP BY 1
ORDER BY 1SELECT
FROM_UNIXTIME(FLOOR(TO_UNIXTIME(parse_datetime(event_day,'yyyy-MM-dd'))/86400)*86400) AS time,
count(*) AS value
FROM events
WHERE parse_datetime(event_day,'yyyy-MM-dd') BETWEEN TIMESTAMP '2023-01-01 00:00:00' AND TIMESTAMP '2023-01-02 00:00:00'
GROUP BY 1
ORDER BY 1Parse a string column in a query:
SELECT $__parseTime(event_day, 'yyyy-MM-dd') AS time, message
FROM eventsSELECT parse_datetime(event_day,'yyyy-MM-dd') AS time, message
FROM eventsTemplate variable values are only quoted when the template variable is a multi-value.
If the variable is a multi-value variable then use the IN comparison operator
rather than = to match against multiple values.
Example with a template variable named hostname:
SELECT
atimestamp as time,
aint as value
FROM table
WHERE $__timeFilter(atimestamp) and hostname in($hostname)
ORDER BY atimestamp ASCGrafana automatically creates a quoted, comma-separated string for multi-value variables.
For example: if server01 and server02 are selected then it will be formatted as:
'server01', 'server02'. To disable quoting, use the csv formatting option for variables:
${servers:csv}
Read more about variable formatting options in the Variables documentation.
If you have any idea for an improvement or found a bug do not hesitate to open an issue or submit a pull request. We will appreciate any help from the community.
See DEVELOPMENT.md for development instructions.
Apache 2.0 License, please see LICENSE for details.