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

ui: Topology - Fix up Default Allow and Permissive Intentions notices #11216

Merged
merged 7 commits into from
Oct 12, 2021

Conversation

kaxcode
Copy link
Contributor

@kaxcode kaxcode commented Oct 5, 2021

✨ Description:

This PR updates the conditionals used to show the Default Allow notice, the Permissive Intentions notice, and all the collapsible notices.

Demo Link

📸 Screenshots:

Permissive Intention Notice
Screen Shot 2021-10-05 at 11 13 57 AM

Default Allow Notice
Screen Shot 2021-10-05 at 11 10 00 AM

⚡ Backend Changes:

No BE changes but we did verify with BE what the response should look like.

🤡 Updates to mock-api:

Removed DefaultAllow and WildcardIntention from root /v1/internal/ui/service-topology response.

🧪 Testing:

Removed the test that covered the Default Allow notice, because of limitations with mocking out API header response. Time-blocked the effort and deleted it in the end.

Updated the test that covered the Permissive Intentions notice.

📝 PR Tasks:

  • Backport
  • Changelog
  • Demo Link

@kaxcode kaxcode added theme/ui Anything related to the UI backport/1.10 labels Oct 5, 2021
@kaxcode kaxcode requested a review from johncowen October 5, 2021 14:13
@vercel vercel bot temporarily deployed to Preview – consul October 5, 2021 14:14 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging October 5, 2021 14:14 Inactive
@kaxcode kaxcode added this to the 1.11.0 milestone Oct 5, 2021
@kaxcode kaxcode added the pr/do-not-merge PR cannot be merged in its current form. label Oct 5, 2021
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging October 5, 2021 16:11 Inactive
@vercel vercel bot temporarily deployed to Preview – consul October 5, 2021 16:11 Inactive
const allNotices = [
...document.querySelectorAll('div.collapsible-notices > div.notices > .notice'),
];
this.collapsible = allNotices.length > 2;
Copy link
Contributor Author

@kaxcode kaxcode Oct 5, 2021

Choose a reason for hiding this comment

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

These code changes are a more efficient solution to showing or not the collapsible button.

FYI in upcoming Topology changes we'll be adding more notices.

Copy link
Contributor

Choose a reason for hiding this comment

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

Curious as to why this could be more efficient? Mostly in modern frameworks the idea is to declaratively configure what you want the view to be based on the state and then the framework efficiently creates that view for you - using querySelector[All] is generally shied away from. I would say that generally if you find yourself using DOM methods like this it might be worth thinking of another way to do it (there's always an outlier but generally the reason for that outlier is clear if there is)

@@ -33,14 +31,19 @@ export default class Topology extends Model {
return undefinedDownstream;
}

@computed('FilteredByACL', 'DefaultAllow', 'WildcardIntention', 'notDefinedIntention')
Copy link
Contributor Author

@kaxcode kaxcode Oct 5, 2021

Choose a reason for hiding this comment

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

I removed this code because it was not efficient to show or not the collapsible banner. Soon it will be impossible to figure out all the "notice combos" that will exist.

With BE folks we verified that default allow and wildcard intentions can co-exist.

@@ -136,7 +98,7 @@ as |nspace dc items topology|}}
{{#if config.data}}
<TopologyMetrics
@nspace={{nspace}}
@dc={{dc.Name}}
@dc={{dc}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to pass the whole dc object since I need the dc.DefaultACLPolicy in topology-metrics/index.js

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool yeah good move, thanks for the explanation.

@@ -53,17 +53,11 @@ ${
fake.seed(index);


// Randomly make permissive intentions
const defaultAllow = fake.random.boolean();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about keeping this, but we verified with BE that default allow and wildcard intentions can co-exist.

@kaxcode kaxcode removed the pr/do-not-merge PR cannot be merged in its current form. label Oct 5, 2021
@johncowen
Copy link
Contributor

Super nice we can do this now with that new ACL header.

I have a few question based on your description before I give this a proper look:

⚡ Backend Changes:
No BE changes but we did verify with BE what the response should look like.

🤡 Updates to mock-api:
Removed DefaultAllow and WildcardIntention from root /v1/internal/ui/service-topology response.

If there are no backend changes, should we be updating the mocks? The mocks should be as close to the backend as possible. Is there a plan to make the same changes to the backend that are made here in the mocks?

Removed the test that covered the Default Allow notice, because of limitations with mocking out API header response. Time-blocked the effort and deleted it in the end.

Could you explain what you mean by the limitations here, off the top of my head I can't think of what that might be?

Lemme know and I can take a look over this

@kaxcode
Copy link
Contributor Author

kaxcode commented Oct 5, 2021

@johncowen

If there are no backend changes, should we be updating the mocks? The mocks should be as close to the backend as possible. Is there a plan to make the same changes to the backend that are made here in the mocks?

The mocks were wrong and did not match BE response. No changes are needed in the BE.

Could you explain what you mean by the limitations here, off the top of my head I can't think of what that might be?

I could not set X-Consul-Default-Acl-Policy = 'allow' as a header response from the v1/catalog/datacenters endpoint.

@johncowen
Copy link
Contributor

The mocks were wrong and did not match BE response. No changes are needed in the BE.

Ah gotcha, thanks for the explanation!

I could not set X-Consul-Default-Acl-Policy = 'allow' as a header response from the v1/catalog/datacenters endpoint.

Ah, so not a limitation as such, more you're not sure how it's done? How much time did you time block this for? I can either walk you through it, show you where we do this already or pop something on the end of this myself depending on whether you can spend some more time on this or not. Lemme know how big your time block is and we can sort either way.

Copy link
Contributor

@johncowen johncowen left a comment

Choose a reason for hiding this comment

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

I made a few inline comments also, but don't feel like you have to address them before we get a chance to talk about avoiding deleting the test here (re: mocking out the ACL header). I'll wait til you get back to me on the other (not-inline) comment I made and we can go from there.

edit: Is this the one we had a list of user stories to test for? The one we were going to make a spreadsheet for to make sure we covered them all?

const allNotices = [
...document.querySelectorAll('div.collapsible-notices > div.notices > .notice'),
];
this.collapsible = allNotices.length > 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious as to why this could be more efficient? Mostly in modern frameworks the idea is to declaratively configure what you want the view to be based on the state and then the framework efficiently creates that view for you - using querySelector[All] is generally shied away from. I would say that generally if you find yourself using DOM methods like this it might be worth thinking of another way to do it (there's always an outlier but generally the reason for that outlier is clear if there is)

@@ -136,7 +98,7 @@ as |nspace dc items topology|}}
{{#if config.data}}
<TopologyMetrics
@nspace={{nspace}}
@dc={{dc.Name}}
@dc={{dc}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool yeah good move, thanks for the explanation.

this.Upstreams.filter(item => !item.Intention.HasExact && item.Intention.Allowed).length !==
0;

return downstreamWildcard || upstreamWildcard;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a note here, not sure if it matters or not. Did you know we have all this intention information available to us in the API call we make for the Services > Intentions tab (we also use the same call to do the intention updating on this Topology Tab). I would guess reusing that would save a bunch of backend work here, and if the user was using TProxy I don't think (not entirely sure) we'd have to make the extra topology endpoint API call at all. Anyway, no action to be made on FEs part here, but if you are talking to BE about this it might free them up a little.

@kaxcode
Copy link
Contributor Author

kaxcode commented Oct 6, 2021

Ah, so not a limitation as such, more you're not sure how it's done? How much time did you time block this for? I can either walk you through it, show you where we do this already or pop something on the end of this myself depending on whether you can spend some more time on this or not. Lemme know how big your time block is and we can sort either way.

@johncowen I time-blocked a whole afternoon for this one assertion. I mostly looked through the tests/steps/doubles files and the the tests/steps.js file. I did not see any examples of setting a API response header. Feel free to share any insight on how it could be done at a later time.

@kaxcode
Copy link
Contributor Author

kaxcode commented Oct 6, 2021

Curious as to why this could be more efficient? Mostly in modern frameworks the idea is to declaratively configure what you want the view to be based on the state and then the framework efficiently creates that view for you - using querySelector[All] is generally shied away from. I would say that generally if you find yourself using DOM methods like this it might be worth thinking of another way to do it (there's always an outlier but generally the reason for that outlier is clear if there is)

@johncowen I see what you mean. I've refactored the code I wrote in the CollapsibleNotices JS file to be in a helper. I made the changes in a separate commit.

@kaxcode kaxcode requested a review from johncowen October 6, 2021 14:14
@kaxcode
Copy link
Contributor Author

kaxcode commented Oct 6, 2021

Is this the one we had a list of user stories to test for? The one we were going to make a spreadsheet for to make sure we covered them all?

@johncowen sorry, I forgot to reply to this. Yes, we got on a call and discovered this was the actual issue. A spreadsheet has been made, but we still see no need for new notices atm.

@johncowen
Copy link
Contributor

Feel free to share any insight on how it could be done at a later time.

You can use the env function in .config files also:

latency: ${ location.search.index ? env('CONSUL_LATENCY', 60000) : env('CONSUL_LATENCY', 0) }

So instead of using randomize here use env

X-Consul-Default-Acl-Policy: ${fake.helpers.randomize(['allow', 'deny'])}

env here takes a default as a second argument so you could use:

X-Consul-Default-Acl-Policy: ${env('CONSUL_ACL_POLICY', fake.helpers.randomize(['allow', 'deny']))}

To make it still use a random value if the env var (the cookie/mock) isn't set. If you try this just in your browser first to make sure you can set it in your development environment, then you can add mocking it in a test environment.

During testing, you were right, you will need to add a new step like:

Given the default ACL policy is "$policy"

And then set your cookie in that step in order to mock this value out. There are a couple of ways to do that, one simpler that the other:

.given('a network latency of $number', function(number) {
set('CONSUL_LATENCY', number);
});

or something like this:

doc.cookie = `CONSUL_DATACENTER_LOCAL=${value}`;

Looking at the new stuff now 👍

@kaxcode
Copy link
Contributor Author

kaxcode commented Oct 6, 2021

@johncowen I've put the solution you suggested to the test in this branch ui/chore/default-allow-notices-test. I left a console.log in there so you can see the cookies make no impact on the mocked API headers response.

@johncowen
Copy link
Contributor

Did you try both approaches I linked to? The first one works fine for me.

@johncowen
Copy link
Contributor

Just a quick note: I'm gonna wait for that ^ (#11240) to merge here before re-reviewing. I think its all good tho and I think my remaining thoughts/comment will be solved by #11240. Good work! 👍

@kaxcode
Copy link
Contributor Author

kaxcode commented Oct 11, 2021

@johncowen I've rebased this PR. Is it ready to be merged?

Copy link
Contributor

@johncowen johncowen left a comment

Choose a reason for hiding this comment

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

Not a blocking question, but whats the difference between a "wildcard intention" and a "permissive intention"?

@kaxcode
Copy link
Contributor Author

kaxcode commented Oct 12, 2021

Not a blocking question, but whats the difference between a "wildcard intention" and a "permissive intention"?

@johncowen they mean the same thing. The only difference is WildcardIntention is what we thought BE was going to return so we implemented it with that name. "Permissive Intentions" was used for the notice. I can make a separate PR to reconcile the names.

@kaxcode kaxcode merged commit daec73e into main Oct 12, 2021
@kaxcode kaxcode deleted the ui/bugfix/topology-notices branch October 12, 2021 13:27
@hc-github-team-consul-core
Copy link
Contributor

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/469698.

@hc-github-team-consul-core
Copy link
Contributor

🍒❌ Cherry pick of commit daec73e onto release/1.10.x failed! Build Log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/ui Anything related to the UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants