2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
2020-10-05 17:07:35 +00:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import { tracked } from '@glimmer/tracking';
|
2021-04-13 16:17:53 +00:00
|
|
|
import { action, get } from '@ember/object';
|
2021-11-05 17:46:41 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2020-10-05 17:07:35 +00:00
|
|
|
|
|
|
|
export default class TopologyMetrics extends Component {
|
2021-11-05 17:46:41 +00:00
|
|
|
@service('env') env;
|
2022-07-22 17:28:13 +00:00
|
|
|
@service() abilities;
|
2021-11-05 17:46:41 +00:00
|
|
|
|
2020-10-05 17:07:35 +00:00
|
|
|
// =attributes
|
|
|
|
@tracked centerDimensions;
|
|
|
|
@tracked downView;
|
|
|
|
@tracked downLines = [];
|
|
|
|
@tracked upView;
|
|
|
|
@tracked upLines = [];
|
2020-12-08 15:47:55 +00:00
|
|
|
@tracked noMetricsReason;
|
2020-10-05 17:07:35 +00:00
|
|
|
|
|
|
|
// =methods
|
|
|
|
drawDownLines(items) {
|
2020-10-08 15:52:09 +00:00
|
|
|
const order = ['allow', 'deny'];
|
|
|
|
const dest = {
|
2020-11-12 15:40:15 +00:00
|
|
|
x: this.centerDimensions.x - 7,
|
2020-10-23 13:45:39 +00:00
|
|
|
y: this.centerDimensions.y + this.centerDimensions.height / 2,
|
2020-10-08 15:52:09 +00:00
|
|
|
};
|
2020-10-05 17:07:35 +00:00
|
|
|
|
2020-10-08 15:52:09 +00:00
|
|
|
return items
|
2022-09-15 08:43:17 +00:00
|
|
|
.map((item) => {
|
2020-10-08 15:52:09 +00:00
|
|
|
const dimensions = item.getBoundingClientRect();
|
|
|
|
const src = {
|
|
|
|
x: dimensions.x + dimensions.width,
|
|
|
|
y: dimensions.y + dimensions.height / 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
id: item.id,
|
|
|
|
permission: item.getAttribute('data-permission'),
|
|
|
|
dest: dest,
|
|
|
|
src: src,
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.sort((a, b) => {
|
|
|
|
return order.indexOf(a.permission) - order.indexOf(b.permission);
|
|
|
|
});
|
2020-10-05 17:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
drawUpLines(items) {
|
2020-10-08 15:52:09 +00:00
|
|
|
const order = ['allow', 'deny'];
|
|
|
|
const src = {
|
2020-11-12 15:40:15 +00:00
|
|
|
x: this.centerDimensions.x + 5.5,
|
2020-10-23 13:45:39 +00:00
|
|
|
y: this.centerDimensions.y + this.centerDimensions.height / 2,
|
2020-10-08 15:52:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return items
|
2022-09-15 08:43:17 +00:00
|
|
|
.map((item) => {
|
2020-10-08 15:52:09 +00:00
|
|
|
const dimensions = item.getBoundingClientRect();
|
|
|
|
const dest = {
|
2020-11-12 15:40:15 +00:00
|
|
|
x: dimensions.x - dimensions.width - 25,
|
2020-10-08 15:52:09 +00:00
|
|
|
y: dimensions.y + dimensions.height / 2,
|
|
|
|
};
|
2020-10-05 17:07:35 +00:00
|
|
|
|
2020-10-08 15:52:09 +00:00
|
|
|
return {
|
|
|
|
id: item.id,
|
|
|
|
permission: item.getAttribute('data-permission'),
|
|
|
|
dest: dest,
|
|
|
|
src: src,
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.sort((a, b) => {
|
|
|
|
return order.indexOf(a.permission) - order.indexOf(b.permission);
|
|
|
|
});
|
2020-10-05 17:07:35 +00:00
|
|
|
}
|
|
|
|
|
2021-11-05 17:46:41 +00:00
|
|
|
emptyColumn() {
|
|
|
|
const noDependencies = get(this.args.topology, 'noDependencies');
|
|
|
|
return !this.env.var('CONSUL_ACLS_ENABLED') || noDependencies;
|
|
|
|
}
|
|
|
|
|
|
|
|
get downstreams() {
|
|
|
|
const downstreams = get(this.args.topology, 'Downstreams') || [];
|
|
|
|
const items = [...downstreams];
|
|
|
|
const noDependencies = get(this.args.topology, 'noDependencies');
|
|
|
|
|
|
|
|
if (!this.env.var('CONSUL_ACLS_ENABLED') && noDependencies) {
|
|
|
|
items.push({
|
|
|
|
Name: 'Downstreams unknown.',
|
|
|
|
Empty: true,
|
|
|
|
Datacenter: '',
|
|
|
|
Namespace: '',
|
|
|
|
});
|
|
|
|
} else if (downstreams.length === 0) {
|
2022-07-22 17:28:13 +00:00
|
|
|
const canUsePeers = this.abilities.can('use peers');
|
|
|
|
|
2021-11-05 17:46:41 +00:00
|
|
|
items.push({
|
2022-07-22 17:28:13 +00:00
|
|
|
Name: canUsePeers
|
|
|
|
? 'No downstreams, or the downstreams are imported services.'
|
|
|
|
: 'No downstreams.',
|
2021-11-05 17:46:41 +00:00
|
|
|
Datacenter: '',
|
|
|
|
Namespace: '',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
2021-04-13 16:17:53 +00:00
|
|
|
get upstreams() {
|
|
|
|
const upstreams = get(this.args.topology, 'Upstreams') || [];
|
2022-09-15 08:43:17 +00:00
|
|
|
upstreams.forEach((u) => {
|
2022-06-23 13:16:26 +00:00
|
|
|
u.PeerOrDatacenter = u.PeerName || u.Datacenter;
|
|
|
|
});
|
2021-04-13 16:17:53 +00:00
|
|
|
const items = [...upstreams];
|
2021-10-12 13:27:06 +00:00
|
|
|
const defaultACLPolicy = get(this.args.dc, 'DefaultACLPolicy');
|
|
|
|
const wildcardIntention = get(this.args.topology, 'wildcardIntention');
|
2021-11-05 17:46:41 +00:00
|
|
|
const noDependencies = get(this.args.topology, 'noDependencies');
|
|
|
|
|
|
|
|
if (!this.env.var('CONSUL_ACLS_ENABLED') && noDependencies) {
|
|
|
|
items.push({
|
|
|
|
Name: 'Upstreams unknown.',
|
|
|
|
Datacenter: '',
|
2022-06-23 13:16:26 +00:00
|
|
|
PeerOrDatacenter: '',
|
2021-11-05 17:46:41 +00:00
|
|
|
Namespace: '',
|
|
|
|
});
|
|
|
|
} else if (defaultACLPolicy === 'allow' || wildcardIntention) {
|
2021-04-13 16:17:53 +00:00
|
|
|
items.push({
|
2021-04-14 22:52:41 +00:00
|
|
|
Name: '* (All Services)',
|
2021-04-13 16:17:53 +00:00
|
|
|
Datacenter: '',
|
2022-06-23 13:16:26 +00:00
|
|
|
PeerOrDatacenter: '',
|
2021-04-13 16:17:53 +00:00
|
|
|
Namespace: '',
|
2021-11-05 17:46:41 +00:00
|
|
|
});
|
|
|
|
} else if (upstreams.length === 0) {
|
|
|
|
items.push({
|
|
|
|
Name: 'No upstreams.',
|
|
|
|
Datacenter: '',
|
2022-06-23 13:16:26 +00:00
|
|
|
PeerOrDatacenter: '',
|
2021-11-05 17:46:41 +00:00
|
|
|
Namespace: '',
|
2021-04-13 16:17:53 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
2021-08-26 18:08:31 +00:00
|
|
|
get mainNotIngressService() {
|
|
|
|
const kind = get(this.args.service.Service, 'Kind') || '';
|
|
|
|
|
|
|
|
return kind !== 'ingress-gateway';
|
|
|
|
}
|
|
|
|
|
2023-11-28 21:27:14 +00:00
|
|
|
get mainNotAPIGatewayService() {
|
|
|
|
const kind = get(this.args.service.Service, 'Kind') || '';
|
|
|
|
|
|
|
|
return kind !== 'api-gateway';
|
|
|
|
}
|
2020-10-05 17:07:35 +00:00
|
|
|
// =actions
|
2021-02-17 18:51:48 +00:00
|
|
|
@action
|
|
|
|
setHeight(el, item) {
|
|
|
|
if (el) {
|
|
|
|
const container = el.getBoundingClientRect();
|
|
|
|
document.getElementById(`${item[0]}`).setAttribute('style', `height:${container.height}px`);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.calculate();
|
|
|
|
}
|
|
|
|
|
2020-10-05 17:07:35 +00:00
|
|
|
@action
|
|
|
|
calculate() {
|
2020-12-08 15:47:55 +00:00
|
|
|
if (this.args.isRemoteDC) {
|
2021-08-26 18:08:31 +00:00
|
|
|
this.noMetricsReason = 'remote-dc';
|
2020-12-08 15:47:55 +00:00
|
|
|
} else if (this.args.service.Service.Kind === 'ingress-gateway') {
|
2021-08-26 18:08:31 +00:00
|
|
|
this.noMetricsReason = 'ingress-gateway';
|
2020-12-08 15:47:55 +00:00
|
|
|
} else {
|
|
|
|
this.noMetricsReason = null;
|
|
|
|
}
|
|
|
|
|
2020-10-05 17:07:35 +00:00
|
|
|
// Calculate viewBox dimensions
|
2021-11-05 17:46:41 +00:00
|
|
|
const downstreamLines = document.getElementById('downstream-lines').getBoundingClientRect();
|
2021-04-13 16:17:53 +00:00
|
|
|
const upstreamLines = document.getElementById('upstream-lines').getBoundingClientRect();
|
2021-04-28 13:22:18 +00:00
|
|
|
const upstreamColumn = document.getElementById('upstream-column');
|
|
|
|
|
2021-11-05 17:46:41 +00:00
|
|
|
if (this.emptyColumn) {
|
|
|
|
this.downView = {
|
|
|
|
x: downstreamLines.x,
|
|
|
|
y: downstreamLines.y,
|
|
|
|
width: downstreamLines.width,
|
|
|
|
height: downstreamLines.height + 10,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
this.downView = downstreamLines;
|
|
|
|
}
|
|
|
|
|
2021-04-28 13:22:18 +00:00
|
|
|
if (upstreamColumn) {
|
|
|
|
this.upView = {
|
|
|
|
x: upstreamLines.x,
|
|
|
|
y: upstreamLines.y,
|
|
|
|
width: upstreamLines.width,
|
|
|
|
height: upstreamColumn.getBoundingClientRect().height + 10,
|
|
|
|
};
|
|
|
|
}
|
2020-10-05 17:07:35 +00:00
|
|
|
|
|
|
|
// Get Card elements positions
|
2021-04-08 19:14:53 +00:00
|
|
|
const downCards = [
|
|
|
|
...document.querySelectorAll('#downstream-container .topology-metrics-card'),
|
|
|
|
];
|
2020-10-23 13:45:39 +00:00
|
|
|
const grafanaCard = document.querySelector('.metrics-header');
|
2021-04-08 19:14:53 +00:00
|
|
|
const upCards = [...document.querySelectorAll('#upstream-column .topology-metrics-card')];
|
2020-10-05 17:07:35 +00:00
|
|
|
|
|
|
|
// Set center positioning points
|
|
|
|
this.centerDimensions = grafanaCard.getBoundingClientRect();
|
|
|
|
|
|
|
|
// Set Downstream Cards Positioning points
|
|
|
|
this.downLines = this.drawDownLines(downCards);
|
|
|
|
|
|
|
|
// Set Upstream Cards Positioning points
|
|
|
|
this.upLines = this.drawUpLines(upCards);
|
|
|
|
}
|
|
|
|
}
|