Skip to content

Commit

Permalink
Add error handler for missing prometheus backend
Browse files Browse the repository at this point in the history
  • Loading branch information
davkal committed Nov 6, 2017
1 parent 260f134 commit a85b2ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import Usage from './Usage';
// import METRICS from './data/metrics';

class App extends Component {
handleRequestError({ error, url }) {
alert(`Error connecting to Promtheus. Make sure it is running and reachable under ${url} via your configured proxy.`);
console.error(error);
}
render() {
return (
<div className="App pr4 pl4 pt3 pb4">
<Usage classNames="p4" />
<Usage classNames="p4" onRequestError={this.handleRequestError} />
</div>
);
}
Expand Down
10 changes: 9 additions & 1 deletion src/Usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class Usage extends Component {
const jetzt = Date.now();

// Getting all metric names
this.request('/api/v1/label/__name__/values')
const url = '/api/v1/label/__name__/values';
this.request(url)
.then(body => body.json())
.then(res => {
metricNames = res.data;
Expand Down Expand Up @@ -97,6 +98,13 @@ class Usage extends Component {
const latency = Date.now() - jetzt;
this.setState({ loading: false, latency });
});
})
.catch(error => {
if (this.props.onRequestError) {
this.props.onRequestError({ error, url });
} else {
throw error;
}
});
}

Expand Down

0 comments on commit a85b2ff

Please sign in to comment.