2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2022-01-07 19:16:21 +00:00
|
|
|
import Model, { attr } from '@ember-data/model';
|
2020-12-07 09:14:30 +00:00
|
|
|
import { fragmentArray } from 'ember-data-model-fragments/attributes';
|
2022-01-07 19:16:21 +00:00
|
|
|
import { computed } 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';
|
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() {
|
2022-09-15 08:43:17 +00:00
|
|
|
const sources = this.items.reduce(function (prev, item) {
|
2020-12-14 14:25:33 +00:00
|
|
|
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
|
|
|
// 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;
|
2021-05-26 16:52:25 +00:00
|
|
|
@attr('string') SocketPath;
|
2020-12-01 15:45:09 +00:00
|
|
|
|
2020-11-09 17:29:12 +00:00
|
|
|
@alias('Service.Tags') Tags;
|
|
|
|
@alias('Service.Meta') Meta;
|
|
|
|
@alias('Service.Namespace') Namespace;
|
2021-10-01 10:07:58 +00:00
|
|
|
@alias('Service.Partition') Partition;
|
2021-09-15 18:50:11 +00:00
|
|
|
|
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;
|
|
|
|
|
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() {
|
2023-03-03 21:59:04 +00:00
|
|
|
return [
|
|
|
|
'connect-proxy',
|
|
|
|
'mesh-gateway',
|
|
|
|
'ingress-gateway',
|
|
|
|
'terminating-gateway',
|
|
|
|
'api-gateway',
|
|
|
|
].includes(this.Service.Kind);
|
2020-12-02 15:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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() {
|
2022-09-15 08:43:17 +00:00
|
|
|
return this.Checks.filter((item) => item.Status === 'passing');
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('Checks.[]')
|
|
|
|
get ChecksWarning() {
|
2022-09-15 08:43:17 +00:00
|
|
|
return this.Checks.filter((item) => item.Status === 'warning');
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed('Checks.[]')
|
|
|
|
get ChecksCritical() {
|
2022-09-15 08:43:17 +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
|
|
|
}
|
|
|
|
}
|