Merge pull request #5862 from influxdata/tp-fix-dynamic-admin-versioning

Get client version dynamically
pull/5936/head
Gunnar 2016-03-07 19:33:44 -08:00
commit 0d374ecca7
7 changed files with 35 additions and 13 deletions

View File

@ -20,6 +20,7 @@
- [#5758](https://github.com/influxdata/influxdb/pull/5758): TSM engine stats for cache, WAL, and filestore. Thanks @jonseymour
- [#5844](https://github.com/influxdata/influxdb/pull/5844): Tag TSM engine stats with database and retention policy
- [#5593](https://github.com/influxdata/influxdb/issues/5593): Modify `SHOW TAG VALUES` output for the new query engine to normalize the output.
- [#5862](https://github.com/influxdata/influxdb/pull/5862): Make Admin UI dynamically fetch both client and server versions
### Bugfixes

View File

@ -279,6 +279,7 @@ func (s *Server) appendAdminService(c admin.Config) {
if !c.Enabled {
return
}
c.Version = s.buildInfo.Version
srv := admin.NewService(c)
s.Services = append(s.Services, srv)
}

View File

@ -165,7 +165,7 @@
<!-- /.container -->
<div id="footer">
<div class="container">
<p class="text-muted text-right credit"><b>InfluxDB</b> v0.10.0<span class="influxdb-version"></span></p>
<p class="text-muted text-right credit"><b>InfluxDB</b> Admin UI: <span class="influxdb-client-version"></span> Server: <span class="influxdb-version"></span></p>
</div>
</div>

View File

@ -47,6 +47,7 @@ var loadSettings = function() {
document.getElementById('password').value = connectionSettings.password;
document.getElementById('ssl').checked = connectionSettings.ssl;
getClientVersion();
getDatabases();
}
@ -343,14 +344,17 @@ var pretty = function(val) {
}
}
var getVersion = function () {
var query = $.get(connectionString() + "/ping");
var getClientVersion = function () {
var query = $.get(window.location.origin + "/");
query.fail(handleRequestError);
query.done(function (data, status, xhr) {
var version = xhr.getResponseHeader('X-InfluxDB-Version');
$('.influxdb-version').html(' (Server v'+version+')');
if (version.indexOf("unknown") == -1) {
version = 'v' + version;
}
$('.influxdb-client-version').html(version);
});
}
@ -365,7 +369,14 @@ var getDatabases = function () {
query.fail(handleRequestError);
query.done(function (data) {
query.done(function (data, status, xhr) {
// Set version of the InfluxDB server
var version = xhr.getResponseHeader('X-InfluxDB-Version');
if (version.indexOf("unknown") == -1) {
version = "v" + version;
}
$('.influxdb-version').html(version);
hideSettings();
hideDatabaseWarning();
@ -415,7 +426,6 @@ var updateDatabaseList = function() {
// when the page is ready, start everything up
$(document).ready(function () {
loadSettings();
getVersion();
// bind to the settings cog in the navbar
$("#action-settings").click(function (e) {

View File

@ -11,6 +11,7 @@ type Config struct {
BindAddress string `toml:"bind-address"`
HTTPSEnabled bool `toml:"https-enabled"`
HTTPSCertificate string `toml:"https-certificate"`
Version string
}
// NewConfig returns an instance of Config with defaults.

View File

@ -21,6 +21,7 @@ type Service struct {
https bool
cert string
err chan error
version string
logger *log.Logger
}
@ -28,11 +29,12 @@ type Service struct {
// NewService returns a new instance of Service.
func NewService(c Config) *Service {
return &Service{
addr: c.BindAddress,
https: c.HTTPSEnabled,
cert: c.HTTPSCertificate,
err: make(chan error),
logger: log.New(os.Stderr, "[admin] ", log.LstdFlags),
addr: c.BindAddress,
https: c.HTTPSEnabled,
cert: c.HTTPSCertificate,
err: make(chan error),
version: c.Version,
logger: log.New(os.Stderr, "[admin] ", log.LstdFlags),
}
}
@ -97,6 +99,13 @@ func (s *Service) Addr() net.Addr {
// serve serves the handler from the listener.
func (s *Service) serve() {
addVersionHeaderThenServe := func(h http.Handler) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("X-InfluxDB-Version", s.version)
h.ServeHTTP(w, r)
}
}
// Instantiate file system from embedded admin.
statikFS, err := fs.New()
if err != nil {
@ -104,7 +113,7 @@ func (s *Service) serve() {
}
// Run file system handler on listener.
err = http.Serve(s.listener, http.FileServer(statikFS))
err = http.Serve(s.listener, addVersionHeaderThenServe(http.FileServer(statikFS)))
if err != nil && !strings.Contains(err.Error(), "closed") {
s.err <- fmt.Errorf("listener error: addr=%s, err=%s", s.Addr(), err)
}

File diff suppressed because one or more lines are too long