New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CDN: Adds support for serving assets over a CDN #30691
Conversation
public/app/index.ts
Outdated
@@ -1,4 +1,6 @@ | |||
import app from './app'; | |||
declare let __webpack_public_path__: string; | |||
__webpack_public_path__ = window.public_cdn_path; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this is the key part of telling webpack where to load files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without this all the dynamic webpack chunks are loaded from localhost
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the code looks ok, but I'm not very familiar with all the details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome 👍
Other things to consider referencing CDN might be email templates for example.
Another thing to take into consideration would be to not having to update the CDN path config each time you upgrade Grafana - I guess this partly will be solved by the build hashes, but thinking about 10 Grafana releases would currently require 10x all the files with hashes in the same CDN folder, unless CDN path config is not changed on upgrade. Maybe would make sense to always enforce/include version number/commit in the CDN path?
pkg/setting/setting.go
Outdated
@@ -1297,6 +1298,7 @@ func readServerSettings(iniFile *ini.File, cfg *Cfg) error { | |||
return err | |||
} | |||
|
|||
cfg.CDNPath = valueAsString(server, "cdn_path", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marefr think here we should probably add Grafana version string to the path (so v7.4.0-beta1) for example. (or in index.go) so that on the cdn each published release is under different paths , the config path you set in the ini file is just the root cdn path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using a hash would work with master builds and pre-releases as well. That would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So maybe both version and hash then? Or only using hash for pre-releases and version for stable ones, not sure how hard that would be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The asset files are already hashed, this should just add version folder. Master builds already build a number of some sort I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, makes sense
@bergquist @marefr added edition & and BuildVersion to the url as well so paths becomes https://cdn.grafana.com/oss/v7.5.0-11124pre if the cdn_path is set to https://cdn.grafana.com depending on what verison & edition grafana is |
Added one final thing, also segrate master builds into a separate path for easier clean-up. So it will be
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. This is great 👍 Spotted some minor problems, see comments. .ini files and documentation needs update as well
@marefr pushed changes, added error handling in the read config stage (of the url parsing), changed the property name from cdn_path to cd_url as it's a url not just path. Added docs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some copy-edit suggestions for the doc content.
Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>
Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the suggestion to fix a typo that got missed earlier.
|
||
Specify a full HTTP URL address to the root of your Grafana CDN assets. Grafana will add edition and version paths. | ||
|
||
For example, given a cdn url like `https://cdn.myserver.com` grafana will try to load a javascript file from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, given a cdn url like `https://cdn.myserver.com` grafana will try to load a javascript file from | |
For example, given a CDN URL like `https://cdn.myserver.com` grafana will try to load a javascript file from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* 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> (cherry picked from commit c04bc80)
* 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> (cherry picked from commit c04bc80) Co-authored-by: Torkel Ödegaard <torkel@grafana.org>
Closes #6844
Adds option to load js & css from cdn path. Tested by starting a local nginx with a custom hostname and copying everything under public to it.
This does not currently impact loading plugins, they are still loaded from instance.
It does impact the content_security_policy, if enabled it needs to be modified allow the cdn. Not sure how exactly.
TODO