mirror of https://github.com/linkerd/linkerd2.git
93 lines
2.4 KiB
JavaScript
93 lines
2.4 KiB
JavaScript
import _ from 'lodash';
|
|
import ConduitSpinner from "./ConduitSpinner.jsx";
|
|
import ErrorBanner from './ErrorBanner.jsx';
|
|
import MetricsTable from './MetricsTable.jsx';
|
|
import PageHeader from './PageHeader.jsx';
|
|
import { processRollupMetrics } from './util/MetricUtils.js';
|
|
import React from 'react';
|
|
import './../../css/list.css';
|
|
import 'whatwg-fetch';
|
|
|
|
export default class PodsList extends React.Component {
|
|
constructor(props) {
|
|
super(props);
|
|
this.api = this.props.api;
|
|
this.handleApiError = this.handleApiError.bind(this);
|
|
this.loadFromServer = this.loadFromServer.bind(this);
|
|
|
|
this.state = {
|
|
pollingInterval: 2000, // TODO: poll based on metricsWindow size
|
|
metrics: [],
|
|
pendingRequests: false,
|
|
loaded: false,
|
|
error: ''
|
|
};
|
|
}
|
|
|
|
componentDidMount() {
|
|
this.loadFromServer();
|
|
this.timerId = window.setInterval(this.loadFromServer, this.state.pollingInterval);
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
window.clearInterval(this.timerId);
|
|
this.api.cancelCurrentRequests();
|
|
}
|
|
|
|
loadFromServer() {
|
|
if (this.state.pendingRequests) {
|
|
return; // don't make more requests if the ones we sent haven't completed
|
|
}
|
|
this.setState({ pendingRequests: true });
|
|
|
|
this.api.setCurrentRequests([
|
|
this.api.fetchMetrics(this.api.urlsForResource["pod"].url().rollup)
|
|
]);
|
|
|
|
Promise.all(this.api.getCurrentPromises())
|
|
.then(([rollup]) => {
|
|
let processedMetrics = processRollupMetrics(rollup);
|
|
|
|
this.setState({
|
|
metrics: processedMetrics,
|
|
loaded: true,
|
|
pendingRequests: false,
|
|
error: ''
|
|
});
|
|
})
|
|
.catch(this.handleApiError);
|
|
}
|
|
|
|
handleApiError(e) {
|
|
if (e.isCanceled) {
|
|
return;
|
|
}
|
|
|
|
this.setState({
|
|
pendingRequests: false,
|
|
error: `Error getting data from server: ${e.message}`
|
|
});
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<div className="page-content">
|
|
{ !this.state.error ? null : <ErrorBanner message={this.state.error} /> }
|
|
{ !this.state.loaded ? <ConduitSpinner /> :
|
|
<div>
|
|
<PageHeader header="Pods" api={this.api} />
|
|
{ _.isEmpty(this.state.metrics) ?
|
|
<div>No pods found</div> :
|
|
<div className="pods-list">
|
|
<MetricsTable
|
|
resource="pod"
|
|
metrics={this.state.metrics}
|
|
api={this.api} />
|
|
</div>
|
|
}
|
|
</div>
|
|
}
|
|
</div>);
|
|
}
|
|
}
|