feat(dashboard): add datasource and default values for query (#9705)

This commit is contained in:
Vikrant Gupta
2025-11-27 19:16:06 +05:30
committed by GitHub
parent 891c56b059
commit e716a2a7b1
2 changed files with 57 additions and 79 deletions

View File

@@ -334,6 +334,7 @@ func (dashboard *Dashboard) GetWidgetQuery(startTime, endTime uint64, widgetInde
PromQL []map[string]any `json:"promql"`
QueryType string `json:"queryType"`
} `json:"query"`
FillGaps bool `json:"fillSpans"`
} `json:"widgets"`
}
@@ -414,6 +415,10 @@ func (dashboard *Dashboard) GetWidgetQuery(startTime, endTime uint64, widgetInde
"compositeQuery": map[string]any{
"queries": compositeQueries,
},
"formatOptions": map[string]any{
"fillGaps": widgetData.FillGaps,
"formatTableResultForUI": widgetData.PanelTypes == "table",
},
}
req, err := json.Marshal(queryRangeReq)

View File

@@ -128,86 +128,59 @@ func NewPublicDashboardDataFromDashboard(dashboard *Dashboard, publicDashboard *
}
for idx, widget := range data.Widgets {
switch widget.Query.QueryType {
case "builder":
widget.Query.ClickhouseSQL = []map[string]any{}
widget.Query.PromQL = []map[string]any{}
updatedQueryData := []map[string]any{}
for _, queryData := range widget.Query.Builder.QueryData {
updatedQueryMap := map[string]any{}
updatedQueryMap["aggregations"] = queryData["aggregations"]
updatedQueryMap["legend"] = queryData["legend"]
updatedQueryMap["queryName"] = queryData["queryName"]
updatedQueryMap["expression"] = queryData["expression"]
updatedQueryMap["groupBy"] = queryData["groupBy"]
updatedQueryData = append(updatedQueryData, updatedQueryMap)
}
widget.Query.Builder.QueryData = updatedQueryData
updatedQueryFormulas := []map[string]any{}
for _, queryFormula := range widget.Query.Builder.QueryFormulas {
updatedQueryFormulaMap := map[string]any{}
updatedQueryFormulaMap["legend"] = queryFormula["legend"]
updatedQueryFormulaMap["queryName"] = queryFormula["queryName"]
updatedQueryFormulaMap["expression"] = queryFormula["expression"]
updatedQueryFormulas = append(updatedQueryFormulas, updatedQueryFormulaMap)
}
widget.Query.Builder.QueryFormulas = updatedQueryFormulas
updatedQueryTraceOperator := []map[string]any{}
for _, queryTraceOperator := range widget.Query.Builder.QueryTraceOperator {
updatedQueryTraceOperatorMap := map[string]any{}
updatedQueryTraceOperatorMap["aggregations"] = queryTraceOperator["aggregations"]
updatedQueryTraceOperatorMap["legend"] = queryTraceOperator["legend"]
updatedQueryTraceOperatorMap["queryName"] = queryTraceOperator["queryName"]
updatedQueryTraceOperatorMap["expression"] = queryTraceOperator["expression"]
updatedQueryTraceOperatorMap["groupBy"] = queryTraceOperator["groupBy"]
updatedQueryTraceOperator = append(updatedQueryTraceOperator, updatedQueryTraceOperatorMap)
}
widget.Query.Builder.QueryTraceOperator = updatedQueryTraceOperator
case "clickhouse_sql":
widget.Query.Builder = struct {
QueryData []map[string]any `json:"queryData"`
QueryFormulas []map[string]any `json:"queryFormulas"`
QueryTraceOperator []map[string]any `json:"queryTraceOperator"`
}{}
widget.Query.PromQL = []map[string]any{}
updatedClickhouseSQLQuery := []map[string]any{}
for _, clickhouseSQLQuery := range widget.Query.ClickhouseSQL {
updatedClickhouseSQLQueryMap := make(map[string]any)
updatedClickhouseSQLQueryMap["legend"] = clickhouseSQLQuery["legend"]
updatedClickhouseSQLQueryMap["name"] = clickhouseSQLQuery["name"]
updatedClickhouseSQLQuery = append(updatedClickhouseSQLQuery, updatedClickhouseSQLQueryMap)
}
widget.Query.ClickhouseSQL = updatedClickhouseSQLQuery
case "promql":
widget.Query.Builder = struct {
QueryData []map[string]any `json:"queryData"`
QueryFormulas []map[string]any `json:"queryFormulas"`
QueryTraceOperator []map[string]any `json:"queryTraceOperator"`
}{}
widget.Query.ClickhouseSQL = []map[string]any{}
updatedPromQLQuery := []map[string]any{}
for _, promQLQuery := range widget.Query.PromQL {
updatedPromQLQueryMap := make(map[string]any)
updatedPromQLQueryMap["legend"] = promQLQuery["legend"]
updatedPromQLQueryMap["name"] = promQLQuery["name"]
updatedPromQLQuery = append(updatedPromQLQuery, updatedPromQLQueryMap)
}
widget.Query.PromQL = updatedPromQLQuery
default:
widget.Query.Builder = struct {
QueryData []map[string]any `json:"queryData"`
QueryFormulas []map[string]any `json:"queryFormulas"`
QueryTraceOperator []map[string]any `json:"queryTraceOperator"`
}{}
widget.Query.ClickhouseSQL = []map[string]any{}
widget.Query.PromQL = []map[string]any{}
updatedQueryData := []map[string]any{}
for _, queryData := range widget.Query.Builder.QueryData {
updatedQueryMap := map[string]any{}
updatedQueryMap["aggregations"] = queryData["aggregations"]
updatedQueryMap["legend"] = queryData["legend"]
updatedQueryMap["queryName"] = queryData["queryName"]
updatedQueryMap["expression"] = queryData["expression"]
updatedQueryMap["groupBy"] = queryData["groupBy"]
updatedQueryMap["dataSource"] = queryData["dataSource"]
updatedQueryData = append(updatedQueryData, updatedQueryMap)
}
widget.Query.Builder.QueryData = updatedQueryData
updatedQueryFormulas := []map[string]any{}
for _, queryFormula := range widget.Query.Builder.QueryFormulas {
updatedQueryFormulaMap := map[string]any{}
updatedQueryFormulaMap["legend"] = queryFormula["legend"]
updatedQueryFormulaMap["queryName"] = queryFormula["queryName"]
updatedQueryFormulaMap["expression"] = queryFormula["expression"]
updatedQueryFormulas = append(updatedQueryFormulas, updatedQueryFormulaMap)
}
widget.Query.Builder.QueryFormulas = updatedQueryFormulas
updatedQueryTraceOperator := []map[string]any{}
for _, queryTraceOperator := range widget.Query.Builder.QueryTraceOperator {
updatedQueryTraceOperatorMap := map[string]any{}
updatedQueryTraceOperatorMap["aggregations"] = queryTraceOperator["aggregations"]
updatedQueryTraceOperatorMap["legend"] = queryTraceOperator["legend"]
updatedQueryTraceOperatorMap["queryName"] = queryTraceOperator["queryName"]
updatedQueryTraceOperatorMap["expression"] = queryTraceOperator["expression"]
updatedQueryTraceOperatorMap["groupBy"] = queryTraceOperator["groupBy"]
updatedQueryTraceOperatorMap["dataSource"] = queryTraceOperator["dataSource"]
updatedQueryTraceOperator = append(updatedQueryTraceOperator, updatedQueryTraceOperatorMap)
}
widget.Query.Builder.QueryTraceOperator = updatedQueryTraceOperator
updatedClickhouseSQLQuery := []map[string]any{}
for _, clickhouseSQLQuery := range widget.Query.ClickhouseSQL {
updatedClickhouseSQLQueryMap := make(map[string]any)
updatedClickhouseSQLQueryMap["legend"] = clickhouseSQLQuery["legend"]
updatedClickhouseSQLQueryMap["name"] = clickhouseSQLQuery["name"]
updatedClickhouseSQLQuery = append(updatedClickhouseSQLQuery, updatedClickhouseSQLQueryMap)
}
widget.Query.ClickhouseSQL = updatedClickhouseSQLQuery
updatedPromQLQuery := []map[string]any{}
for _, promQLQuery := range widget.Query.PromQL {
updatedPromQLQueryMap := make(map[string]any)
updatedPromQLQueryMap["legend"] = promQLQuery["legend"]
updatedPromQLQueryMap["name"] = promQLQuery["name"]
updatedPromQLQuery = append(updatedPromQLQuery, updatedPromQLQueryMap)
}
widget.Query.PromQL = updatedPromQLQuery
if widgets, ok := dashboard.Data["widgets"].([]any); ok {
if widgetMap, ok := widgets[idx].(map[string]any); ok {