mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Store: don't marshall/unmarshall the dashboard when building a summary (#57520)
* dont pretty print the dashboard * stop marshalling the dashboard * do not sanitize for searchV2 Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
parent
749b3b6263
commit
e485ddd13d
@ -59,7 +59,7 @@ func exportDashboards(helper *commitHelper, job *gitExportJob) error {
|
||||
return err
|
||||
}
|
||||
|
||||
reader := dashboard.NewStaticDashboardSummaryBuilder(lookup)
|
||||
reader := dashboard.NewStaticDashboardSummaryBuilder(lookup, false)
|
||||
|
||||
// Process all folders
|
||||
for _, row := range rows {
|
||||
|
@ -953,7 +953,7 @@ func (l sqlDashboardLoader) LoadDashboards(ctx context.Context, orgID int64, das
|
||||
readDashboardSpan.SetAttributes("orgID", orgID, attribute.Key("orgID").Int64(orgID))
|
||||
readDashboardSpan.SetAttributes("dashboardCount", len(rows), attribute.Key("dashboardCount").Int(len(rows)))
|
||||
|
||||
reader := kdash.NewStaticDashboardSummaryBuilder(lookup)
|
||||
reader := kdash.NewStaticDashboardSummaryBuilder(lookup, false)
|
||||
|
||||
for _, row := range rows {
|
||||
summary, _, err := reader(ctx, row.Uid, row.Data)
|
||||
|
@ -21,24 +21,27 @@ func GetObjectKindInfo() models.ObjectKindInfo {
|
||||
|
||||
// This summary does not resolve old name as UID
|
||||
func GetObjectSummaryBuilder() models.ObjectSummaryBuilder {
|
||||
builder := NewStaticDashboardSummaryBuilder(&directLookup{})
|
||||
builder := NewStaticDashboardSummaryBuilder(&directLookup{}, true)
|
||||
return func(ctx context.Context, uid string, body []byte) (*models.ObjectSummary, []byte, error) {
|
||||
return builder(ctx, uid, body)
|
||||
}
|
||||
}
|
||||
|
||||
// This implementation moves datasources referenced by internal ID or name to UID
|
||||
func NewStaticDashboardSummaryBuilder(lookup DatasourceLookup) models.ObjectSummaryBuilder {
|
||||
func NewStaticDashboardSummaryBuilder(lookup DatasourceLookup, sanitize bool) models.ObjectSummaryBuilder {
|
||||
return func(ctx context.Context, uid string, body []byte) (*models.ObjectSummary, []byte, error) {
|
||||
var parsed map[string]interface{}
|
||||
err := json.Unmarshal(body, &parsed)
|
||||
if err != nil {
|
||||
return nil, nil, err // did not parse
|
||||
|
||||
if sanitize {
|
||||
err := json.Unmarshal(body, &parsed)
|
||||
if err != nil {
|
||||
return nil, nil, err // did not parse
|
||||
}
|
||||
// values that should be managed by the container
|
||||
delete(parsed, "uid")
|
||||
delete(parsed, "version")
|
||||
// slug? (derived from title)
|
||||
}
|
||||
// values that should be managed by the container
|
||||
delete(parsed, "uid")
|
||||
delete(parsed, "version")
|
||||
// slug? (derived from title)
|
||||
|
||||
summary := &models.ObjectSummary{
|
||||
Labels: make(map[string]string),
|
||||
@ -98,7 +101,9 @@ func NewStaticDashboardSummaryBuilder(lookup DatasourceLookup) models.ObjectSumm
|
||||
}
|
||||
|
||||
summary.References = dashboardRefs.Get()
|
||||
out, err := json.MarshalIndent(parsed, "", " ")
|
||||
return summary, out, err
|
||||
if sanitize {
|
||||
body, err = json.MarshalIndent(parsed, "", " ")
|
||||
}
|
||||
return summary, body, err
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user