Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hedge for when consul sends nodes with an empty ID #4331

Merged
merged 2 commits into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ui-v2/app/adapters/node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import Adapter from './application';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/node';
import { OK as HTTP_OK } from 'consul-ui/utils/http/status';
// TODO: Looks like ID just isn't used at all
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean that ID isn't used at all here? It looks like you're generating IDs on the client and using that as the primary key (uid) so ember data is never using the ID from the server for its identity map. Probably not an issue as long as you're not caching the list or editing things, but something to be aware of if you ever want to add that sort of thing. I'm guessing you already work around that though for individual node pages (or you fetch the group first).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, yeah its more or less a note to go back and consider just ignoring ID completely, and just pretend Node is the 'unique key' to use for the slug. It sounds like that is always unique and ID can sometimes be empty, although, even while I'm writing this, the more i think about it the more I'd just continue to use ID - it just reads better plus the big has been fixed in the backend now - this is just for old data I think.

// consider just using .Node for the SLUG_KEY
const fillSlug = function(item) {
if (item[SLUG_KEY] === '') {
item[SLUG_KEY] = item['Node'];
}
return item;
};
export default Adapter.extend({
urlForQuery: function(query, modelName) {
return this.appendURL('internal/ui/nodes', [], this.cleanQuery(query));
Expand All @@ -14,6 +22,7 @@ export default Adapter.extend({
const url = this.parseURL(requestData.url);
switch (true) {
case this.isQueryRecord(url):
response = fillSlug(response);
response = {
...response,
...{
Expand All @@ -23,6 +32,7 @@ export default Adapter.extend({
break;
default:
response = response.map((item, i, arr) => {
item = fillSlug(item);
return {
...item,
...{
Expand Down
33 changes: 33 additions & 0 deletions ui-v2/tests/acceptance/dc/nodes/empty-ids.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@setupApplicationTest
Feature: Hedge for if nodes come in over the API with no ID
Scenario: A node list with some missing IDs
Given 1 datacenter model with the value "dc-1"
And 5 node models from yaml
---
- ID: id-1
Node: name-1
- ID: ""
Node: name-2
- ID: ""
Node: name-3
- ID: ""
Node: name-4
- ID: ""
Node: name-5
---
When I visit the nodes page for yaml
---
dc: dc-1
---
Then the url should be /dc-1/nodes
Then I see name on the nodes like yaml
---
- name-1
- name-2
- name-3
- name-4
- name-5

@ignore
Scenario: Visually comparing
Then the ".unhealthy" element should look like the "/node_modules/@hashicorp/consul-testing-extras/fixtures/dc/nodes/empty-ids.png" image
10 changes: 10 additions & 0 deletions ui-v2/tests/acceptance/steps/dc/nodes/empty-ids-steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import steps from '../../steps';

// step definitions that are shared between features should be moved to the
// tests/acceptance/steps/steps.js file

export default function(assert) {
return steps(assert).then('I should find a file', function() {
assert.ok(true, this.step);
});
}