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

OEP-50 | initial draft of the hooks extension framework #184

Merged
merged 8 commits into from
May 20, 2021

Conversation

felipemontoya
Copy link
Member

This PR converts the previous proposal held in a google doc to a formal OEP

@openedx-webhooks
Copy link

Thanks for the pull request, @felipemontoya! I've created OSPR-5608 to keep track of it in JIRA.

As a core committer in this repo, you can merge this once the pull request is approved per the core committer reviewer requirements and according to the agreement with your edX Champion.

@openedx-webhooks openedx-webhooks added core committer open-source-contribution PR author is not from Axim or 2U waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. labels Feb 5, 2021
@felipemontoya felipemontoya changed the title add: initial draft of the hooks extension framework, OEP-50. OEP-50 | initial draft of the hooks extension framework Feb 5, 2021
@felipemontoya
Copy link
Member Author

Hello all,
I'm tagging everyone who commented in the previous doc to let you know it is now trying to become an OEP.
@nasthagiri, @ormsbee, @pdpinch, @davidjoy, @bradenmacdonald, @morenol, @diegomillan.

@openedx-webhooks openedx-webhooks added engineering review and removed waiting on author PR author needs to resolve review requests, answer questions, fix tests, etc. labels Feb 8, 2021
Copy link
Contributor

@bradenmacdonald bradenmacdonald left a comment

Choose a reason for hiding this comment

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

Thanks @felipemontoya, I am excited to see this.

We had proposed a much simpler and lighter weight mechanism with some similar ideas in openedx/edx-django-utils#64 ; I'm mentioning it because it's like a "filter" hook that can be easily declared for small functions. If there's some way that these hooks will cover that same use case, it would be nice. (However, our use for that was something quite insignificant: changing the algorithm for selecting XBlock icons. I'm not sure if hooks are used for things that small?)

oeps/oep-0050-hooks-extension-framework.rst Show resolved Hide resolved
@pdpinch
Copy link
Contributor

pdpinch commented Feb 28, 2021

very exciting 👍

@felipemontoya
Copy link
Member Author

@bradenmacdonald thanks a lot for your comment on the lightweight mechanism created in openedx/edx-django-utils#64. We studied it during this last weeks to see how we could better design what we are proposing. We ended up drawing more inspiration from the social-core pipelines for their flexibility.

I don't know what the limit should be for the size or complexity of the hooks framework. For now, I started the proposal with what I though was a comprehensive list of locations that covers the entire lifecycle of a user registering, login in, enrolling, interacting with a course, getting a certificate and loging out. Later we added hooks for the course publication lifecycle. In the future we could add more hooks when the system gains traction and we could also make the exposed triggers somewhat configurable. We have in mind to have a big FEATURE SettingFlag that switches the system on/off. Later on this could be more granular.

@felipemontoya felipemontoya force-pushed the fmo/hooks-extension-framework branch from 9b316e0 to 7347384 Compare March 24, 2021 21:12
@felipemontoya
Copy link
Member Author

felipemontoya commented Mar 24, 2021

@nizarmah, @bradenmacdonald. You are both candidates for arbiter of this PR. Given that Braden might also want to be a reviewer I was thinking of writing Nizar in.

Do you agree with this?

Also, this has been as a draft since February and the first working document started getting feedback since August last year.

The latest round of implementation discussion in happening in discuss. The OEP itself has been mostly quiet for a while. Would you agree to give a review period of about a month more, to put a review end date by the 23.04.2021?

@felipemontoya
Copy link
Member Author

@feanil I take from openedx/wg-coordination#5 that you are reviewing this from edX side. Would agree with this date for the OEP as well? Or am I being too aggressive with the timing here?

We have a proposed implementation that already incorporates much of the feedback and we want to move forward with making a PR for that as well. We'll post the link once is up.

@mariajgrimaldi
Copy link
Member

mariajgrimaldi commented Mar 24, 2021

Here's the draft PR where we're implementing the necessary tooling for the Hooks Extension Framework
[BD-32] Hooks Extension Framework: Tooling

Please feel free to leave any comments or feedback!

@bradenmacdonald
Copy link
Contributor

You are both candidates for arbiter of this PR. Given that Braden might also want to be a reviewer I was thinking of writing Nizar in.

I think Nizar would be a great choice! I'm also available if you need a backup :)

@nizarmah
Copy link

nizarmah commented Mar 25, 2021

Thanks @felipemontoya and @bradenmacdonald for the opportunity 😃

The latest round of implementation discussion in happening in discuss. The OEP itself has been mostly quiet for a while. Would you agree to give a review period of about a month more, to put a review end date by the 23.04.2021?

I need to schedule some time tomorrow next week to go over the discussion on discourse. Sorry about that!

@felipemontoya
Copy link
Member Author

I added PR https://github.com/edx/edx-platform/pull/27157 with the first view of how the documentation would look.

Copy link
Contributor

@nasthagiri nasthagiri left a comment

Choose a reason for hiding this comment

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

Thanks for putting this together.

actions called.

Although the first document contains a list of the proposed hooks, we now
proposed that the documentation for this is kept in-code at https://github.com/edx/edx-platform/tree/master/docs/guides.
Copy link
Contributor

Choose a reason for hiding this comment

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

[kudos] I appreciate having the reference doc for these standard APIs be co-located with the codebase that implements those APIs. This also allows other microservices to support such APIs in the future within their own codebase. Though yes, we will focus on enabling this for edx-platform for now.

oeps/oep-0050-hooks-extension-framework.rst Outdated Show resolved Hide resolved
must consider that:

* Most actions will be implemented in plugins.
* The order of execution for multiple actions/filters listening on a trigger
Copy link
Contributor

Choose a reason for hiding this comment

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

[clarification] Where and how is the order of execution defined?

Copy link
Member Author

Choose a reason for hiding this comment

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

With the separation of django signals for events this would be defined via a config dict in django settings. I left the specifics of the format out since they are more of a implementation detail.

https://github.com/edx/open-edx-proposals/pull/184/files#diff-f28146adea40eb552912482a8b24a19107252beba3e25295413bcd5ef8927628R106-R112

via their results. In this case, the actions called at the time will be called
filters.
* Triggers that will not allow the application flow to be altered by the
actions called.
Copy link
Contributor

Choose a reason for hiding this comment

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

[puzzled] This definition of filters versus actions doesn't match what is written in the Wordpress docs.

Filters do not alter the application flow. Instead, they alter the data that is used within the application flow.
Actions halt the application flow, execute the action, and then return back to the normal flow.

What am I missing in my understanding of this proposal?

Copy link
Member Author

Choose a reason for hiding this comment

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

This comment made me clarify a lot of the wording. First I removed "trigger" and "action" from the OEP since it was making it even more complicated. I settled on events and filters (both are kinds of hooks).

I also removed the specific link to the wordpress docs because this proposal is not to copy what Wordpress does, but to be inspired by it.

I clarified the events vs filters part at: https://github.com/edx/open-edx-proposals/pull/184/files#diff-f28146adea40eb552912482a8b24a19107252beba3e25295413bcd5ef8927628R71-R78

======================

The only extension point that will be affected by this OEP is the
REGISTRATION_EXTENSION_FORM. This extension point should still be supported
Copy link
Contributor

Choose a reason for hiding this comment

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

[clarification] Is the proposal to reimplement the current extensibility provided by REGISTRATION_EXTENSION_FORM to instead use this new framework?

Copy link
Member Author

Choose a reason for hiding this comment

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

I made it clear now. Our suggestion is to keep the current feature until it is clear that it can be implemented using hooks and a migration path has been documented


* Django Signals was initially considered as the primary mechanism to connect
triggers and actions, but was ultimately discarded due to the lack of control
of the execution order when more than one action is listening for a trigger.
Copy link
Contributor

Choose a reason for hiding this comment

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

[seeking more information] Django Signals are the standard Django web framework capability for this type of extension. My initial inclination would be to leverage this capability that already exists in our framework, rather than building and maintaining our own.

What use cases do we have that require a pre-defined execution order?
Also, see my question above since it's not clear how this proposal will satisfy this requirement?

Copy link
Member Author

Choose a reason for hiding this comment

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

Now that django signals are back as the mechanism for supporting event hooks, the strict execution order is only there because filters need a way to 'add' or 'reduce' the result of all the functions that were registered.

.. _two types of hooks: https://developer.wordpress.org/plugins/hooks/#actions-vs-filters


Performance Considerations
Copy link
Contributor

Choose a reason for hiding this comment

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

[request] Can we provide some basis for debugging and troubleshooting performance and functional errors? For example, can we include how one might support distributed tracing so we can track (1) how long each hook's implementation takes and (2) reliable traces/logs through multiple hooks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a paragraph at the end of this section about that.

act on it, and return a modified version for the rest of the core-code to use in
the next steps of execution. We intend to make the two kinds of hooks
interchangeable such that developers are not limited by the framework but
instead given maximum flexibility on its usage to attain their extension goals.
Copy link
Contributor

Choose a reason for hiding this comment

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

[strengthening this proposal] It would be great if you could include a few Use Cases (feature-extension examples) for each of the 2 types of hooks. That would bring to light what each hook could enable for the platform.

Copy link
Member Author

Choose a reason for hiding this comment

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

@nizarmah
Copy link

Hello again @felipemontoya! I finally had a chance to go into depth regarding the discussions on discourse, and the proposal and the comments raised.

Would you agree to give a review period of about a month more, to put a review end date by the 23.04.2021?

I think that would be fair or a week after, until 30.04.2021, since some of the discussions on discourse have been getting to a resolution, meanwhile, the ones regarding signals/broadcasts and async are still going on, though.

I do have some comments I was considering posting, but I noticed that the proposal hasn't been updated since February 7; therefore, I was thinking of postponing my comments slightly until you have had the chance to update it based on the discourse discussion.

@felipemontoya
Copy link
Member Author

I updated the oep with the latest feedback.

In summary:

  • clarified the language to use only hooks, events and filters as the main concepts
  • made clear that events will use django signals via a new library containing the definitions
  • added examples of usage
  • included thoughts on async view for django 3.2
  • altogether clarified or resolved the open comments (at least I hope they are resolved now)

@felipemontoya
Copy link
Member Author

@nizarmah @nasthagiri any comments on the current status of this OEP?

Are we ready to merge this latest version?

Copy link

@nizarmah nizarmah left a comment

Choose a reason for hiding this comment

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

@felipemontoya sorry for the late reply. I have a small comment about a possible typo, but as the arbiter of this OEP, I noticed you've addressed the discussion on the forum and the comments on the pull request in the final changes of this OEP.

I'll keep an eye for @nasthagiri's comments and make sure things are addressed and provide my approval again on the pull request.

Thanks for the nice work with the document and the helpful forum updates about the discussions!


Since the creation of the plugin framework different initiatives in the
community have demonstrated success by adopting this pattern. This OEP extends
the range of possible extensions that the patter can hold sustainably.
Copy link

Choose a reason for hiding this comment

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

I'm not sure if patter was intended here, or if it's a typo.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good eyes. It is indeed a typo. I'll fix it quick

Copy link
Contributor

@nasthagiri nasthagiri left a comment

Choose a reason for hiding this comment

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

This looks great! Thank you for leading us in an aligned direction via this PR, the discourse thread, and live discussions.

open edX plugins. Initially, this proposal is meant as a way for community
members to extend the platform, but it could even become a way for the
installation at edx.org to implement some of its particular business rules in a
way that is sufficiently separated from the Open edX core.
Copy link
Contributor

Choose a reason for hiding this comment

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

[+1] Yes, completely agree. Once this framework is in place, it would be good to follow-up with technical refactorings of edx.org specific business logic.

current receivers of an event.


Use Cases
Copy link
Contributor

Choose a reason for hiding this comment

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

[kudos] Excellent examples of use cases. Thx!

common case is to be passed data and return the same of somewhat changed, but
similar data. Other common case would be to receive data and raise an exception
in accordance with the definition of the hook. Most likely to completely halt
the process that would happen after the hook.
Copy link
Contributor

Choose a reason for hiding this comment

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

[appreciation] Nice explanation of the difference between events and filters.

========================

The reference implementation must be completed before this OEP is given "Final"
status. It is not necessary for the "accepted" status.
Copy link
Contributor

Choose a reason for hiding this comment

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

[request] hmm... Can we replace "Final" with "Accepted" and "accepted" with "Provisional"?

The reference implementation must be completed before this OEP is given "Accepted" status. It is not necessary for the "Provisional" status.

Rationale: We don't have any OEPs in the "Final" state and should probably update OEP-1 to exclude that state altogether. "Accepted" is synonymous with the community accepting and adopting the proposal. We did introduce a new state called "Provisional", which means the OEP was reviewed and tentatively accepted while the work is being implemented and piloted.

When possible, hooks should be compatible with the Async Event Messaging
described in OEP-41.
In terms of error handling, the implementation should allow the configuration of
silent failures letting operators know the source of the error.
Copy link
Contributor

Choose a reason for hiding this comment

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

[+1] If I understand this statement correctly, the implementation will have the means to debug issues (logging statements, etc) to help operators understand the root cause of performance and functional issues caused by hooks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but cautiously. By this I mean that we definitely need to put some tooling in place in the implementation to allow debugging and help operators know what is going on. However we also don't want to make the library implementing this bloated by too many extra tools and scaffolding.

@felipemontoya felipemontoya force-pushed the fmo/hooks-extension-framework branch from 0478bec to 13c0f55 Compare May 19, 2021 23:40
@felipemontoya
Copy link
Member Author

Thanks a lot @nasthagiri and @nizarmah. I updated the two suggestions you made and went ahead to make the status be Provisional.

Would agree to merge this in this Provisional state so that we can focus on the discussions at the libraries about naming and ergonomics? I'd like to merge so that this starts to appear at https://open-edx-proposals.readthedocs.io/en/latest/

@nasthagiri
Copy link
Contributor

Yes, go for it. I had approved the PR and we had kept it open for comments already.

@felipemontoya felipemontoya merged commit 1fef39a into master May 20, 2021
@felipemontoya felipemontoya deleted the fmo/hooks-extension-framework branch May 20, 2021 00:10
@openedx-webhooks
Copy link

@felipemontoya 🎉 Your pull request was merged!

Please take a moment to answer a two question survey so we can improve your experience in the future.

@openedx-webhooks
Copy link

@jmbowman, @feanil: thought you might like to know that felipemontoya merged this pull request.

davidjoy pushed a commit that referenced this pull request Nov 2, 2021
OEP-50 | initial draft of the hooks extension framework
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants