2020-10-09 20:31:15 +00:00
|
|
|
import RepositoryService from 'consul-ui/services/repository';
|
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { env } from 'consul-ui/env';
|
|
|
|
|
|
|
|
// meta is used by DataSource to configure polling. The interval controls how
|
|
|
|
// long between each poll to the metrics provider. TODO - make this configurable
|
|
|
|
// in the UI settings.
|
|
|
|
const meta = {
|
|
|
|
interval: env('CONSUL_METRICS_POLL_INTERVAL') || 10000,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default RepositoryService.extend({
|
|
|
|
cfg: service('ui-config'),
|
2020-10-20 15:41:16 +00:00
|
|
|
error: null,
|
2020-10-09 20:31:15 +00:00
|
|
|
|
|
|
|
init: function() {
|
|
|
|
this._super(...arguments);
|
|
|
|
const uiCfg = this.cfg.get();
|
|
|
|
// Inject whether or not the proxy is enabled as an option into the opaque
|
|
|
|
// JSON options the user provided.
|
|
|
|
const opts = uiCfg.metrics_provider_options || {};
|
|
|
|
opts.metrics_proxy_enabled = uiCfg.metrics_proxy_enabled;
|
|
|
|
// Inject the base app URL
|
|
|
|
const provider = uiCfg.metrics_provider || 'prometheus';
|
2020-10-20 15:41:16 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
this.provider = window.consul.getMetricsProvider(provider, opts);
|
2020-10-21 14:23:16 +00:00
|
|
|
} catch (e) {
|
2020-10-20 15:41:16 +00:00
|
|
|
this.error = new Error(`metrics provider not initialized: ${e}`);
|
|
|
|
// Show the user the error once for debugging their provider outside UI
|
|
|
|
// Dev.
|
2020-10-21 14:23:16 +00:00
|
|
|
console.error(this.error); // eslint-disable-line no-console
|
2020-10-20 15:41:16 +00:00
|
|
|
}
|
2020-10-09 20:31:15 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
findServiceSummary: function(protocol, slug, dc, nspace, configuration = {}) {
|
2020-10-20 15:41:16 +00:00
|
|
|
if (this.error) {
|
|
|
|
return Promise.reject(this.error);
|
|
|
|
}
|
2020-10-09 20:31:15 +00:00
|
|
|
const promises = [
|
|
|
|
// TODO: support namespaces in providers
|
|
|
|
this.provider.serviceRecentSummarySeries(slug, protocol, {}),
|
|
|
|
this.provider.serviceRecentSummaryStats(slug, protocol, {}),
|
|
|
|
];
|
|
|
|
return Promise.all(promises).then(function(results) {
|
|
|
|
return {
|
|
|
|
meta: meta,
|
2020-10-20 15:41:16 +00:00
|
|
|
series: results[0],
|
2020-10-09 20:31:15 +00:00
|
|
|
stats: results[1].stats,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
findUpstreamSummary: function(slug, dc, nspace, configuration = {}) {
|
2020-10-20 15:41:16 +00:00
|
|
|
if (this.error) {
|
|
|
|
return Promise.reject(this.error);
|
|
|
|
}
|
2020-10-09 20:31:15 +00:00
|
|
|
return this.provider.upstreamRecentSummaryStats(slug, {}).then(function(result) {
|
|
|
|
result.meta = meta;
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
findDownstreamSummary: function(slug, dc, nspace, configuration = {}) {
|
2020-10-20 15:41:16 +00:00
|
|
|
if (this.error) {
|
|
|
|
return Promise.reject(this.error);
|
|
|
|
}
|
2020-10-09 20:31:15 +00:00
|
|
|
return this.provider.downstreamRecentSummaryStats(slug, {}).then(function(result) {
|
|
|
|
result.meta = meta;
|
|
|
|
return result;
|
|
|
|
});
|
2020-10-21 14:23:16 +00:00
|
|
|
},
|
2020-10-09 20:31:15 +00:00
|
|
|
});
|