Skip to content

async client: introduce AsyncClientRequestTracker to keep track of inflight requests and cancel them on destruction#10359

Merged
mattklein123 merged 9 commits intoenvoyproxy:masterfrom
yskopets:feature/introduce-async-request-tracker
Mar 18, 2020
Merged

async client: introduce AsyncClientRequestTracker to keep track of inflight requests and cancel them on destruction#10359
mattklein123 merged 9 commits intoenvoyproxy:masterfrom
yskopets:feature/introduce-async-request-tracker

Conversation

@yskopets
Copy link
Member

Description: introduce AsyncClientRequestTracker to keep track of inflight requests and cancel them on destruction
Risk Level: Low
Testing: unit tests
Docs Changes: N/A
Release Notes: N/A

Context:

Motivation:

  • some tracers implementations, e.g. zipkin and datadog, allow concurrent inflight requests to trace collector
  • it's important to track those requests and cancel them in case tracer gets removed
  • AsyncClientRequestTracker is meant to be reusable in such cases

…inflight requests and cancel them on destruction

Signed-off-by: Yaroslav Skopets <yaroslav@tetrate.io>
@yskopets yskopets force-pushed the feature/introduce-async-request-tracker branch from a2e6ddc to 9117dbd Compare March 13, 2020 07:06
Signed-off-by: Yaroslav Skopets <yaroslav@tetrate.io>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM with small comment. Thank you!

/wait

Signed-off-by: Yaroslav Skopets <yaroslav@tetrate.io>
Signed-off-by: Yaroslav Skopets <yaroslav@tetrate.io>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM w/ 1 small question. Thank you!

/wait-any

Signed-off-by: Yaroslav Skopets <yaroslav@tetrate.io>
Signed-off-by: Yaroslav Skopets <yaroslav@tetrate.io>
Signed-off-by: Yaroslav Skopets <yaroslav@tetrate.io>
* Excludes a given async HTTP request from a set of known active requests.
* @param request request handle
*/
void remove(const AsyncClient::Request& request);
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't make sense to pass a non-const object above and a const object here. I would just pass a non-const in both places and remove the const_cast. Thank you!

/wait

Copy link
Member Author

Choose a reason for hiding this comment

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

AsyncClientRequestTracker::remove() is intended for use in the context of AsyncClient::Callbacks::onSuccess(request, response) and AsyncClient::Callbacks::onFailure(request, reason).

Notice that onSuccess / onFailure methods will now have request as an extra parameter to enable correlation between requests and responses.

The proposed interface for AsyncClient::Callbacks looks like this:

  /**
   * Notifies caller of async HTTP request status.
   *
   * To support a use case where a caller makes multiple requests in parallel,
   * individual callback methods provide request context corresponding to that response.
   */
  class Callbacks {
  public:
    virtual ~Callbacks() = default;

    /**
     * Called when the async HTTP request succeeds.
     * @param request  request handle.
     *                 NOTE: request handle is passed for correlation purposes only, e.g.
     *                 for client code to be able to exclude that handle from a list of
     *                 requests in progress.
     * @param response the HTTP response
     */
    virtual void onSuccess(const Request& request, ResponseMessagePtr&& response) PURE;

    /**
     * Called when the async HTTP request fails.
     * @param request request handle.
     *                NOTE: request handle is passed for correlation purposes only, e.g.
     *                for client code to be able to exclude that handle from a list of
     *                requests in progress.
     * @param reason  failure reason
     */
    virtual void onFailure(const Request& request, FailureReason reason) PURE;
  };

request was made const Request& to prevent any unintended usage, e.g. calling request.cancel().

So, const Request& in Callbacks causes the same in AsyncClientRequestTracker::remove() (otherwise, const_cast will be a part of every call to AsyncClientRequestTracker::remove()).

Do you want me to remove const AsyncClient::Request& from both AsyncClientRequestTracker and Callbacks ?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm OK. Can you add a comment above the const_cast as to why it's required? Thank you.

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 comments

@yskopets yskopets force-pushed the feature/introduce-async-request-tracker branch from 66b309e to 070ffdb Compare March 18, 2020 12:21
Signed-off-by: Yaroslav Skopets <yaroslav@tetrate.io>
Signed-off-by: Yaroslav Skopets <yaroslav@tetrate.io>
@yskopets yskopets force-pushed the feature/introduce-async-request-tracker branch from 070ffdb to 31d55a4 Compare March 18, 2020 12:50
@mattklein123
Copy link
Member

@yskopets friendly request to please never force push. It makes reviews more difficult. Please just add commits and merge master. Thank you!

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thank you!

@mattklein123 mattklein123 merged commit e343412 into envoyproxy:master Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants