Add logging to legacy datasource look up path (#97065)
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
data "github.com/grafana/grafana-plugin-sdk-go/experimental/apis/data/v0alpha1"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
)
|
||||
|
||||
@@ -38,6 +39,7 @@ type cachingLegacyDataSourceLookup struct {
|
||||
retriever DataSourceRetriever
|
||||
cache map[string]cachedValue
|
||||
cacheMu sync.Mutex
|
||||
log log.Logger
|
||||
}
|
||||
|
||||
type cachedValue struct {
|
||||
@@ -49,15 +51,18 @@ func ProvideLegacyDataSourceLookup(p *Service) LegacyDataSourceLookup {
|
||||
return &cachingLegacyDataSourceLookup{
|
||||
retriever: p,
|
||||
cache: make(map[string]cachedValue),
|
||||
log: log.New("legacy-datasource-lookup"),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *cachingLegacyDataSourceLookup) GetDataSourceFromDeprecatedFields(ctx context.Context, name string, id int64) (*data.DataSourceRef, error) {
|
||||
if id == 0 && name == "" {
|
||||
s.log.Error("missing id and name in GetDataSourceFromDeprecatedFields")
|
||||
return nil, fmt.Errorf("either name or ID must be set")
|
||||
}
|
||||
user, err := identity.GetRequester(ctx)
|
||||
if err != nil {
|
||||
s.log.Error("failed to get user from context after getRequester", "error", err)
|
||||
return nil, err
|
||||
}
|
||||
key := fmt.Sprintf("%d/%s/%d", user.GetOrgID(), name, id)
|
||||
@@ -74,6 +79,9 @@ func (s *cachingLegacyDataSourceLookup) GetDataSourceFromDeprecatedFields(ctx co
|
||||
Name: name,
|
||||
ID: id,
|
||||
})
|
||||
if err != nil {
|
||||
s.log.Error("failed to get datasource from retriever", "error", err)
|
||||
}
|
||||
if errors.Is(err, datasources.ErrDataSourceNotFound) && name != "" {
|
||||
ds, err = s.retriever.GetDataSource(ctx, &datasources.GetDataSourceQuery{
|
||||
OrgID: user.GetOrgID(),
|
||||
|
||||
Reference in New Issue
Block a user