telefonicaid / fiware-orion

Context Broker and CEF building block for context data management, providing NGSI interfaces.
https://github.com/telefonicaid/fiware-orion/blob/master/doc/manuals/orion-api.md
GNU Affero General Public License v3.0
210 stars 265 forks source link

Request to implement pagination for request forwarding. #4149

Closed Anjali-NEC closed 1 year ago

Anjali-NEC commented 2 years ago

We know that the community has the following deprecated and to be discontinued the opinion regarding request forwarding (and pagination at the time of request forwarding) using the registrations/context providers functionality. https://github.com/telefonicaid/fiware-orion/issues/3108#issuecomment-1027672998 2501

https://github.com/telefonicaid/fiware-orion/issues/3263#issuecomment-1068136490 25-02

However, we would like to realize it with Orion as a contact point for information that each company and local government (context provider) has. We think that using the request forwarding function is effective for the following reasons.

Orion community has considered two ways to deal with it in the past. We would like to consider and implement in the direction of the second plan. https://github.com/telefonicaid/fiware-orion/issues/847#issuecomment-107379768 25-03

We devised a way to use no creDate based on the above second plan. please check the diagram below. If this can be implemented, the context consumer will be able to get all the data of the context providers. Please consider the implementation. 25-04

mapedraza commented 2 years ago

After some internal discussion of the Orion development team, we arrive that there it makes no sense to implements those features inside the Broker. Context registrations codebase present in Orion would need a lot of work to solve all the pending issues and to have this functionalities. Not only pagination, filtering is also a known problem.

Instead, we thought that the best way to implement the functionalities you are proposing to cover the described scenario is to develop a micro service that handle registrations to different Context Providers and serves the information to the Context Consumer. This microservice can be part of the Orion project hosted in the same repository, but could be implemented in a different programming language (such as Node.js or Python).

What we propose would have the following architecture: CSM docx

In fact, this strategy is pretty similar to the one implemented by MongoDB sharding cluster. The success of such solution in MongoDB proves that it could also be a good alternative in the context management domain. You can check the as reference the mongo documentation here

The advantage of separating this into a different service are severals (our proposal):

The disadvantages of implementing requested features in Orion codebase (your proposal):

What do you think? Would you like to progress in a solution as we propose?

Anjali-NEC commented 2 years ago

@fgalan @mapedraza

Thank you for your suggestions for Context Shard Manager. But I want to consider adding features to Orion again.

After some internal discussion of the Orion development team, we arrive that there it makes no sense to implements those features inside the Broker. Context registrations codebase present in Orion would need a lot of work to solve all the pending issues and to have this functionalities. Not only pagination, filtering is also a known problem.

I understand that it is quite difficult to resolve all pending issues. Would you like to suspend the modification of query filtering this time and narrow down the modification target to pagination (#847) ? Pagination makes client to get all information available to the context provider through Orion, the contact point for information. If all the data is available, the client can handle the filtering.

After narrowing down the correction points as shown below, it may be possible to minimize the amount of correction by making corrections on the Orion.

Anjali-NEC commented 2 years ago
@fgalan @mapedraza

Thank you for your suggestions for Context Shard Manager.
But I want to consider adding features to Orion again.

After some internal discussion of the Orion development team, we arrive that there it makes no sense to implements those features inside the Broker. Context registrations codebase present in Orion would need a lot of work to solve all the pending issues and to have this functionalities. Not only pagination, filtering is also a known problem.

I understand that it is quite difficult to resolve all pending issues.
Would you like to suspend the modification of query filtering this time and narrow down the modification target to pagination (https://github.com/telefonicaid/fiware-orion/issues/847) ?
Pagination makes client to get all information available to the context provider through Orion, the contact point for information.
If all the data is available, the client can handle the filtering.

After narrowing down the correction points as shown below, it may be possible to minimize the amount of correction by making corrections on the Orion.

Targets the getting API of multiple entities. Updates and deletions are excluded from the correction target.
NGSIv1 ("details": "Count:") and NGSIv2 ("Fiware-Total-Count:) returns the total number of entities of itself and all context providers in.
Allows the client to get the context broker itself and all context provider entities by specifying limits and offsets.
Filtering functions are complicated and difficult to modify, so we will not support it this time@fgalan @mapedraza

Thank you for your suggestions for Context Shard Manager.
But I want to consider adding features to Orion again.

After some internal discussion of the Orion development team, we arrive that there it makes no sense to implements those features inside the Broker. Context registrations codebase present in Orion would need a lot of work to solve all the pending issues and to have this functionalities. Not only pagination, filtering is also a known problem.

I understand that it is quite difficult to resolve all pending issues.
Would you like to suspend the modification of query filtering this time and narrow down the modification target to pagination (https://github.com/telefonicaid/fiware-orion/issues/847) ?
Pagination makes client to get all information available to the context provider through Orion, the contact point for information.
If all the data is available, the client can handle the filtering.

After narrowing down the correction points as shown below, it may be possible to minimize the amount of correction by making corrections on the Orion.

Targets the getting API of multiple entities. Updates and deletions are excluded from the correction target.
NGSIv1 ("details": "Count:") and NGSIv2 ("Fiware-Total-Count:) returns the total number of entities of itself and all context providers in.
Allows the client to get the context broker itself and all context provider entities by specifying limits and offsets.
Filtering functions are complicated and difficult to modify, so we will not support it this time..

Hi @fgalan @mapedraza

Please provide your response on it. Thanks

fgalan commented 2 years ago

@Anjali-NEC so if I have understand correctly your proposal is not to work in the line described by @mapedraza at https://github.com/telefonicaid/fiware-orion/issues/4149#issuecomment-1151178321 but focus only in the CPr pagination issue. Is my understanding correct?

In that case, I'd like to clarify what are you exactly proposing, please. Examples may help.

Thus, taking into account your picture:

imagen

Let's name CPrs A, B and C (from left to right).

Let's assume we have the following situation in a given moment:

Which entities (order matters) the following queries will return?

Anjali-NEC commented 2 years ago

@Anjali-NEC so if I have understand correctly your proposal is not to work in the line described by @mapedraza at #4149 (comment) but focus only in the CPr pagination issue. Is my understanding correct?

Yes your understanding is correct.

In that case, I'd like to clarify what are you exactly proposing, please. Examples may help.

Thus, taking into account your picture: orion_requestforwarding_pagination

Let's name CPrs A, B and C (from left to right).

Let's assume we have the following situation in a given moment:

In CB we have E1 created at time 1 E2 created at time 2 E3 created at time 3 In CPra A we have EA1 created at time 1.1 EA2 created at time 2.2 EA3 created at time 3.3 In CPra B we have: EB1 created at time 1.2 EB2 created at time 2.1 EB3 created at time 3.2 In CPra C we have: EC1 created at time 1.3 EC2 created at time 2.3 EC3 created at time 3.1 Which entities (order matters) the following queries will return?

GET /v2/entities

It will return all the entities of CB, CPra A, CPra B, CPra C based on the registration order of ContextProvider in CB and the registration order of Entities in CP.

If you register in CP in the order of CPra A, CPra B, CPra C. It will return the response in the following order:

{E1, E2, E3, EA1, EA2, EA3, EB1, EB2, EB3, EC1, EC2, EC3}

GET /v2/entities?orderBy=dateCreated

This time, only offset, limit, option=count is modifying target, so orderBy does not work and returns the same result as GET /v2/entities.

{E1, E2, E3, EA1, EA2, EA3, EB1, EB2, EB3, EC1, EC2, EC3}

However, when supporting orderBy in the future, the responses of CB, CPra A, CPra B, CPra C will be sorted by the orderBy condition and returned.

Orion_with_CP

The order of CPra A, CPra B, CPra C is guaranteed on the CP side, so CB just performs a mergesort. CB does not need to get all CP responses at once. CB can be sorted while getting CP response by pagination.

GET /v2/entities?offset=2&limit=3

The pagination parameters will apply on the basis of the order of CPrs. the limit and offset to be passed to ContextProvider while taking into account the order of ContextProvider registration.

{E3, EA1, EA2}

GET /v2/entities?offset=2&limit=3&orderBy=dateCreated

If orderBy is not implemented, it will return below output:

{E3, EA1, EA2}

It will be {EB1, EC1, E2} in the orderBy implementation.

GET /v2/entities?offset=5&limit=4

This will return below data:

{EA3, EB1, EB2, EB3}

GET /v2/entities?offset=5&limit=4&orderBy=dateCreated

If orderBy is not implemented, it will return below output:

{EA3, EB1, EB2, EB3}

It will be {EB2, EA2, EC2, E3} in the orderBy implementation.

Anjali-NEC commented 2 years ago

Hi @fgalan @mapedraza

We have done some investigation on how the pagination feature laid out in case of request forwarding and how it will be implemented. we have classified some function on the basis of sequence diagram flow and the details of the function which need to be modified for the implementation of pagination in case of request forwarding are given below.

Please find below my solution approach and please let us know if you have any suggestion.

As per my analysis below is the updated sequence diagram regarding the implementation of pagination in request forwarding:

mongoQueryContext Sequence Diagram

Note: Reference of above image is taken from below link: https://github.com/telefonicaid/fiware-orion/blob/3.6.0/doc/manuals/devel/mongoBackend.md#mongoquerycontext-sr

Sequence Diagram01

Note: Reference of above image is taken from below link: https://github.com/telefonicaid/fiware-orion/blob/3.6.0/doc/manuals/devel/mongoBackend.md#mongodiscovercontextavailability-sr

Function list in which changes required

As per the current understanding of code and sequence diagram, below table contains the details of modification corresponding to the target functions to implementing the pagination feature in case of request forwarding

<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

File name | Function name | Change point -- | -- | -- src/lib/mongoBackend/mongoQueryContext.cpp | mongoQueryContext() | Currently only the default value of the pagination parameters is received. Need to add code for getting the value of limit, offset and count which is provided by the context consumer and manage them. src/lib/mongoBackend/MongoGlobal.cpp | registrationsQuery() | Need to modify registrationsQuery function to get the exact value of pagination parameters which is pass by context consumer in this function. src/lib/mongoBackend/mongoDiscoverContextAvailability.cpp | processDiscoverContextAvailability() | Need to add code to pass the value of pagination parameters to the context Provider. src/lib/mongoBackend/mongoDiscoverContextAvailability.cpp | mongoDiscoverContextAvailability() | Need to change code for the context availability discovery (NGSIv1) operation in order to add the logic for provider ordering is unique and pagination parameters pass on the basis of that. src/lib/mongoBackend/MongoCommonUpdate.cpp | searchContextProviders() | It uses registrationsQuery() in order to locate Context Providers for forwarding of the update. might be need to change the logic and add code according to the registrationsQuery(). src/lib/mongoBackend/mongoQueryContext.cpp | processGenericEntities() | Need to add code for addition of entities from each contextProvider which is needed in the case of the pagination if limit is not reached with local entities src/lib/mongoBackend/mongoQueryContext.cpp | addContextProviders() | Need to add code for manage entities from each contextProvider if limit is not reached with local entities src/lib/ngsi10/QueryContextRequest.cpp | QueryContextRequest() | mongoQueryContext() uses a QueryContextRequest object as input parameter and a QueryContextResponse as output parameter. Its purpose is to build a response object based on a request object and entities and registrations. Need to change in request that it takes the pagination parameters in request and give the response according to the pagination parameters src/lib/serviceRoutines/postQueryContext.cpp | queryForward() | queryForward() forward the query request to the context provider Need to change that function so that the pagination parameters also forwarded to the context provider src/lib/ mongoDriver/connectionOperations.cpp | collectionRangedQuery() | collectionRangedQuery() is called in order to do the actual query in the database Currently default value of limit, offset is passed in collectionRangedQuery(). Need to pass the value given by context consumer

Anjali-NEC commented 2 years ago

@fgalan @mapedraza

We have started working on implementing this feature with the shared implementation approach. please let us know if you have any query or concern.

Anjali-NEC commented 1 year ago

@fgalan @mapedraza Gentle Reminder!!

Please let us know the feedback on the shared approach to fix this issue.

fgalan commented 1 year ago

I'm sorry we don't have time to provide feedback on #4149 in a timely manner taking into account the urgency it has for you and that it is not part of the roadmap. Issues that are in the roadmap are the ones in which focus our feedback and review effort.

Thus, go ahead with the implementation of #4149 without waiting for our feedback and we will see the PR when it comes. At that moment we have another feedback point.

ArqamFarooqui110719 commented 1 year ago

Hi @fgalan, Is there any plan to review PR of this issue i.e. PR #4275?

fgalan commented 1 year ago

Hi @fgalan, Is there any plan to review PR of this issue i.e. PR #4275?

Yes. It is planned. However, we cannot commit on a date. The review will be done in a best-effort way.

ArqamFarooqui110719 commented 1 year ago

Gentle Reminder... Hi @fgalan, Is there any possibility to review the PR in this month?

fgalan commented 1 year ago

Gentle Reminder... Hi @fgalan, Is there any possibility to review the PR in this month?

I have done a first round or review. Please find my comments in the PR itself.

ArqamFarooqui110719 commented 1 year ago

Hi, As both the PRs (#4275 and #4352 ) have been merged, So we can close these issues (#4149 and #4341) now?

fgalan commented 1 year ago

I'd suggest to wait to close this issues until PR https://github.com/telefonicaid/fiware-orion/pull/4341 gets merged.

ArqamFarooqui110719 commented 1 year ago

As the PR #4341 also got merged, Now we can close the issue #4149 (and other related issues, for e.g. #847)?

fgalan commented 1 year ago

As the PR #4341 also got merged, Now we can close the issue #4149 (and other related issues, for e.g. #847)?

Yes, that issues (along with #1647) will be closed.

However, I have discovered that this other issue, which is related with pagination and CPrs is not solved: https://github.com/telefonicaid/fiware-orion/issues/1025#issuecomment-1584403726. Please, have a look.