Merge pull request #707 from weaveworks/282-hostname-in-api

Show hostname of app you are connected to
This commit is contained in:
David
2015-12-04 16:38:34 +01:00
7 changed files with 25 additions and 10 deletions

View File

@@ -11,6 +11,7 @@ import (
"github.com/PuerkitoBio/ghost/handlers"
"github.com/gorilla/mux"
"github.com/weaveworks/scope/common/hostname"
"github.com/weaveworks/scope/report"
"github.com/weaveworks/scope/xfer"
)
@@ -105,5 +106,9 @@ func makeReportPostHandler(a Adder) http.HandlerFunc {
}
func apiHandler(w http.ResponseWriter, r *http.Request) {
respondWith(w, http.StatusOK, xfer.Details{ID: uniqueID, Version: version})
respondWith(w, http.StatusOK, xfer.Details{
ID: uniqueID,
Version: version,
Hostname: hostname.Get(),
})
}

View File

@@ -167,6 +167,7 @@ export function receiveTopologies(topologies) {
export function receiveApiDetails(apiDetails) {
AppDispatcher.dispatch({
type: ActionTypes.RECEIVE_API_DETAILS,
hostname: apiDetails.hostname,
version: apiDetails.version
});
}

View File

@@ -25,6 +25,7 @@ function getStateFromStores() {
errorUrl: AppStore.getErrorUrl(),
highlightedEdgeIds: AppStore.getHighlightedEdgeIds(),
highlightedNodeIds: AppStore.getHighlightedNodeIds(),
hostname: AppStore.getHostname(),
selectedNodeId: AppStore.getSelectedNodeId(),
nodeDetails: AppStore.getNodeDetails(),
nodes: AppStore.getNodes(),
@@ -68,7 +69,7 @@ export default class App extends React.Component {
render() {
const showingDetails = this.state.selectedNodeId;
const versionString = this.state.version ? 'Version ' + this.state.version : '';
const footer = `Version ${this.state.version} on ${this.state.hostname}`;
// width of details panel blocking a view
const detailsWidth = showingDetails ? 450 : 0;
const topMargin = 100;
@@ -101,7 +102,7 @@ export default class App extends React.Component {
</Sidebar>
<div className="footer">
{versionString}&nbsp;&nbsp;
{footer}&nbsp;&nbsp;
<a href="https://gitreports.com/issue/weaveworks/scope" target="_blank">Report an issue</a>
</div>
</div>

View File

@@ -51,7 +51,8 @@ let controlPending = false;
let currentTopology = null;
let currentTopologyId = 'containers';
let errorUrl = null;
let version = '';
let hostname = '...';
let version = '...';
let mouseOverEdgeId = null;
let mouseOverNodeId = null;
let nodes = makeOrderedMap();
@@ -198,6 +199,10 @@ export class AppStore extends Store {
return null;
}
getHostname() {
return hostname;
}
getNodeDetails() {
return nodeDetails;
}
@@ -403,6 +408,7 @@ export class AppStore extends Store {
case ActionTypes.RECEIVE_API_DETAILS:
errorUrl = null;
hostname = payload.hostname;
version = payload.version;
this.__emitChange();
break;

View File

@@ -1,9 +1,9 @@
package probe
package hostname
import "os"
// Hostname returns the hostname of this host.
func Hostname() string {
// Get returns the hostname of this host.
func Get() string {
if hostname := os.Getenv("SCOPE_HOSTNAME"); hostname != "" {
return hostname
}

View File

@@ -16,6 +16,7 @@ import (
"github.com/armon/go-metrics"
"github.com/weaveworks/weave/common"
"github.com/weaveworks/scope/common/hostname"
"github.com/weaveworks/scope/probe"
"github.com/weaveworks/scope/probe/controls"
"github.com/weaveworks/scope/probe/docker"
@@ -78,7 +79,7 @@ func main() {
rand.Seed(time.Now().UnixNano())
probeID := strconv.FormatInt(rand.Int63(), 16)
var (
hostName = probe.Hostname()
hostName = hostname.Get()
hostID = hostName // TODO(pb): we should sanitize the hostname
)
log.Printf("probe starting, version %s, ID %s", version, probeID)

View File

@@ -15,8 +15,9 @@ import (
// Details are some generic details that can be fetched from /api
type Details struct {
ID string `json:"id"`
Version string `json:"version"`
ID string `json:"id"`
Version string `json:"version"`
Hostname string `json:"hostname"`
}
// AppClient is a client to an app for dealing with controls.