Vijay 2f20c77e4d
Displays Consul version of each nodes in UI nodes section (#17754)
* update UINodes and UINodeInfo response with consul-version info added as NodeMeta, fetched from serf members

* update test cases TestUINodes, TestUINodeInfo

* added nil check for map

* add consul-version in local agent node metadata

* get consul version from serf member and add this as node meta in catalog register request

* updated ui mock response to include consul versions as node meta

* updated ui trans and added version as query param to node list route

* updates in ui templates to display consul version with filter and sorts

* updates in ui - model class, serializers,comparators,predicates for consul version feature

* added change log for Consul Version Feature

* updated to get version from consul service, if for some reason not available from serf

* updated changelog text

* updated dependent testcases

* multiselection version filter

* Update agent/consul/state/catalog.go

comments updated

Co-authored-by: Jared Kirschner <85913323+jkirschner-hashicorp@users.noreply.github.com>

---------

Co-authored-by: Jared Kirschner <85913323+jkirschner-hashicorp@users.noreply.github.com>
2023-07-12 13:34:39 -06:00

76 lines
2.3 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Model, { attr, hasMany } from '@ember-data/model';
import { computed } from '@ember/object';
import { filter } from '@ember/object/computed';
import { fragmentArray } from 'ember-data-model-fragments/attributes';
export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'ID';
export default class Node extends Model {
@attr('string') uid;
@attr('string') ID;
@attr('string') Datacenter;
@attr('string') PeerName;
@attr('string') Partition;
@attr('string') Address;
@attr('string') Node;
@attr('number') SyncTime;
@attr('number') CreateIndex;
@attr('number') ModifyIndex;
@attr() meta; // {}
@attr() Meta; // {}
@attr() TaggedAddresses; // {lan, wan}
@attr({ defaultValue: () => [] }) Resources; // []
// Services are reshaped to a different shape to what you sometimes get from
// the response, see models/node.js
@hasMany('service-instance') Services; // TODO: Rename to ServiceInstances
@fragmentArray('health-check') Checks;
// MeshServiceInstances are all instances that aren't connect-proxies this
// currently includes gateways as these need to show up in listings
@filter('Services', (item) => item.Service.Kind !== 'connect-proxy') MeshServiceInstances;
// ProxyServiceInstances are all instances that are connect-proxies
@filter('Services', (item) => item.Service.Kind === 'connect-proxy') ProxyServiceInstances;
@filter('Checks', (item) => item.ServiceID === '') NodeChecks;
@computed('ChecksCritical', 'ChecksPassing', 'ChecksWarning')
get Status() {
switch (true) {
case this.ChecksCritical !== 0:
return 'critical';
case this.ChecksWarning !== 0:
return 'warning';
case this.ChecksPassing !== 0:
return 'passing';
default:
return 'empty';
}
}
@computed('NodeChecks.[]')
get ChecksCritical() {
return this.NodeChecks.filter((item) => item.Status === 'critical').length;
}
@computed('NodeChecks.[]')
get ChecksPassing() {
return this.NodeChecks.filter((item) => item.Status === 'passing').length;
}
@computed('NodeChecks.[]')
get ChecksWarning() {
return this.NodeChecks.filter((item) => item.Status === 'warning').length;
}
@computed('Meta')
get Version() {
return this.Meta?.['consul-version'] ?? '';
}
}