SSE: Update execution order to move DS queries first (#105686)

This is part of getting SSE more consistent when run from the query service vs part of grafana-server. 
fixes #105680
This commit is contained in:
Kyle Brandt 2025-05-27 09:34:40 -04:00 committed by GitHub
parent b6c9ecf7fe
commit 005f390df4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 5 deletions

View File

@ -211,19 +211,29 @@ func (s *Service) buildDependencyGraph(req *Request) (*simple.DirectedGraph, err
// buildExecutionOrder returns a sequence of nodes ordered by dependency.
// Note: During execution, Datasource query nodes for the same datasource will
// be grouped into one request and executed first as phase after this call.
// be grouped into one request and executed first as phase after this call
// If the groupByDSFlag is enabled.
func buildExecutionOrder(graph *simple.DirectedGraph) ([]Node, error) {
sortedNodes, err := topo.SortStabilized(graph, nil)
if err != nil {
return nil, err
}
nodes := make([]Node, len(sortedNodes))
for i, v := range sortedNodes {
nodes[i] = v.(Node)
var dsNodes []Node
var otherNodes []Node
for _, v := range sortedNodes {
n := v.(Node)
switch n.NodeType() {
case TypeDatasourceNode, TypeMLNode:
dsNodes = append(dsNodes, n)
default:
otherNodes = append(otherNodes, n)
}
}
return nodes, nil
// Datasource/ML nodes come first, followed by all others, in original topo order
return append(dsNodes, otherNodes...), nil
}
// buildNodeRegistry returns a lookup table for reference IDs to respective node.