grafana/pkg/registry/apis/query
Ryan McKinley 42b0f802de
QueryTypes: Add feature toggle to show query types in datasource apiservers (#88213)
* initial attempt

* show query types

* show query types

* with formatting

* with formatting

* more cleanup

* add feature toggle

* fix build
2024-05-23 18:46:28 +02:00
..
client QueryService: Add feature toggles to better support testing (#86493) 2024-04-19 12:26:21 +03:00
queryschema QueryTypes: Add feature toggle to show query types in datasource apiservers (#88213) 2024-05-23 18:46:28 +02:00
testdata QueryService: Return application/json and better errors (#84234) 2024-03-19 15:52:15 +02:00
client.go QueryService: Use types from sdk (#84029) 2024-03-08 18:12:59 +02:00
errors_test.go QueryService: Return application/json and better errors (#84234) 2024-03-19 15:52:15 +02:00
errors.go QueryService: Return application/json and better errors (#84234) 2024-03-19 15:52:15 +02:00
metrics.go QueryService: Use types from sdk (#84029) 2024-03-08 18:12:59 +02:00
parser_test.go QueryService: Return application/json and better errors (#84234) 2024-03-19 15:52:15 +02:00
parser.go QueryTypes: Add feature toggle to show query types in datasource apiservers (#88213) 2024-05-23 18:46:28 +02:00
plugins.go QueryService: Add feature toggles to better support testing (#86493) 2024-04-19 12:26:21 +03:00
query.go API Server: Include traceID in HTTP request logs (#88179) 2024-05-22 17:56:34 +02:00
README.md QueryService: Add feature toggles to better support testing (#86493) 2024-04-19 12:26:21 +03:00
register.go QueryTypes: Add feature toggle to show query types in datasource apiservers (#88213) 2024-05-23 18:46:28 +02:00

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