mirror of
https://github.com/grafana/grafana.git
synced 2026-08-18 17:15:08 -05:00
Start of dashboard query API (#49547)
This PR adds endpoints for public dashboards to retrieve data from the backend (trusted) query engine. It works by executing queries defined on the backend without any user input and does not support template variables. * Public dashboard query API * Create new API on service for building metric request * Flesh out testing, implement BuildPublicDashboardMetricRequest * Test for errors and missing panels * Refactor tests, add supporting code for multiple datasources * Handle queries from multiple datasources * Explicitly pass no user for querying public dashboard Co-authored-by: Jeff Levin <jeff@levinology.com>
This commit is contained in:
co-authored by
Jeff Levin
parent
07aa2bbbba
commit
0371884cdd
@@ -83,6 +83,33 @@ func (s *Service) QueryData(ctx context.Context, user *models.SignedInUser, skip
|
||||
return s.handleQueryData(ctx, user, parsedReq)
|
||||
}
|
||||
|
||||
// QueryData can process queries and return query responses.
|
||||
func (s *Service) QueryDataMultipleSources(ctx context.Context, user *models.SignedInUser, skipCache bool, reqDTO dtos.MetricRequest, handleExpressions bool) (*backend.QueryDataResponse, error) {
|
||||
byDataSource := models.GroupQueriesByDataSource(reqDTO.Queries)
|
||||
|
||||
if len(byDataSource) == 1 {
|
||||
return s.QueryData(ctx, user, skipCache, reqDTO, handleExpressions)
|
||||
} else {
|
||||
resp := backend.NewQueryDataResponse()
|
||||
|
||||
for _, queries := range byDataSource {
|
||||
subDTO := reqDTO.CloneWithQueries(queries)
|
||||
|
||||
subResp, err := s.QueryData(ctx, user, skipCache, subDTO, handleExpressions)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for refId, queryResponse := range subResp.Responses {
|
||||
resp.Responses[refId] = queryResponse
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
|
||||
// handleExpressions handles POST /api/ds/query when there is an expression.
|
||||
func (s *Service) handleExpressions(ctx context.Context, user *models.SignedInUser, parsedReq *parsedRequest) (*backend.QueryDataResponse, error) {
|
||||
exprReq := expr.Request{
|
||||
|
||||
Reference in New Issue
Block a user