diff --git a/.changelog/18464.txt b/.changelog/18464.txt new file mode 100644 index 0000000000..b0c15cf0d5 --- /dev/null +++ b/.changelog/18464.txt @@ -0,0 +1,3 @@ +```release-note:bug +UI : Nodes list view was breaking for synthetic-nodes. Fix handles non existence of consul-version meta for node. +``` diff --git a/ui/packages/consul-ui/app/serializers/application.js b/ui/packages/consul-ui/app/serializers/application.js index 6230554f7c..b7b1fa4847 100644 --- a/ui/packages/consul-ui/app/serializers/application.js +++ b/ui/packages/consul-ui/app/serializers/application.js @@ -227,7 +227,7 @@ export default class ApplicationSerializer extends Serializer { // create a Set and add version with only major.minor : ex-1.24.6 as 1.24 let versionSet = new Set(); payload.forEach(function (item) { - if (item.Meta && item.Meta['consul-version'] !== '') { + if (item.Meta && item.Meta['consul-version']) { const split = item.Meta['consul-version'].split('.'); versionSet.add(split[0] + '.' + split[1]); } diff --git a/ui/packages/consul-ui/mock-api/v1/internal/ui/nodes b/ui/packages/consul-ui/mock-api/v1/internal/ui/nodes index de64b0bb8e..5cabfb4246 100644 --- a/ui/packages/consul-ui/mock-api/v1/internal/ui/nodes +++ b/ui/packages/consul-ui/mock-api/v1/internal/ui/nodes @@ -13,6 +13,7 @@ function(item, i) { const peerNameString = i === 0 ? '"PeerName": "billing",' : '"PeerName": "",' + const isSyntheticNode = env('CONSUL_AGENTLESS_ENABLED') ? fake.helpers.randomize([true, false, false, false]) : false return ` { "ID":"${fake.random.uuid()}", @@ -25,8 +26,10 @@ }, "Meta": { "consul-network-segment":"", + ${isSyntheticNode ? `` : ` "consul-version": "${env('CONSUL_VERSION') ? fake.helpers.randomize([env('CONSUL_VERSION'),"1.10.4","1.15.2", "1.17.8","1.7.2","1.12.4", "1.17.2","1.0.9","2.0.2"]) : fake.helpers.randomize(["1.10.4","1.15.2", "1.17.8","1.7.2","1.12.4", "1.17.2","1.0.9","2.0.2"]) }", - "synthetic-node": ${env('CONSUL_AGENTLESS_ENABLED') ? fake.helpers.randomize([true, false, false, false]) : false} + `} + "synthetic-node": ${isSyntheticNode} }, "Services":[ ${ diff --git a/ui/packages/consul-ui/tests/unit/serializers/application-test.js b/ui/packages/consul-ui/tests/unit/serializers/application-test.js index d50bf81d3f..180ae76172 100644 --- a/ui/packages/consul-ui/tests/unit/serializers/application-test.js +++ b/ui/packages/consul-ui/tests/unit/serializers/application-test.js @@ -6,6 +6,7 @@ import { module, test } from 'qunit'; import { setupTest } from 'ember-qunit'; import { HEADERS_SYMBOL as META } from 'consul-ui/utils/http/consul'; +import Node from 'consul-ui/models/node'; module('Unit | Serializer | application', function (hooks) { setupTest(hooks); @@ -122,4 +123,94 @@ module('Unit | Serializer | application', function (hooks) { assert.deepEqual(actual, expected); // assert.ok(adapter.uidForURL.calledTwice); }); + test('normalizeResponse for Node returns the expected meta in response', function (assert) { + const store = this.owner.lookup('service:store'); + const serializer = store.serializerFor('application'); + serializer.timestamp = () => 1234567890; //mocks actual timestamp + serializer.primaryKey = 'primary-key-name'; + serializer.slugKey = 'Name'; + serializer.fingerprint = function (primary, slug, foreignValue) { + return function (item) { + return { + ...item, + ...{ + Datacenter: foreignValue, + [primary]: item[slug], + }, + }; + }; + }; + + const payload = [ + { + Node: 'node-0', + Meta: { 'consul-version': '1.7.2' }, + uid: '1234', + SyncTime: 1234567890, + }, + { + Node: 'node-1', + Meta: { 'consul-version': '1.18.0' }, + uid: '1235', + SyncTime: 1234567891, + }, + // synthetic-node without consul-version meta + { + Node: 'node-2', + Meta: { 'synthetic-node': true }, + uid: '1236', + SyncTime: 1234567891, + }, + ]; + + const expected = { + data: [ + { + attributes: { + Node: 'node-0', + Meta: { 'consul-version': '1.7.2' }, + SyncTime: 1234567890, + uid: '1234', + }, + id: '1234', + relationships: {}, + type: 'node', + }, + { + attributes: { + Node: 'node-1', + Meta: { 'consul-version': '1.18.0' }, + SyncTime: 1234567890, + uid: '1235', + }, + id: '1235', + relationships: {}, + type: 'node', + }, + { + attributes: { + Node: 'node-2', + Meta: { 'synthetic-node': true }, + SyncTime: 1234567890, + uid: '1236', + }, + id: '1236', + relationships: {}, + type: 'node', + }, + ], + included: [], + meta: { + versions: ['1.18', '1.7'], //expect distinct major versions sorted + cacheControl: undefined, + cursor: undefined, + date: 1234567890, + dc: undefined, + nspace: undefined, + partition: undefined, + }, + }; + const actual = serializer.normalizeResponse(store, Node, payload, '2', 'query'); + assert.deepEqual(actual, expected); + }); });