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

Firehose: honor optional prop for watches on individual resources #1711

Merged
merged 2 commits into from
Jun 14, 2019
Merged

Firehose: honor optional prop for watches on individual resources #1711

merged 2 commits into from
Jun 14, 2019

Conversation

mareklibra
Copy link
Contributor

@mareklibra mareklibra commented Jun 13, 2019

Introduce ignoreIfMissing Firehose resource property.

If set to true, a resource is skipped from generic
loadError 404 checking (cross-resources). So the overall data
retrieval does not fail if a specified resource is missing.

Can be used to optionally query a resource but enable rendering
of children if it is missing (HTTP 404).

The new property is an addition to existing optional property which
does not block rendering of children if list-retrieval is still in progress.

With default value ignoreIfMissing = false, the component is
backward compatible.

If set to `true`, a resource is skipped from generic
`loadError` 404 checking (cross-resources). So the overall data
retrieval does not fail if a specified resource is missing.

Can be used to optionally query a resource but enable rendering
of children if it is missing (HTTP 404).

The new property is an addition to existing `optional` property which
does not block rendering of children if list-retrieval is still in progress.

With default value `ignoreIfMissing = false`, the component is
backward compatible.
@openshift-ci-robot
Copy link
Contributor

Hi @mareklibra. Thanks for your PR.

I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 13, 2019
@mareklibra mareklibra mentioned this pull request Jun 13, 2019
4 tasks
stuff = stuff.toJS();
stuff.ignoreIfMissing = props.ignoreIfMissing;
}
return stuff || {};
Copy link
Member

@atiratree atiratree Jun 13, 2019

Choose a reason for hiding this comment

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

can we use the same approach which is used for lists?

const data = k8s.getIn([reduxID, 'data']);

 return {
    data: data && data.toJS(), 
    loadError: k8s.getIn([reduxID, 'loadError']),	
    loaded: k8s.getIn([reduxID, 'loaded']),
    optional: props.optional,
    ignoreIfMissing: props.ignoreIfMissing,
};

This way we can optionally swap the toJS with only immutables once they are needed in the future.

Copy link
Contributor Author

@mareklibra mareklibra Jun 13, 2019

Choose a reason for hiding this comment

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

Actually the stuff is not the response received from API but already a wrapper around it, please see

return state.mergeIn([id], {

Copy link
Member

Choose a reason for hiding this comment

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

I know, but it will be easier to extend for adding a support of raw immutables

Copy link
Member

Choose a reason for hiding this comment

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

meaning that toJS may not be used at all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this is needed, I propose to do it in a follow-up.
It would require refactoring of code around the reducer and this is unrelated to original need behind this PR.

@spadgett
Copy link
Member

@mareklibra I'm confused: how is this different than optional? Can you give a specific example where optional doesn't work?

@@ -208,6 +223,7 @@ Firehose.propTypes = {
selector: PropTypes.object,
fieldSelector: PropTypes.string,
isList: PropTypes.bool,
optional: PropTypes.bool,
optional: PropTypes.bool, // do not block children-rendering while resource is still being loaded
ignoreIfMissing: PropTypes.bool, // do not fail if the resource is missing (HTTP 404)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Someone can opinionate that optional can be reused for that feature, as the difference is quite small.
I prefer to keep semantics of optional as it is, so existing functionality will not be broken.

If not clear otherwise: if optional=true, the children are rendered no matter if loading is still in progress. And eventually causes error 404 afterwards.

With ignoreIfMissing=true only, the rendering is postponed till data are loaded or errored. But 404 is not a blocker for rendering. A child component can still check the error code, but the overall error checking is not affected.

It makes sense to set these props individually same as both together.

Copy link
Member

Choose a reason for hiding this comment

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

Having two similarly-named properties that behave almost the same, but subtly different, makes for a confusing API. I'm still unclear on the difference even after the explaination :) Can't callers check the loaded value if they don't want to render when loading?

I'd prefer either:

  1. Using optional as-is
  2. Changing optional if we think there is better behavior (as long as we can do so without breaking current use)

Copy link
Member

Choose a reason for hiding this comment

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

I only see 5 places where optional is used today, so changing behavior is an option as long we can test / update those places.

Again, I'm still unclear on what's different. Can you give a specific example?

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 found that when reusing StatusBox component.

If optional=true for a single (non-list) object and 404 occurs, the Firehose injects top-level loadError with 404.

With the change proposed in this PR, the ignoreIfMissing resource will not affect the top-level loadError with 404.

My component structure is like:

<Firehose>
  <StatusBox>
     <MyComponent>

I can change behaviour in StatusBox by ignoring the top-level loadError and checking loadError on every loaded resource, but this is more complicated and would introduce more confusion.
Or I can re-implement StatusBox, but this goes against reusability.

Again, expected behaviour by this PR is:

  • optional=true ==> do not postpone rendering but fail on 404
  • ignoreIfMissing=true ==> postpone rendering but ignore 404
  • both set to true ==> do not block rendering and do not fail if 404 - the resource is really optional we do not care about it's availability.

If we change semantics of optional to act like the third option above only, it will be difficult to implement scenario for immediate (non-blocking) rendering of a page/detail and failing asynchronously if missing.
My PRs do not need this feature but I am not sure whether this is not already expected on other places.

Copy link
Member

Choose a reason for hiding this comment

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

If optional=true for a single (non-list) object and 404 occurs, the Firehose injects top-level loadError with 404.

That sounds like a bug. Are we sure that's how optional is intended to behave? Can we simply fix optional? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Such a "fix" would be simple.

I don't see optional defined anywhere except just the code.
It was my natural understanding that optional should ignore 404. But I am not sure whether something is not already relying on recent semantics.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know the history, but I believe it was originally added to avoid 403 errors when you don't have permission. I don't see a reason to handle 404 the same way, though.

The places to check are:

  • frontend/public/components/resource-quota.jsx
  • frontend/public/components/operator-lifecycle-manager/k8s-resource.tsx
  • frontend/public/components/RBAC/role.jsx
  • frontend/public/components/RBAC/bindings.jsx
  • frontend/public/components/cluster-settings/cluster-settings.tsx

I don't see any other usages.

If a resource is `optional: true` then it is excluded from
setting of top-level loadError.

Firehose's child component can still check loadError by
inspecting the resource directly.
@mareklibra
Copy link
Contributor Author

@spadgett , I changed semantics of optional based on discussion and so could remove ignoreIfMissing.
Can you please have a look?

@spadgett
Copy link
Member

/ok-to-test

@openshift-ci-robot openshift-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 13, 2019
@spadgett spadgett added this to the v4.2 milestone Jun 13, 2019
@spadgett spadgett added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jun 13, 2019
Copy link
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

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

/lgtm

@@ -25,8 +25,12 @@ const processReduxId = ({k8s}, props) => {
}

if (!isList) {
Copy link
Member

Choose a reason for hiding this comment

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

Ah, OK. I see now. We didn't have proper support for optional with individual resources, only lists.

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 13, 2019
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mareklibra, spadgett

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 13, 2019
@spadgett spadgett changed the title Firehose: introduce "ignoreIfMissing" resource property Firehose: honor optional prop for watches on individual resources Jun 13, 2019
@spadgett
Copy link
Member

/retest

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit 4653e3a into openshift:master Jun 14, 2019
gnehapk pushed a commit to gnehapk/console that referenced this pull request Jun 25, 2019
…penshift#1711)

* Firehose: introduce "ignoreIfMissing" resource property

If set to `true`, a resource is skipped from generic
`loadError` 404 checking (cross-resources). So the overall data
retrieval does not fail if a specified resource is missing.

Can be used to optionally query a resource but enable rendering
of children if it is missing (HTTP 404).

The new property is an addition to existing `optional` property which
does not block rendering of children if list-retrieval is still in progress.

With default value `ignoreIfMissing = false`, the component is
backward compatible.

* Firehose: fix the `optional` property for 404

If a resource is `optional: true` then it is excluded from
setting of top-level loadError.

Firehose's child component can still check loadError by
inspecting the resource directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants