From 9c965f98fdf99daab5f40f04804c5632f121f680 Mon Sep 17 00:00:00 2001 From: Michael Klein Date: Wed, 26 Oct 2022 16:42:55 +0200 Subject: [PATCH] Fix PeerName is part of service uniqueness We need to make a PeerName part of a the service id when present. This makes sure that peers can export services named the same as other peers but have the UI still treat them as separate services. --- ui/packages/consul-ui/app/models/service.js | 2 +- .../app/utils/create-fingerprinter.js | 28 +++++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ui/packages/consul-ui/app/models/service.js b/ui/packages/consul-ui/app/models/service.js index 7b50315d7..0e06f81a8 100644 --- a/ui/packages/consul-ui/app/models/service.js +++ b/ui/packages/consul-ui/app/models/service.js @@ -5,7 +5,7 @@ import { fragment } from 'ember-data-model-fragments/attributes'; import replace, { nullValue } from 'consul-ui/decorators/replace'; export const PRIMARY_KEY = 'uid'; -export const SLUG_KEY = 'Name'; +export const SLUG_KEY = 'Name,PeerName'; export const Collection = class Collection { @tracked items; diff --git a/ui/packages/consul-ui/app/utils/create-fingerprinter.js b/ui/packages/consul-ui/app/utils/create-fingerprinter.js index bc6481647..f1b91cfc0 100644 --- a/ui/packages/consul-ui/app/utils/create-fingerprinter.js +++ b/ui/packages/consul-ui/app/utils/create-fingerprinter.js @@ -1,4 +1,5 @@ import { get } from '@ember/object'; +import { isEmpty } from '@ember/utils'; export default function (foreignKey, nspaceKey, partitionKey, hash = JSON.stringify) { return function (primaryKey, slugKey, foreignKeyValue, nspaceValue, partitionValue) { @@ -10,15 +11,24 @@ export default function (foreignKey, nspaceKey, partitionKey, hash = JSON.string ); } const slugKeys = slugKey.split(','); - const slugValues = slugKeys.map(function (slugKey) { - const slug = get(item, slugKey); - if (slug == null || slug.length < 1) { - throw new Error( - `Unable to create fingerprint, missing slug. Looking for value in \`${slugKey}\` got \`${slug}\`` - ); - } - return slug; - }); + const slugValues = slugKeys + .map(function (slugKey) { + const slug = get(item, slugKey); + + const isSlugEmpty = isEmpty(slug); + + if (isSlugEmpty) { + // PeerName should be optional as part of id + if (slugKey === 'PeerName') { + return; + } + throw new Error( + `Unable to create fingerprint, missing slug. Looking for value in \`${slugKey}\` got \`${slug}\`` + ); + } + return slug; + }) + .compact(); // This ensures that all data objects have a Namespace and a Partition // value set, even in OSS. if (typeof item[nspaceKey] === 'undefined') {