Skip to content

Commit

Permalink
refactor: improve wording in glossary and reference it throughout docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mariajgrimaldi committed Nov 4, 2024
1 parent 1712817 commit 4a92546
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 76 deletions.
28 changes: 15 additions & 13 deletions docs/how-tos/create-new-filter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Assumptions
* You have a basic understanding of Python and Django.
* You understand the concept of filters or have reviewed the relevant
:doc:`/concepts/index` docs.
* You are familiar with the terminology used in the project, such as
`:term: filter type<Filter Type>`, `:term: filter signature<Filter Signature>`, etc. If not, you can review the :doc:`/reference/glossary` docs.

Steps
*****
Expand All @@ -34,10 +36,10 @@ Steps

#. Place your filter in an architecture subdomain

As specified in the Architectural Decisions Record (ADR) filter naming and versioning, the filter definition needs an Open edX Architecture
As specified in the Architectural Decisions Record (ADR) filter naming and versioning, the `:term: filter definition<Filter Definition>` needs an Open edX Architecture
Subdomain for:

- The type of the filter: ``{Reverse DNS}.{Architecture Subdomain}.{Subject}.{Action}.{Major Version}``
- The `:term: type of the filter<Filter Type>`: ``{Reverse DNS}.{Architecture Subdomain}.{Subject}.{Action}.{Major Version}``
- The package name where the definition will live, eg. ``learning/``.

For those reasons, after studying your new filter purpose, you must place it in one of the subdomains already in use, or introduce a new subdomain:
Expand All @@ -57,28 +59,28 @@ Steps

Defining the filter's behavior includes:

- Defining the filter type for identification
- Defining the filter's signature
- Defining the `:term: filter type<Filter Type>` for identification
- Defining the `:term: filter signature<Filter Signature>`
- Defining the filter's behavior for stopping the process in which it is being used

The filter type is the name that will be used to identify the filter's and it'd help others identifying its purpose. For example, if you're creating a filter that will be used during the student registration process in the LMS,
according to the documentation, the filter type is defined as follows:
The `:term: filter type<Filter Type>` is the name that will be used to identify the filter's and it'd help others identifying its purpose. For example, if you're creating a filter that will be used during the student registration process in the LMS,
according to the documentation, the `:term: filter type<Filter Type>` is defined as follows:

``{Reverse DNS}.{Architecture Subdomain}.student.registration.requested.{Major Version}``

Where ``student`` is the subject and ``registration.requested`` the action being performed. The major version is the version of the filter, which will be incremented
when a change is made to the filter that is not backwards compatible, as explained in the ADR.

Now that you have the filter type, you'll need to define the filter's signature and overall behavior. The filter's signature, which is the set of parameters that the filter will manipulate, depends on where the filter is located. For example,
if you're creating a filter that will be used during the student registration process in the LMS, the filter's signature will be the set of parameters available for that time for the user. In this case, the filter's signature will be the set of parameters that the registration form sends to the LMS.
Now that you have the `:term: filter type<Filter Type>`, you'll need to define the `:term: filter signature<Filter Signature>` and overall behavior. The `:term: filter signature<Filter Signature>`, which is the set of parameters that the filter will manipulate, depends on where the filter is located. For example,
if you're creating a filter that will be used during the student registration process in the LMS, the `:term: filter signature<Filter Signature>` will be the set of parameters available for that time for the user. In this case, the `:term: filter signature<Filter Signature>` will be the set of parameters that the registration form sends to the LMS.

You can ask yourself the following questions to help you figure out your filter's parameters:

- What is the filter's purpose? (e.g. to validate the student's email address)
- What parameters will the filter need to to that? (e.g. the email address)
- Where in the registration process will the filter be used? (e.g. after the student submits the registration form but before anything else)

With that information, you can define the filter's signature:
With that information, you can define the `:term: filter signature<Filter Signature>`:

- Arguments: ``email``. Since we want this filter to be broadly used, we'll add as much relevant information as possible for the user at that point. As we mentioned above, we can send more information stored in the registration form like ``name`` or ``username``.
- Returns: since filters take in a set of parameters and return a set of parameters, we'll return the same set of parameters that we received.
Expand Down Expand Up @@ -126,8 +128,8 @@ Steps

Some things to note:

- The filter's type is defined in the ``filter_type`` class attribute. In this case, the filter type is ``org.openedx.learning.student.registration.requested.v1``.
- The filter's signature is defined in the ``run_filter`` method. In this case, the signature is the ``form_data`` parameter.
- The filter's type is defined in the ``filter_type`` class attribute. In this case, the `:term: filter type<Filter Type>` is ``org.openedx.learning.student.registration.requested.v1``.
- The `:term: filter signature<Filter Signature>` is defined in the ``run_filter`` method. In this case, the signature is the ``form_data`` parameter.
- The ``run_filter`` is a class method that returns the same set of parameters that it receives.
- The ``run_filter`` class method calls the ``run_pipeline`` method, which is the method that executes the filter's logic. This method is defined in the ``OpenEdxPublicFilter`` class, which is the base class for all the filters in the library. This method returns a dictionary with the following structure:

Expand All @@ -148,7 +150,7 @@ Steps
"form_data": form_data,
}
Where ``form_data`` is the same set of parameters that the filter receives, which is the accumulated output for the filter's pipeline. That is how ``run_filter`` should always look like.
Where ``form_data`` is the same set of parameters that the filter receives, which is the accumulated output for the `:term: filter pipeline<Filter Pipeline>`. That is how ``run_filter`` should always look like.
- The filter's behavior for stopping the process is defined in the ``PreventRegistration`` exception which inherits from the ``OpenEdxFilterException`` base exception. In this case, the exception is raised when the filter stops the registration process. This is done in the service where the filter is being used, which in this case is the LMS.
- The class name is the filter's type ``{Subject}.{Action}`` part in a camel case format. In this case, the filter's name is ``StudentRegistrationRequested``.

Expand Down Expand Up @@ -196,7 +198,7 @@ Steps
self.assertDictContainsSubset(attributes, exception.__dict__)
.. note::
Basically, we're testing the filter's signature and the filter's behavior for stopping the process. The first test is testing the filter's signature, which is the set of parameters that the filter receives and returns. The second test is testing the filter's behavior for stopping the process, which is the exception that is raised when the filter stops the process.
Basically, we're testing the `:term: filter signature<Filter Signature>` and the filter's behavior for stopping the process. The first test is testing the `:term: filter signature<Filter Signature>`, which is the set of parameters that the filter receives and returns. The second test is testing the filter's behavior for stopping the process, which is the exception that is raised when the filter stops the process.

.. .. seealso::

Expand Down
10 changes: 5 additions & 5 deletions docs/how-tos/using-filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ How to use Open edX Filters
---------------------------

Using openedx-filters in your code is very straight forward. We can consider the
various use cases: implementing pipeline steps, attaching/hooking pipelines to filter,
various use cases: implementing `:term: Pipeline Steps<Pipeline Steps>`, attaching/hooking pipelines to filter,
and triggering a filter. We'll also cover how to test the filters you create in your service.


Expand All @@ -11,8 +11,8 @@ Implement pipeline steps

Let's say you want to consult student's information with a third party service
before generating the students certificate. This is a common use case for filters,
where the functions part of the filter's pipeline will perform the consulting tasks and
decide the execution flow for the application. These functions are the pipeline steps,
where the functions part of the `:term: filter pipeline<Filter Pipeline>` will perform the consulting tasks and
decide the execution flow for the application. These functions are the `:term: pipeline steps<Pipeline Steps>`,
and can be implemented in an installable Python library:

.. code-block:: python
Expand Down Expand Up @@ -83,8 +83,8 @@ There's two key components to the implementation:
Attach/hook pipeline to filter
******************************

After implementing the pipeline steps, we have to tell the certificate creation
filter to execute our pipeline.
After implementing the `:term: pipeline steps<Pipeline Steps>`, we have to tell the certificate creation
filter to execute our `:term: pipeline<Filter Pipeline>`.

.. code-block:: python
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/django-plugins-and-filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ file. The dictionary has the following structure:
Create pipeline steps
*********************

In your own plugin, you can create your own pipeline steps by inheriting from ``PipelineStep`` and implementing the
``run_filter`` method. You can find examples of pipeline steps in the ``openedx-filters-samples`` repository. See :doc:`/quickstarts/index` for more details.
In your own plugin, you can create your own `:term: pipeline steps<Pipeline Steps>` by inheriting from ``PipelineStep`` and implementing the
``run_filter`` method. You can find examples of `:term: pipeline steps<Pipeline Steps>` in the ``openedx-filters-samples`` repository. See :doc:`/quickstarts/index` for more details.
74 changes: 18 additions & 56 deletions docs/reference/glossary.rst
Original file line number Diff line number Diff line change
@@ -1,70 +1,32 @@
Open edX Filters Glossary
##########################

This glossary provides definitions for some of the terms to ease the adoption of the Open edX Filters library.
A filter has multiple components, such as pipeline, pipeline steps, filter definition, filter signature, filter type, filter exceptions, filter configuration, etc. This glossary provides definitions for these components.

Here's a brief explanation of each component:

.. glossary::

Pipeline
A pipeline is a list of functions that are executed in order. Each function receives the output of the previous function as input. The output of the last function is the output of the filter itself.
Pipeline
A pipeline is a list of functions executed in a specific order; these functions are known as pipeline steps. Each function in the pipeline takes the output of the previous function as its input, with the final function's output serving as the overall output of the filter. These pipelines are configured in the filter configuration and are executed in sequence.

Pipeline Steps
A pipeline step is a function that receives, manipulates, and returns data. It can be used to transform data, validate it, filter it, enrich it, etc. It's a class that inherits from ``PipelineStep`` that implements the ``run_filter`` method which must match the Open edX Filter signature.
Pipeline Step
A pipeline step is a function within a pipeline that receives, processes, and returns data. Each step may perform operations like transforming, validating, filtering, or enriching data. Pipeline steps are implemented as classes that inherit from a base step class and define specific logic within their ``run_filter`` method, which conforms to the filter's signature.

Filter Definition
A filter definition is the class that implements the ``run_filter`` method, which is usually implemented in this repository for community use. Services invoke it to execute configured pipeline steps.

Open edX Filter signature
It's the signature of each filter's ``run_filter`` method in the class inheriting from ``OpenEdxPublicFilter``. The signature specifies the filter's input and output.

Filter type
It's the filter identifier. It's used to identify the filter in the configuration settings. When configuring the pipeline for a filter, the type is as an index for the filter configuration.
A filter definition is the class that defines the ``run_filter`` method for a filter, specifying the input and output behavior. This class, which inherits from a standard filter base, executes the configured pipeline steps, enabling custom processing within the defined filter.

Filter exceptions
Filter Signature
The filter signature consists of the specific parameters required by a filter's ``run_filter`` method. It defines the expected input and output structure for the filter, detailing the data the filter will process.

Besides acting as a filter, an Open edX Filter can also raise exceptions. These exceptions are used to control the execution of the pipeline. If an exception is raised, the pipeline execution is stopped and the exception is raised again as the output of the pipeline. These exceptions are intentionally raised by the developer during the filter's execution when a condition is met.
Filter Type
The filter type is a unique identifier for the filter, following a standardized format (e.g., reverse DNS style). This type is used as an index for configuring the filter pipeline and specifies which configuration settings apply to a given filter.

Filter configuration
Filter Exceptions
Filters can raise exceptions to control the flow of the pipeline. If a filter raises an exception, the pipeline halts, and the exception becomes the pipeline's output. Exceptions are typically raised when certain conditions specified in the filter's logic are met, signaling an event or state change.

The filter configuration is a dictionary with the configuration settings for the filter. It's used to configure the pipeline for a filter. The configuration settings are specific for each filter type. The dictionary looks like this:

.. code-block:: python
OPEN_EDX_FILTERS_CONFIG = {
"<FILTER EVENT TYPE>": {
"fail_silently": <BOOLEAN>,
"pipeline": [
"<STEP MODULE PATH 0>",
"<STEP MODULE PATH 1>",
...
"<STEP MODULE PATH N-1>",
]
},
}
Where:

- ``<FILTER EVENT TYPE>`` is the filter type.
- ``fail_silently`` is a boolean value.

If ``fail_silently`` is ``True``: when a pipeline step raises a runtime exception -- like ``ImportError`` or ``AttributeError`` exceptions which are not intentionally raised by the developer during the filter's execution; the exception won't be propagated and the pipeline execution will resume, i.e the next steps will be executed
If ``fail_silently`` is ``False``: the exception will be propagated and the pipeline execution will stop.

For example, with this configuration:

.. code-block:: python
OPEN_EDX_FILTERS_CONFIG = {
"<FILTER EVENT TYPE>": {
"fail_silently": True,
"pipeline": [
"non_existing_module.non_existing_function",
"existing_module.function_raising_attribute_error",
"existing_module.existing_function",
]
},
}
The pipeline tooling will catch the ``ImportError`` exception raised by the first step and the ``AttributeError`` exception raised by the second step, then continue and execute the third step. Now, if ``fail_silently`` is ``False``, the pipeline tooling will catch the ``ImportError`` exception raised by the first step and propagate it, i.e the pipeline execution will stop.
Filter Configuration
Filter configuration is a dictionary that defines the pipeline settings for a filter. Each filter type has its own configuration, which includes settings like whether errors should fail silently or propagate, and the sequence of pipeline steps. Configurations specify the filter type, error-handling preferences, and a list of module paths for each pipeline step to be executed.

- ``pipeline`` is list of paths for each pipeline step. Each path is a string with the following format: ``<MODULE PATH>.<CLASS NAME>``. The module path is the path to the module where the pipeline step class is defined and the class name is the name of the class that implements the ``run_filter`` method to be executed.
.. note::
In practice, "filter" is used to refer to the whole mechanism, including the pipeline steps, filter definition and so on.

0 comments on commit 4a92546

Please sign in to comment.