open-nomad/ui/app/components/allocation-service-sidebar.js
Phil Renaud a381ecaa09
[ui] Service Discovery: provide a quick link to the Consul UI if available (#14537)
* Test for aggregate service health and consul agg service health

* If a consul UI link is present, show a nice little link

* Also add to job services page

* Reallocate consul url in mock
2022-09-12 10:00:30 -04:00

59 lines
1.5 KiB
JavaScript

import Component from '@glimmer/component';
import { inject as service } from '@ember/service';
export default class AllocationServiceSidebarComponent extends Component {
@service store;
@service system;
get isSideBarOpen() {
return !!this.args.service;
}
keyCommands = [
{
label: 'Close Evaluations Sidebar',
pattern: ['Escape'],
action: () => this.args.fns.closeSidebar(),
},
];
get service() {
return this.store.query('service-fragment', { refID: this.args.serviceID });
}
get address() {
const port = this.args.allocation?.allocatedResources?.ports?.findBy(
'label',
this.args.service.portLabel
);
if (port) {
return `${port.hostIp}:${port.value}`;
} else {
return null;
}
}
get aggregateStatus() {
return this.checks.any((check) => check.Status === 'failure')
? 'Unhealthy'
: 'Healthy';
}
get consulRedirectLink() {
return this.system.agent.get('config')?.UI?.Consul?.BaseUIURL;
}
get checks() {
if (!this.args.service || !this.args.allocation) return [];
let allocID = this.args.allocation.id;
// Our UI checks run every 2 seconds; but a check itself may only update every, say, minute.
// Therefore, we'll have duplicate checks in a service's healthChecks array.
// Only get the most recent check for each check.
return (this.args.service.healthChecks || [])
.filterBy('Alloc', allocID)
.sortBy('Timestamp')
.reverse()
.uniqBy('Check')
.sortBy('Check');
}
}