-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Frontend: Detect new assets / versions / config changes #79258
Frontend: Detect new assets / versions / config changes #79258
Conversation
@@ -104,7 +105,7 @@ func function(pc uintptr) []byte { | |||
|
|||
// Recovery returns a middleware that recovers from any panics and writes a 500 if there was one. | |||
// While Martini is in development mode, Recovery will also output the panic as HTML. | |||
func Recovery(cfg *setting.Cfg) web.Middleware { | |||
func Recovery(cfg *setting.Cfg, license licensing.Licensing) web.Middleware { |
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.
How's this change related?
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.
Ok, nvm, I see it's required to get the corect 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.
Right -- but with this approach, I hope we can remove that link. It will be less "safe" because the CDN will not necessarily be the same version, but has more control so the frontend could be ahead of the backend
@@ -25,6 +25,53 @@ import ( | |||
"github.com/grafana/grafana/pkg/util" | |||
) | |||
|
|||
// Returns a file that is easy to check for changes | |||
// Any changes to the file means we should refresh the frontend |
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.
how do we make sure it doesn't result in a endless refresh loop if there are issues? Can we limit the amount of refreshes?
const resultRaw = await getBackendSrv().get('/api/frontend/assets'); | ||
const result = JSON.stringify(resultRaw); | ||
if (this.checked && this.previous !== result) { | ||
this.hasUpdates = true; | ||
console.log('updates detected', true); |
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.
nit: console.debug
maybe?
} | ||
|
||
public reloadIfUpdateDetected() { | ||
if (this._hasUpdates) { | ||
if (this.hasUpdates) { | ||
window.location.reload(); |
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.
didn't we want to do it during next navigation events? Otherwise it will just refresh in the middle of someone editing a dashboard.
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.
@tolzhabayev this function is only called when moving to another page
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.
got it, thanks for clarifying.
export class NewFrontendAssetsChecker { | ||
private _hasUpdates = false; | ||
private hasUpdates = false; | ||
private previous = '?'; |
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.
this would mean every grafana instance will have to refresh at least once to fill out the previous
state? So basically as soon as you open grafana and navigate for the "first time" (browser session) it will always refresh for everyone?
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 actual logic makes sure previous has been called before, many ways to slice it, but ths avoids the case you are talking about
if (this.checked && this.previous !== result) {
torkels original version (the PR this is targeting) saves the original values directly in the bootdata -- but I'm not sure we need/want that. This has the downside that the first navigation will never find a change, only the second
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.
Took this for a spin today, looks good!
PR targets #79057
This PR: