Skip to content

Add version check to Grafana dashboard#1638

Merged
siggy merged 3 commits intomasterfrom
siggy/grafana-version-check
Sep 13, 2018
Merged

Add version check to Grafana dashboard#1638
siggy merged 3 commits intomasterfrom
siggy/grafana-version-check

Conversation

@siggy
Copy link
Member

@siggy siggy commented Sep 13, 2018

The web dashboard checks the local Linkerd version against the latest
release, and informs the user if an update is available. Grafana was not
doing this.

Modify the Grafana dashboard to perform a version check, and prompt the
user to update if needed.

Fixes #1607

Signed-off-by: Andrew Seigner [email protected]

Open question: Do we want this on the top-line dashboard, or on every Grafana dashboard?

screen shot 2018-09-13 at 9 36 44 am

screen shot 2018-09-13 at 9 37 06 am

Since the code change is embedded in a single line in the Grafana dashboard, I'll include it here also for easier review:

<div>
  <div style="position: absolute; top: 0, left: 0">
    <a href="https://linkerd.io" target="_blank"><img src="https://linkerd.io/images/identity/svg/linkerd_primary_color_white.svg" style="height: 30px;"></a>
  </div>
  <div id="version" style="position: absolute; top: 0; right: 0; font-size: 15px">
  </div>
</div>
<script type="text/javascript">
var localReqURL =
  window.location.href.substring(
    0,
    window.location.href.indexOf(
    "/services/grafana:http/proxy/"
    )
  )+'/services/web:http/proxy/overview';

fetch(localReqURL, {
  credentials: 'include',
  headers: {
    "Content-Type": "text/html; charset=utf-8",
  },
})
.then(response => response.text())
.then(text => (new window.DOMParser()).parseFromString(text, "text/html"))
.then(html => {
  var main = html.getElementById('main');
  var localVersion = main.getAttribute("data-release-version");
  var uuid = main.getAttribute("data-uuid");

  var versionElem = document.getElementById('version');
  versionElem.innerHTML += 'Running Linkerd ' + localVersion + '.<br>';

  fetch('https://versioncheck.linkerd.io/version.json?version='+localVersion+'&uuid='+uuid+'&source=grafana', {
    credentials: 'include',
    headers: {
      "Content-Type": "application/json; charset=utf-8",
    },
  })
  .then(response => response.json())
  .then(json => {
    if (json.version === localVersion) {
      versionElem.innerHTML += 'Linkerd is up to date.';
    } else {
      versionElem.innerHTML += "A new version ("+json.version+") is available. <a href='https://versioncheck.linkerd.io/update' target='_blank'>Update now</a>.";
    }
  });
});
</script>

@siggy siggy added the area/web label Sep 13, 2018
@siggy siggy self-assigned this Sep 13, 2018
@siggy siggy requested a review from grampelberg September 13, 2018 01:18
@siggy siggy force-pushed the siggy/grafana-version-check branch from 41da225 to 691610e Compare September 13, 2018 01:18
@wmorgan
Copy link
Member

wmorgan commented Sep 13, 2018

I think we should remove the "Linkerd is a ..." text entirely, and have it read purely "Running Linkerd vx.x.x. Linkerd is up to date."

(Don't forget the trailing period!)

@siggy
Copy link
Member Author

siggy commented Sep 13, 2018

@wmorgan we don't use trailing periods on the web dashboard... shall I make them consistent? which way?
screen shot 2018-09-13 at 9 33 03 am

@wmorgan
Copy link
Member

wmorgan commented Sep 13, 2018

Since we have multiple sentences at this point, my preference is to add trailing periods and make everything a real sentence, just like how you have the original screenshot in this PR.

@grampelberg
Copy link
Contributor

@siggy could you change from XMLHttpRequest to fetch and add { credentials: 'include' } as options?

You'll want to switch over to promises as well as part of that:

fetch(localReqURL, { credentials: 'include' })
  .then()

The web dashboard checks the local Linkerd version against the latest
release, and informs the user if an update is available. Grafana was not
doing this.

Modify the Grafana dashboard to perform a version check, and prompt the
user to update if needed.

Fixes #1607

Signed-off-by: Andrew Seigner <[email protected]>
@siggy siggy force-pushed the siggy/grafana-version-check branch from 195d9e2 to 716c66b Compare September 13, 2018 17:50
Copy link
Contributor

@grampelberg grampelberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have as a footer on every page. Otherwise, working great!

Copy link

@rmars rmars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌟 lgtm!

Note that you could use more of the arrow functions in your code instead of function (right now you have a mixture of both styles), e.g.
.then(function(json) { could be .then(json => {
and .then(function(html) { could be .then(html => {

@siggy siggy merged commit b708378 into master Sep 13, 2018
@siggy siggy deleted the siggy/grafana-version-check branch September 13, 2018 22:28
zachalbert added a commit to zachalbert/linkerd2 that referenced this pull request Sep 15, 2018
* master:
  Move more info from the tap table into the expanded row (linkerd#1641)
  `linkerd check` sends params on version check (linkerd#1642)
  Bikeshed the tap and top icons (linkerd#1637)
  Add link to tap each row in top table (linkerd#1643)
  Bump default check retry time to 5 minutes (linkerd#1645)
  Make wait=true a default option for check and dashboard (linkerd#1640)
  Add version check to Grafana dashboard (linkerd#1638)
  Add data plane check for metrics Prometheus (linkerd#1635)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants