2020-11-09 17:29:12 +00:00
|
|
|
import Model, { attr, belongsTo } from '@ember-data/model';
|
2020-12-07 09:14:30 +00:00
|
|
|
import { fragmentArray } from 'ember-data-model-fragments/attributes';
|
2021-01-29 15:57:47 +00:00
|
|
|
import { computed, get } from '@ember/object';
|
2020-09-01 18:13:11 +00:00
|
|
|
import { or, filter, alias } from '@ember/object/computed';
|
2020-12-14 14:25:33 +00:00
|
|
|
import { tracked } from '@glimmer/tracking';
|
2021-01-29 15:57:47 +00:00
|
|
|
import mergeChecks from 'consul-ui/utils/merge-checks';
|
2020-08-26 14:24:30 +00:00
|
|
|
|
|
|
|
export const PRIMARY_KEY = 'uid';
|
|
|
|
export const SLUG_KEY = 'Node.Node,Service.ID';
|
|
|
|
|
2020-12-14 14:25:33 +00:00
|
|
|
export const Collection = class Collection {
|
|
|
|
@tracked items;
|
|
|
|
|
|
|
|
constructor(items) {
|
|
|
|
this.items = items;
|
|
|
|
}
|
|
|
|
|
|
|
|
get ExternalSources() {
|
|
|
|
const sources = this.items.reduce(function(prev, item) {
|
|
|
|
return prev.concat(item.ExternalSources || []);
|
|
|
|
}, []);
|
|
|
|
// unique, non-empty values, alpha sort
|
|
|
|
return [...new Set(sources)].filter(Boolean).sort();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-11-09 17:29:12 +00:00
|
|
|
export default class ServiceInstance extends Model {
|
|
|
|
@attr('string') uid;
|
|
|
|
|
|
|
|
@attr('string') Datacenter;
|
2020-08-26 14:24:30 +00:00
|
|
|
// ProxyInstance is the ember-data model relationship
|
2020-11-09 17:29:12 +00:00
|
|
|
@belongsTo('Proxy') ProxyInstance;
|
2020-08-26 14:24:30 +00:00
|
|
|
// Proxy is the actual JSON api response
|
2020-11-09 17:29:12 +00:00
|
|
|
@attr() Proxy;
|
|
|
|
@attr() Node;
|
|
|
|
@attr() Service;
|
2020-12-07 09:14:30 +00:00
|
|
|
@fragmentArray('health-check') Checks;
|
2020-11-09 17:29:12 +00:00
|
|
|
@attr('number') SyncTime;
|
|
|
|
@attr() meta;
|
2021-02-19 16:42:16 +00:00
|
|
|
@attr({ defaultValue: () => [] }) Resources; // []
|
2020-11-09 17:29:12 +00:00
|
|
|
|
2020-12-03 09:14:59 +00:00
|
|
|
// The name is the Name of the Service (the grouping of instances)
|
|
|
|
@alias('Service.Service') Name;
|
|
|
|
|
|
|
|
// If the ID is blank fallback to the Service.Service (the Name)
|
2020-12-14 15:28:35 +00:00
|
|
|
@or('Service.{ID,Service}') ID;
|
2020-12-01 15:45:09 +00:00
|
|
|
@or('Service.Address', 'Node.Service') Address;
|
|
|
|
|
2020-11-09 17:29:12 +00:00
|
|
|
@alias('Service.Tags') Tags;
|
|
|
|
@alias('Service.Meta') Meta;
|
|
|
|
@alias('Service.Namespace') Namespace;
|
2020-12-07 09:14:30 +00:00
|
|
|
|
|
|
|
@filter('Checks.@each.Kind', (item, i, arr) => item.Kind === 'service') ServiceChecks;
|
|
|
|
@filter('Checks.@each.Kind', (item, i, arr) => item.Kind === 'node') NodeChecks;
|
|
|
|
|
|
|
|
// MeshChecks are a concatenation of Checks for the Instance and Checks for
|
2021-01-29 15:57:47 +00:00
|
|
|
// the ProxyInstance.
|
|
|
|
@computed('Checks.[]', 'ProxyInstance.{Checks.[],ServiceProxy.Expose.Checks}')
|
2020-12-07 09:14:30 +00:00
|
|
|
get MeshChecks() {
|
2021-01-29 15:57:47 +00:00
|
|
|
// merge the instance and proxy checks together, avoiding duplicate node
|
|
|
|
// checks and additionally setting any checks to exposed if required
|
|
|
|
return mergeChecks(
|
|
|
|
[get(this, 'Checks'), get(this, 'ProxyInstance.Checks')],
|
|
|
|
get(this, 'ProxyInstance.ServiceProxy.Expose.Checks')
|
|
|
|
);
|
2020-12-07 09:14:30 +00:00
|
|
|
}
|
2020-11-09 17:29:12 +00:00
|
|
|
|
|
|
|
@computed('Service.Meta')
|
|
|
|
get ExternalSources() {
|
2020-09-01 18:13:11 +00:00
|
|
|
const sources = Object.entries(this.Service.Meta || {})
|
|
|
|
.filter(([key, value]) => key === 'external-source')
|
|
|
|
.map(([key, value]) => {
|
|
|
|
return value;
|
|
|
|
});
|
|
|
|
return [...new Set(sources)];
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 15:42:18 +00:00
|
|
|
@computed('Service.Kind')
|
|
|
|
get IsProxy() {
|
|
|
|
return ['connect-proxy', 'mesh-gateway', 'ingress-gateway', 'terminating-gateway'].includes(
|
|
|
|
this.Service.Kind
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsOrigin means that the service can have associated up or down streams,
|
|
|
|
// this service being the origin point of those streams
|
|
|
|
@computed('Service.Kind')
|
|
|
|
get IsOrigin() {
|
|
|
|
return !['connect-proxy', 'mesh-gateway'].includes(this.Service.Kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsMeshOrigin means that the service can have associated up or downstreams
|
|
|
|
// that are in the Consul mesh itself
|
|
|
|
@computed('IsOrigin')
|
|
|
|
get IsMeshOrigin() {
|
|
|
|
return this.IsOrigin && !['terminating-gateway'].includes(this.Service.Kind);
|
|
|
|
}
|
|
|
|
|
2020-11-09 17:29:12 +00:00
|
|
|
@computed('ChecksPassing', 'ChecksWarning', 'ChecksCritical')
|
|
|
|
get Status() {
|
2020-09-01 18:13:11 +00:00
|
|
|
switch (true) {
|
|
|
|
case this.ChecksCritical.length !== 0:
|
|
|
|
return 'critical';
|
|
|
|
case this.ChecksWarning.length !== 0:
|
|
|
|
return 'warning';
|
|
|
|
case this.ChecksPassing.length !== 0:
|
|
|
|
return 'passing';
|
|
|
|
default:
|
|
|
|
return 'empty';
|
|
|
|
}
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('Checks.[]')
|
|
|
|
get ChecksPassing() {
|
2020-09-01 18:13:11 +00:00
|
|
|
return this.Checks.filter(item => item.Status === 'passing');
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('Checks.[]')
|
|
|
|
get ChecksWarning() {
|
2020-09-01 18:13:11 +00:00
|
|
|
return this.Checks.filter(item => item.Status === 'warning');
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('Checks.[]')
|
|
|
|
get ChecksCritical() {
|
2020-09-01 18:13:11 +00:00
|
|
|
return this.Checks.filter(item => item.Status === 'critical');
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('Checks.[]', 'ChecksPassing')
|
|
|
|
get PercentageChecksPassing() {
|
2020-09-01 18:13:11 +00:00
|
|
|
return (this.ChecksPassing.length / this.Checks.length) * 100;
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('Checks.[]', 'ChecksWarning')
|
|
|
|
get PercentageChecksWarning() {
|
2020-09-01 18:13:11 +00:00
|
|
|
return (this.ChecksWarning.length / this.Checks.length) * 100;
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('Checks.[]', 'ChecksCritical')
|
|
|
|
get PercentageChecksCritical() {
|
2020-09-01 18:13:11 +00:00
|
|
|
return (this.ChecksCritical.length / this.Checks.length) * 100;
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
}
|