Skip to content

ext_proc http bytes tracking support - #37297

Merged
yanavlasov merged 10 commits into
envoyproxy:mainfrom
yanjunxiang-google:ext_proc_http_billing
Dec 6, 2024
Merged

yanavlasov merged 10 commits into
envoyproxy:mainfrom
yanjunxiang-google:ext_proc_http_billing

Conversation

@yanjunxiang-google

@yanjunxiang-google yanjunxiang-google commented Nov 21, 2024 •

Copy link
Copy Markdown
Contributor

This is a follow up PR of: #35740.

This PR added the bytes tracking support for ext_proc http service, which basically is counting how many bytes are sent to and received from ext_proc HTTP service.

It takes the stream_info from the active HTTP request, and saved in the ext_proc filter. When the external processing completes, the bytes counters from the stream_info are retrieved and stored into the filter state.

The existing logging test filter is leveraged to test the byte counters in the filter state are correctly updated.

@repokitteh-read-only

Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #37297 was opened by yanjunxiang-google.

see: more, trace.

@yanjunxiang-google
yanjunxiang-google marked this pull request as ready for review November 25, 2024 16:06
Signed-off-by: Yanjun Xiang <[email protected]>
Signed-off-by: Yanjun Xiang <[email protected]>
@yanjunxiang-google

Copy link
Copy Markdown
Contributor Author

/assign @tyxia @yanavlasov

@yanjunxiang-google

Copy link
Copy Markdown
Contributor Author

/retest

@yanjunxiang-google

Copy link
Copy Markdown
Contributor Author

Kind Ping!

@yanjunxiang-google

Copy link
Copy Markdown
Contributor Author

Kind ping!

@tyxia tyxia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for working on this.

void Filter::logStreamInfo() {
if (!config().grpcService().has_value()) {
// HTTP service
logStreamInfoBase(stream_info_http_);

@tyxia tyxia Dec 2, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to cache stream_info_http_ and setStreamInfo function?

Can we get access to this through existing members and active_requests_, similar to gRPC below?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure. We can add a new interface: client->getStreamInfo() to retrieve streamInfo() from active_request_.

if (active_request_ != nullptr) {
Buffer::OwnedImpl body(req_in_json.value());
active_request_->sendData(body, true);
callbacks_->setStreamInfo(&active_request_->streamInfo());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This PR is missing setting the upstreamClusterInfo() in logging_info

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch! done

@tyxia

tyxia commented Dec 2, 2024

Copy link
Copy Markdown
Member

/wait

Signed-off-by: Yanjun Xiang <[email protected]>
Signed-off-by: Yanjun Xiang <[email protected]>
Signed-off-by: Yanjun Xiang <[email protected]>
@yanjunxiang-google

Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@yanjunxiang-google

Copy link
Copy Markdown
Contributor Author

/retest

@tyxia tyxia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/wait

}

void ExtProcHttpClient::onError() {
// Cancel if the request is active.

@tyxia tyxia Dec 5, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like there is behavior change in this revision. Can you elaborate why we are removing this line? but still keeping cancel() in the code base.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's a good question.

However, there is no logic change here. The cancel() call is dead code here as from the context, the onError() is always called after active_request_ is set to nullptr. And with active_request_ == nullptr, cancel() is no-op.

BTW, cancel() call is only needed in the context when the ext_proc filter is destroyed:

Another thing is that this PR is trying to move the "active_request_ = nullptr" to after callbacks_->onComplete() and callbacks_->onError() call finished, as these calls will use active_request_ to get the stream_info.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK then original ext_proc http code has redundancy that is cleaned up here

callbacks_->onError();
callbacks_ = nullptr;
}
active_request_ = nullptr;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Compared with previous code, it seems that you are missing active_request_->cancel();?

why cancel() is removed from this function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Please check comments above.

@tyxia tyxia left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@yanavlasov
yanavlasov merged commit 57fa0e0 into envoyproxy:main Dec 6, 2024
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.

3 participants