grafana/pkg/registry/apis/query
Kyle Brandt d64f41afdc
SQL Expressions: Re-implement feature using go-mysql-server (#99521)
* Under feature flag `sqlExpressions` and is experimental
* Excluded from arm32
* Will not work with the Query Service yet
* Does not have limits in place yet
* Does not working with alerting yet
* Currently requires "prepare time series" Transform for time series viz
 
---------

Co-authored-by: Sam Jewell <sam.jewell@grafana.com>
2025-02-06 07:27:28 -05:00
..
client datasources: querier: adjust the query-client (#99805) 2025-02-03 09:06:18 +01:00
clientapi datasources: querier: adjust the query-client (#99805) 2025-02-03 09:06:18 +01:00
queryschema
testdata chore: move DatasourceUid parsing to ruler instead (#95972) 2024-11-07 21:48:29 -05:00
README.md
client.go datasources: querier: adjust the query-client (#99805) 2025-02-03 09:06:18 +01:00
errors.go
errors_test.go
header_utils.go query: add missing x-rule headers (#95948) 2024-11-07 16:03:54 +01:00
metrics.go
parser.go Add logging to legacy datasource look up path (#97065) 2024-11-27 14:32:06 -05:00
parser_test.go Add logging to legacy datasource look up path (#97065) 2024-11-27 14:32:06 -05:00
plugins.go
query.go SQL Expressions: Re-implement feature using go-mysql-server (#99521) 2025-02-06 07:27:28 -05:00
query_test.go datasources: querier: adjust the query-client (#99805) 2025-02-03 09:06:18 +01:00
register.go datasources: querier: adjust the query-client (#99805) 2025-02-03 09:06:18 +01:00

README.md

Query service

This query service aims to replace the existing /api/ds/query.

The key differences are:

  1. This service has a stronger type system (not simplejson)
  2. Same workflow regardless if expressions exist
  3. Datasource settings+access is managed in each datasource, not at the beginning

Current /api/ds/query workflow

sequenceDiagram
    autonumber
    actor User as User or Process
    participant api as /api/ds/query
    participant db as Storage<br/>(SQL)
    participant ds as Datasource<br/>Plugin
    participant expr as Expression<br/>Engine

    User->>api: POST Query
    loop Each query
        api->>api: Parse query
        api->>db: Get ds config<br>and secrets
        db->>api: 
    end
    alt No expressions
      alt Single datasource
          api->>ds: QueryData
      else Multiple datasources
        loop Each datasource (concurrently)
          api->>ds: QueryData
        end
        api->>api: Wait for results
      end
    else Expressions exist
        api->>expr: Calculate expressions graph
        loop Each node (eg, refID)
          alt Is query
              expr->>ds: QueryData
          else Is expression
            expr->>expr: Process
          end
        end
    end
    api->>User: return results

/apis/query.grafana.app (in single tenant grafana)

sequenceDiagram
    autonumber
    actor User as User or Process
    participant api as /apis/query.grafana.app
    participant ds as Datasource<br/>Handler/Plugin
    participant db as Storage<br/>(SQL)
    participant expr as Expression<br/>Engine

    User->>api: POST Query
    api->>api: Parse queries
    api->>api: Calculate dependencies
    loop Each datasource (concurrently)
        api->>ds: QueryData
        ds->>ds: Verify user access
        ds->>db: Get settings <br> and secrets
    end
    loop Each expression
        api->>expr: Execute
    end
    api->>api: Verify ResultExpectations
    api->>User: return results