Skip to content

Commit

Permalink
fix for , non presence of consul-version meta (#18464)
Browse files Browse the repository at this point in the history
* fix for #18406 , non presence of consul-version meta

* removed redundant checks

* updated mock-api to mimic api response for synthetic nodes

* added test to test getDistinctConsulVersions method with synthetic-node case

* updated typo in comments

* added change log
  • Loading branch information
vijayraghav-io authored Aug 22, 2023
1 parent 8a93124 commit a1755d1
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/18464.txt
Original file line number Diff line number Diff line change
@@ -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.
```
2 changes: 1 addition & 1 deletion ui/packages/consul-ui/app/serializers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
5 changes: 4 additions & 1 deletion ui/packages/consul-ui/mock-api/v1/internal/ui/nodes
Original file line number Diff line number Diff line change
Expand Up @@ -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()}",
Expand All @@ -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":[
${
Expand Down
91 changes: 91 additions & 0 deletions ui/packages/consul-ui/tests/unit/serializers/application-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
});

0 comments on commit a1755d1

Please sign in to comment.