github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/components/allocation-service-sidebar.js (about) 1 import Component from '@glimmer/component'; 2 import { inject as service } from '@ember/service'; 3 4 export default class AllocationServiceSidebarComponent extends Component { 5 @service store; 6 @service system; 7 8 get isSideBarOpen() { 9 return !!this.args.service; 10 } 11 keyCommands = [ 12 { 13 label: 'Close Service Sidebar', 14 pattern: ['Escape'], 15 action: () => this.args.fns.closeSidebar(), 16 }, 17 ]; 18 19 get service() { 20 return this.store.query('service-fragment', { refID: this.args.serviceID }); 21 } 22 23 get address() { 24 const port = this.args.allocation?.allocatedResources?.ports?.findBy( 25 'label', 26 this.args.service.portLabel 27 ); 28 if (port) { 29 return `${port.hostIp}:${port.value}`; 30 } else { 31 return null; 32 } 33 } 34 35 get aggregateStatus() { 36 return this.checks.any((check) => check.Status === 'failure') 37 ? 'Unhealthy' 38 : 'Healthy'; 39 } 40 41 get consulRedirectLink() { 42 return this.system.agent.get('config')?.UI?.Consul?.BaseUIURL; 43 } 44 45 get checks() { 46 if (!this.args.service || !this.args.allocation) return []; 47 let allocID = this.args.allocation.id; 48 // Our UI checks run every 2 seconds; but a check itself may only update every, say, minute. 49 // Therefore, we'll have duplicate checks in a service's healthChecks array. 50 // Only get the most recent check for each check. 51 return (this.args.service.healthChecks || []) 52 .filterBy('Alloc', allocID) 53 .sortBy('Timestamp') 54 .reverse() 55 .uniqBy('Check') 56 .sortBy('Check'); 57 } 58 }