mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 06:42:13 +08:00
CDN: Adds support for serving assets over a CDN (#30691)
* CDN: Initial poc support for serving assets over a CDN * Minor fix * added build path and test * fix lint error * Added edition to cdn path * Move master builds to a separate path * Added error handling for the url parsing, changed setting name, and added docs * Updated sample.ini * Some property renames * updated * Minor update to html * index template improvements * Update docs/sources/administration/configuration.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/administration/configuration.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Added ContentDeliveryPrefix to Licence service * updated docs * Updated test mock Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>
This commit is contained in:
@ -197,6 +197,7 @@ type Cfg struct {
|
||||
SocketPath string
|
||||
RouterLogging bool
|
||||
Domain string
|
||||
CDNRootURL *url.URL
|
||||
|
||||
// build
|
||||
BuildVersion string
|
||||
@ -767,7 +768,7 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
|
||||
provisioning := valueAsString(iniFile.Section("paths"), "provisioning", "")
|
||||
cfg.ProvisioningPath = makeAbsolute(provisioning, HomePath)
|
||||
|
||||
if err := readServerSettings(iniFile, cfg); err != nil {
|
||||
if err := cfg.readServerSettings(iniFile); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -1251,7 +1252,7 @@ func readSnapshotsSettings(cfg *Cfg, iniFile *ini.File) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func readServerSettings(iniFile *ini.File, cfg *Cfg) error {
|
||||
func (cfg *Cfg) readServerSettings(iniFile *ini.File) error {
|
||||
server := iniFile.Section("server")
|
||||
var err error
|
||||
AppUrl, AppSubUrl, err = parseAppUrlAndSubUrl(server)
|
||||
@ -1263,8 +1264,8 @@ func readServerSettings(iniFile *ini.File, cfg *Cfg) error {
|
||||
cfg.AppURL = AppUrl
|
||||
cfg.AppSubURL = AppSubUrl
|
||||
cfg.ServeFromSubPath = ServeFromSubPath
|
||||
|
||||
cfg.Protocol = HTTPScheme
|
||||
|
||||
protocolStr := valueAsString(server, "protocol", "http")
|
||||
|
||||
if protocolStr == "https" {
|
||||
@ -1297,9 +1298,34 @@ func readServerSettings(iniFile *ini.File, cfg *Cfg) error {
|
||||
return err
|
||||
}
|
||||
|
||||
cdnURL := valueAsString(server, "cdn_url", "")
|
||||
if cdnURL != "" {
|
||||
cfg.CDNRootURL, err = url.Parse(cdnURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetContentDeliveryURL returns full content delivery URL with /<edition>/<version> added to URL
|
||||
func (cfg *Cfg) GetContentDeliveryURL(prefix string) string {
|
||||
if cfg.CDNRootURL != nil {
|
||||
url := *cfg.CDNRootURL
|
||||
preReleaseFolder := ""
|
||||
|
||||
if strings.Contains(cfg.BuildVersion, "pre") || strings.Contains(cfg.BuildVersion, "alpha") {
|
||||
preReleaseFolder = "pre-releases"
|
||||
}
|
||||
|
||||
url.Path = path.Join(url.Path, prefix, preReleaseFolder, cfg.BuildVersion)
|
||||
return url.String()
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func (cfg *Cfg) readDataSourcesSettings() {
|
||||
datasources := cfg.Raw.Section("datasources")
|
||||
cfg.DataSourceLimit = datasources.Key("datasource_limit").MustInt(5000)
|
||||
|
Reference in New Issue
Block a user