* Wire up sprinkles to oss and enterprise. Fetching sprinkles not implemented yet. * Adds wireset for initializing document builders. Had to init it when creating the service to avoid cyclical imports. * updates to int64 for stats * adds config for sprinklesApiServer and gets sprinkles from there when its present * add comment for later * adds feature toggle for sprinkles. returns empty results when flag not enabled. * adds unified storage config setting for sprinkles apiserver page limit * fixes bug where dashboard uid was not getting set * when creating dashboard summary, use metadata.name as the dashboard uid * cleans up wire. use existing oss and enterprise sets to generate doc builders * remove old wireset * fix linter - adds missing arg for doc builders * update dashboard stats in tests * updates test-data dashboards * log a warning instead of returning an error if we can't get sprinkles for a namespace * dont read uid from dashboard json
77 lines
2.2 KiB
Go
77 lines
2.2 KiB
Go
package search
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/grafana/authlib/claims"
|
|
"github.com/grafana/grafana/pkg/infra/db"
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/services/store/kind/dashboard"
|
|
"github.com/grafana/grafana/pkg/storage/unified/resource"
|
|
)
|
|
|
|
// The default list of open source document builders
|
|
type StandardDocumentBuilders struct {
|
|
sql db.DB
|
|
sprinkles DashboardStats
|
|
}
|
|
|
|
// Hooked up so wire can fill in different sprinkles
|
|
func ProvideDocumentBuilders(sql db.DB, sprinkles DashboardStats) resource.DocumentBuilderSupplier {
|
|
return &StandardDocumentBuilders{sql, sprinkles}
|
|
}
|
|
|
|
func (s *StandardDocumentBuilders) GetDocumentBuilders() ([]resource.DocumentBuilderInfo, error) {
|
|
dashboards, err := DashboardBuilder(func(ctx context.Context, namespace string, blob resource.BlobSupport) (resource.DocumentBuilder, error) {
|
|
logger := log.New("dashboard_builder", "namespace", namespace)
|
|
dsinfo := []*dashboard.DatasourceQueryResult{{}}
|
|
ns, err := claims.ParseNamespace(namespace)
|
|
if err != nil && s.sql != nil {
|
|
rows, err := s.sql.GetSqlxSession().Query(ctx, "SELECT uid,type,name,is_default FROM data_source WHERE org_id=?", ns.OrgID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
defer func() {
|
|
_ = rows.Close()
|
|
}()
|
|
|
|
for rows.Next() {
|
|
info := &dashboard.DatasourceQueryResult{}
|
|
err = rows.Scan(&info.UID, &info.Type, &info.Name, &info.IsDefault)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
dsinfo = append(dsinfo, info)
|
|
}
|
|
}
|
|
|
|
// Fetch dashboard sprinkles for the namespace
|
|
// This could take a while if namespace has a lot of dashboards
|
|
var stats map[string]map[string]int64
|
|
if s.sprinkles != nil {
|
|
stats, err = s.sprinkles.GetStats(ctx, namespace)
|
|
if err != nil {
|
|
// only log a warning. Don't need to fail the indexer if we can't get sprinkles
|
|
logger.Warn("Failed to get sprinkles", "error", err)
|
|
}
|
|
}
|
|
|
|
return &DashboardDocumentBuilder{
|
|
Namespace: namespace,
|
|
Blob: blob,
|
|
Stats: stats,
|
|
DatasourceLookup: dashboard.CreateDatasourceLookup(dsinfo),
|
|
}, nil
|
|
})
|
|
|
|
return []resource.DocumentBuilderInfo{
|
|
// The default builder
|
|
{
|
|
Builder: resource.StandardDocumentBuilder(),
|
|
},
|
|
// Dashboard builder
|
|
dashboards,
|
|
}, err
|
|
}
|