*Create Caching Config interface and OSS impl
*Create front-end facing DS Cache config *Populate Caching Config on Datasource DTO *Update OSS wire deps
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/datasources/querycaching"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/licensing"
|
||||
"github.com/grafana/grafana/pkg/services/pluginsettings"
|
||||
@@ -249,6 +250,13 @@ func (hs *HTTPServer) getFSDataSources(c *models.ReqContext, enabledPlugins Enab
|
||||
}
|
||||
}
|
||||
|
||||
// load enterprise caching config for all datasources
|
||||
cacheCfgs, err := hs.DataSourceCacheCfgService.GetAllDatasourceConfig(c.Req.Context())
|
||||
if err != nil {
|
||||
// non-fatal - log and continue
|
||||
c.Logger.Error("failed to get datasource caching config", "error", err.Error())
|
||||
cacheCfgs = querycaching.CacheConfigMap{}
|
||||
}
|
||||
dataSources := make(map[string]plugins.DataSourceDTO)
|
||||
|
||||
for _, ds := range orgDataSources {
|
||||
@@ -337,6 +345,10 @@ func (hs *HTTPServer) getFSDataSources(c *models.ReqContext, enabledPlugins Enab
|
||||
ds.JsonData.Set("directUrl", ds.Url)
|
||||
}
|
||||
|
||||
if cfg, ok := cacheCfgs[dsDTO.UID]; ok {
|
||||
dsDTO.EnterpriseCachingConfig = cfg
|
||||
}
|
||||
|
||||
dataSources[ds.Name] = dsDTO
|
||||
}
|
||||
|
||||
@@ -359,6 +371,11 @@ func (hs *HTTPServer) getFSDataSources(c *models.ReqContext, enabledPlugins Enab
|
||||
dto.ID = grafanads.DatasourceID
|
||||
dto.UID = grafanads.DatasourceUID
|
||||
}
|
||||
|
||||
if cfg, ok := cacheCfgs[dto.UID]; ok {
|
||||
dto.EnterpriseCachingConfig = cfg
|
||||
}
|
||||
|
||||
dataSources[ds.Name] = dto
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/datasourceproxy"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/datasources/permissions"
|
||||
"github.com/grafana/grafana/pkg/services/datasources/querycaching"
|
||||
"github.com/grafana/grafana/pkg/services/encryption"
|
||||
"github.com/grafana/grafana/pkg/services/export"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
@@ -167,6 +168,7 @@ type HTTPServer struct {
|
||||
secretsMigrator secrets.Migrator
|
||||
secretsPluginMigrator spm.SecretMigrationProvider
|
||||
DataSourcesService datasources.DataSourceService
|
||||
DataSourceCacheCfgService querycaching.DatasourceCacheConfig
|
||||
cleanUpService *cleanup.CleanUpService
|
||||
tracer tracing.Tracer
|
||||
grafanaUpdateChecker *updatechecker.GrafanaService
|
||||
@@ -255,7 +257,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
|
||||
accesscontrolService accesscontrol.Service, dashboardThumbsService thumbs.DashboardThumbService, navTreeService navtree.Service,
|
||||
annotationRepo annotations.Repository, tagService tag.Service, searchv2HTTPService searchV2.SearchHTTPService,
|
||||
queryLibraryHTTPService querylibrary.HTTPService, queryLibraryService querylibrary.Service, oauthTokenService oauthtoken.OAuthTokenService,
|
||||
statsService stats.Service, authnService authn.Service,
|
||||
statsService stats.Service, authnService authn.Service, dataSourceCacheCfgService querycaching.DatasourceCacheConfig,
|
||||
k8saccess k8saccess.K8SAccess, // required so that the router is registered
|
||||
) (*HTTPServer, error) {
|
||||
web.Env = cfg.Env
|
||||
@@ -319,6 +321,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi
|
||||
secretsStore: secretsStore,
|
||||
httpEntityStore: httpEntityStore,
|
||||
DataSourcesService: dataSourcesService,
|
||||
DataSourceCacheCfgService: dataSourceCacheCfgService,
|
||||
searchUsersService: searchUsersService,
|
||||
ldapGroups: ldapGroups,
|
||||
teamGuardian: teamGuardian,
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/datasources/querycaching"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
)
|
||||
|
||||
@@ -226,6 +227,8 @@ type DataSourceDTO struct {
|
||||
BasicAuth string `json:"basicAuth,omitempty"`
|
||||
WithCredentials bool `json:"withCredentials,omitempty"`
|
||||
|
||||
EnterpriseCachingConfig querycaching.CacheConfig `json:"cachingConfig,omitempty"`
|
||||
|
||||
// InfluxDB
|
||||
Username string `json:"username,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/services/auth/authimpl"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/datasources/permissions"
|
||||
querycaching "github.com/grafana/grafana/pkg/services/datasources/querycaching"
|
||||
datasourceservice "github.com/grafana/grafana/pkg/services/datasources/service"
|
||||
"github.com/grafana/grafana/pkg/services/encryption"
|
||||
encryptionprovider "github.com/grafana/grafana/pkg/services/encryption/provider"
|
||||
@@ -81,6 +82,8 @@ var wireExtsBasicSet = wire.NewSet(
|
||||
ossaccesscontrol.ProvideDatasourcePermissionsService,
|
||||
wire.Bind(new(accesscontrol.DatasourcePermissionsService), new(*ossaccesscontrol.DatasourcePermissionsService)),
|
||||
pluginsintegration.WireExtensionSet,
|
||||
querycaching.ProvideService,
|
||||
wire.Bind(new(querycaching.DatasourceCacheConfig), new(*querycaching.OSSDatasourceCacheConfigImpl)),
|
||||
)
|
||||
|
||||
var wireExtsSet = wire.NewSet(
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package querycaching
|
||||
|
||||
import "context"
|
||||
|
||||
type DatasourceCacheConfig interface {
|
||||
GetAllDatasourceConfig(ctx context.Context) (CacheConfigMap, error)
|
||||
}
|
||||
|
||||
// Map of datasource UIDs to cache configs
|
||||
type CacheConfigMap map[string]CacheConfig
|
||||
|
||||
type CacheConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
TTLMS int64 `json:"ttl_ms"`
|
||||
UseDefaultTTL bool `json:"default_ttl"`
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package querycaching
|
||||
|
||||
import "context"
|
||||
|
||||
func ProvideService() *OSSDatasourceCacheConfigImpl {
|
||||
return &OSSDatasourceCacheConfigImpl{}
|
||||
}
|
||||
|
||||
type OSSDatasourceCacheConfigImpl struct {
|
||||
}
|
||||
|
||||
func (c *OSSDatasourceCacheConfigImpl) GetAllDatasourceConfig(ctx context.Context) (CacheConfigMap, error) {
|
||||
return CacheConfigMap{}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user