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';
|
2020-10-05 17:07:35 +00:00
|
|
|
|
|
|
|
export default class TopologyMetrics extends Component {
|
|
|
|
// =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
|
|
|
|
.map(item => {
|
|
|
|
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
|
|
|
|
.map(item => {
|
|
|
|
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-04-13 16:17:53 +00:00
|
|
|
get upstreams() {
|
|
|
|
const upstreams = get(this.args.topology, 'Upstreams') || [];
|
|
|
|
const items = [...upstreams];
|
|
|
|
const defaultAllow = get(this.args.topology, 'DefaultAllow');
|
|
|
|
const wildcardIntention = get(this.args.topology, 'WildcardIntention');
|
|
|
|
if (defaultAllow || wildcardIntention) {
|
|
|
|
items.push({
|
2021-04-14 22:52:41 +00:00
|
|
|
Name: '* (All Services)',
|
2021-04-13 16:17:53 +00:00
|
|
|
Datacenter: '',
|
|
|
|
Namespace: '',
|
|
|
|
Intention: {
|
|
|
|
Allowed: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
this.noMetricsReason = 'Unable to fetch metrics for a remote datacenter';
|
|
|
|
} else if (this.args.service.Service.Kind === 'ingress-gateway') {
|
|
|
|
this.noMetricsReason = 'Unable to fetch metrics for a ingress gateway';
|
|
|
|
} else {
|
|
|
|
this.noMetricsReason = null;
|
|
|
|
}
|
|
|
|
|
2020-10-05 17:07:35 +00:00
|
|
|
// Calculate viewBox dimensions
|
2021-02-17 18:51:48 +00:00
|
|
|
this.downView = document.getElementById('downstream-lines').getBoundingClientRect();
|
2021-04-13 16:17:53 +00:00
|
|
|
const upstreamLines = document.getElementById('upstream-lines').getBoundingClientRect();
|
|
|
|
const upstreamColumn = document.getElementById('upstream-column').getBoundingClientRect();
|
|
|
|
|
|
|
|
this.upView = {
|
|
|
|
x: upstreamLines.x,
|
|
|
|
y: upstreamLines.y,
|
|
|
|
width: upstreamLines.width,
|
|
|
|
height: upstreamColumn.height,
|
|
|
|
};
|
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);
|
|
|
|
}
|
|
|
|
}
|