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