Skip to content

Commit

Permalink
Merge pull request #1126 from weaveworks/plugins
Browse files Browse the repository at this point in the history
Plugins
  • Loading branch information
paulbellamy committed Apr 12, 2016
2 parents 6158cbe + 3865e0f commit f211d48
Show file tree
Hide file tree
Showing 65 changed files with 3,568 additions and 626 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ tags

# Project specific
.*.uptodate
.uptodate
scope.tar
.pkg
prog/scope
Expand Down
4 changes: 2 additions & 2 deletions app/api_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func handleTopology(ctx context.Context, rep Reporter, renderer render.Renderer,
return
}
respondWith(w, http.StatusOK, APITopology{
Nodes: detailed.Summaries(renderer.Render(report)),
Nodes: detailed.Summaries(report, renderer.Render(report)),
})
}

Expand Down Expand Up @@ -119,7 +119,7 @@ func handleWebsocket(
log.Errorf("Error generating report: %v", err)
return
}
newTopo := detailed.Summaries(renderer.Render(report))
newTopo := detailed.Summaries(report, renderer.Render(report))
diff := detailed.TopoDiff(previousTopo, newTopo)
previousTopo = newTopo

Expand Down
21 changes: 14 additions & 7 deletions app/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func gzipHandler(h http.HandlerFunc) http.HandlerFunc {
func RegisterTopologyRoutes(router *mux.Router, r Reporter) {
get := router.Methods("GET").Subrouter()
get.HandleFunc("/api",
gzipHandler(requestContextDecorator(apiHandler)))
gzipHandler(requestContextDecorator(apiHandler(r))))
get.HandleFunc("/api/topology",
gzipHandler(requestContextDecorator(topologyRegistry.makeTopologyList(r))))
get.HandleFunc("/api/topology/{topology}",
Expand Down Expand Up @@ -132,10 +132,17 @@ func RegisterReportPostHandler(a Adder, router *mux.Router) {
}))
}

func apiHandler(_ context.Context, w http.ResponseWriter, r *http.Request) {
respondWith(w, http.StatusOK, xfer.Details{
ID: UniqueID,
Version: Version,
Hostname: hostname.Get(),
})
func apiHandler(rep Reporter) CtxHandlerFunc {
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
report, err := rep.Report(ctx)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
respondWith(w, http.StatusOK, xfer.Details{
ID: UniqueID,
Version: Version,
Hostname: hostname.Get(),
Plugins: report.Plugins,
})
}
}
3 changes: 2 additions & 1 deletion client/app/scripts/actions/app-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ export function receiveApiDetails(apiDetails) {
AppDispatcher.dispatch({
type: ActionTypes.RECEIVE_API_DETAILS,
hostname: apiDetails.hostname,
version: apiDetails.version
version: apiDetails.version,
plugins: apiDetails.plugins
});
}

Expand Down
1 change: 1 addition & 0 deletions client/app/scripts/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function getStateFromStores() {
updatePaused: AppStore.isUpdatePaused(),
updatePausedAt: AppStore.getUpdatePausedAt(),
version: AppStore.getVersion(),
plugins: AppStore.getPlugins(),
websocketClosed: AppStore.isWebsocketClosed()
};
}
Expand Down
7 changes: 6 additions & 1 deletion client/app/scripts/components/footer.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React from 'react';
import moment from 'moment';

import Plugins from './plugins.js';
import { getUpdateBufferSize } from '../utils/update-buffer-utils';
import { contrastModeUrl, isContrastMode } from '../utils/contrast-utils';
import { clickDownloadGraph, clickForceRelayout, clickPauseUpdate,
clickResumeUpdate, toggleHelp } from '../actions/app-actions';
import { basePathSlash } from '../utils/web-api-utils';

export default function Footer(props) {
const { hostname, updatePaused, updatePausedAt, version } = props;
const { hostname, plugins, updatePaused, updatePausedAt, version } = props;
const contrastMode = isContrastMode();

// link url to switch contrast with current UI state
Expand Down Expand Up @@ -47,6 +48,10 @@ export default function Footer(props) {
{hostname}
</div>

<div className="footer-plugins">
<Plugins plugins={plugins} />
</div>

<div className="footer-tools">
<a className={pauseClassName} onClick={pauseAction} title={pauseTitle}>
{pauseLabel !== '' && <span className="footer-label">{pauseLabel}</span>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class NodeDetailsInfo extends React.Component {

render() {
let rows = (this.props.rows || []);
const prime = rows.filter(row => row.prime);
const prime = rows.filter(row => row.priority < 10);
let notShown = 0;
if (!this.state.expanded && prime.length < rows.length) {
notShown = rows.length - prime.length;
Expand Down
24 changes: 24 additions & 0 deletions client/app/scripts/components/plugins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';

export default class Plugins extends React.Component {
renderPlugin(plugin) {
return (
<span className="plugins-plugin" key={plugin.id} title={plugin.description}>
{plugin.label || plugin.id}
</span>
);
}

render() {
const hasPlugins = this.props.plugins && this.props.plugins.length > 0;
return (
<div className="plugins">
<span className="plugins-label">
Plugins:
</span>
{hasPlugins && this.props.plugins.map((plugin, index) => this.renderPlugin(plugin, index))}
{!hasPlugins && <span className="plugins-empty">n/a</span>}
</div>
);
}
}
7 changes: 7 additions & 0 deletions client/app/scripts/stores/app-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ let highlightedEdgeIds = makeSet();
let highlightedNodeIds = makeSet();
let hostname = '...';
let version = '...';
let plugins = null;
let mouseOverEdgeId = null;
let mouseOverNodeId = null;
let nodeDetails = makeOrderedMap(); // nodeId -> details
Expand Down Expand Up @@ -275,6 +276,11 @@ export class AppStore extends Store {
return version;
}

getPlugins() {
return plugins;
}


isForceRelayout() {
return forceRelayout;
}
Expand Down Expand Up @@ -679,6 +685,7 @@ export class AppStore extends Store {
errorUrl = null;
hostname = payload.hostname;
version = payload.version;
plugins = payload.plugins;
this.__emitChange();
break;
}
Expand Down
17 changes: 17 additions & 0 deletions client/app/styles/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,23 @@ h2 {
}
}

.plugins {
margin-right: 0.5em;

&-label {
text-transform: uppercase;
margin-right: 0.25em;
}

&-plugin + &-plugin:before {
content: ', ';
}

&-empty {
opacity: @text-secondary-color;
}
}

.status {
text-transform: uppercase;
padding: 2px 12px;
Expand Down
5 changes: 5 additions & 0 deletions common/backoff/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Interface interface {
Start()
Stop()
SetInitialBackoff(time.Duration)
SetMaxBackoff(time.Duration)
}

// New makes a new Interface
Expand All @@ -40,6 +41,10 @@ func (b *backoff) SetInitialBackoff(d time.Duration) {
b.initialBackoff = d
}

func (b *backoff) SetMaxBackoff(d time.Duration) {
b.maxBackoff = d
}

// Stop the backoff, and waits for it to stop.
func (b *backoff) Stop() {
close(b.quit)
Expand Down
7 changes: 4 additions & 3 deletions common/xfer/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const (

// Details are some generic details that can be fetched from /api
type Details struct {
ID string `json:"id"`
Version string `json:"version"`
Hostname string `json:"hostname"`
ID string `json:"id"`
Version string `json:"version"`
Hostname string `json:"hostname"`
Plugins PluginSpecs `json:"plugins,omitempty"`
}
Loading

0 comments on commit f211d48

Please sign in to comment.