mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* Previews: datasource permissions * lint * simplify - force non-null `ds_uids` * add `canBeDisabled` to search service * add `IncludeThumbnailsWithEmptyDsUids` * remove force refresh migration * refactor main preview service * add safeguard * revert ticker interval * update testdata * fix test * add mock search service * add datasources lookup test * update migration * extract ds lookup to its own package to avoid cyclic imports * lint * fix dashbaord extract, use the real datasource lookup in tests. IS IT BULLETPROOF YET?! * fix dashbaord extract, use the real datasource lookup in tests. IS IT BULLETPROOF YET?! * remove stale log * consistent casing * pass context to `createServiceAccount` * filter out the special grafana ds
94 lines
1.9 KiB
Go
94 lines
1.9 KiB
Go
package extract
|
|
|
|
import (
|
|
jsoniter "github.com/json-iterator/go"
|
|
|
|
"github.com/grafana/grafana/pkg/services/searchV2/dslookup"
|
|
)
|
|
|
|
type targetInfo struct {
|
|
lookup dslookup.DatasourceLookup
|
|
uids map[string]*dslookup.DataSourceRef
|
|
}
|
|
|
|
func newTargetInfo(lookup dslookup.DatasourceLookup) targetInfo {
|
|
return targetInfo{
|
|
lookup: lookup,
|
|
uids: make(map[string]*dslookup.DataSourceRef),
|
|
}
|
|
}
|
|
|
|
func (s *targetInfo) GetDatasourceInfo() []dslookup.DataSourceRef {
|
|
keys := make([]dslookup.DataSourceRef, len(s.uids))
|
|
i := 0
|
|
for _, v := range s.uids {
|
|
keys[i] = *v
|
|
i++
|
|
}
|
|
return keys
|
|
}
|
|
|
|
// the node will either be string (name|uid) OR ref
|
|
func (s *targetInfo) addDatasource(iter *jsoniter.Iterator) {
|
|
switch iter.WhatIsNext() {
|
|
case jsoniter.StringValue:
|
|
key := iter.ReadString()
|
|
|
|
dsRef := &dslookup.DataSourceRef{UID: key}
|
|
if !isVariableRef(dsRef.UID) && !isSpecialDatasource(dsRef.UID) {
|
|
ds := s.lookup.ByRef(dsRef)
|
|
s.addRef(ds)
|
|
} else {
|
|
s.addRef(dsRef)
|
|
}
|
|
|
|
case jsoniter.NilValue:
|
|
s.addRef(s.lookup.ByRef(nil))
|
|
iter.Skip()
|
|
|
|
case jsoniter.ObjectValue:
|
|
ref := &dslookup.DataSourceRef{}
|
|
iter.ReadVal(ref)
|
|
|
|
if !isVariableRef(ref.UID) && !isSpecialDatasource(ref.UID) {
|
|
s.addRef(s.lookup.ByRef(ref))
|
|
} else {
|
|
s.addRef(ref)
|
|
}
|
|
|
|
default:
|
|
v := iter.Read()
|
|
logf("[Panel.datasource.unknown] %v\n", v)
|
|
}
|
|
}
|
|
|
|
func (s *targetInfo) addRef(ref *dslookup.DataSourceRef) {
|
|
if ref != nil && ref.UID != "" {
|
|
s.uids[ref.UID] = ref
|
|
}
|
|
}
|
|
|
|
func (s *targetInfo) addTarget(iter *jsoniter.Iterator) {
|
|
for l1Field := iter.ReadObject(); l1Field != ""; l1Field = iter.ReadObject() {
|
|
switch l1Field {
|
|
case "datasource":
|
|
s.addDatasource(iter)
|
|
|
|
case "refId":
|
|
iter.Skip()
|
|
|
|
default:
|
|
v := iter.Read()
|
|
logf("[Panel.TARGET] %s=%v\n", l1Field, v)
|
|
}
|
|
}
|
|
}
|
|
|
|
func (s *targetInfo) addPanel(panel PanelInfo) {
|
|
for idx, v := range panel.Datasource {
|
|
if v.UID != "" {
|
|
s.uids[v.UID] = &panel.Datasource[idx]
|
|
}
|
|
}
|
|
}
|