Skip to content

Conversation

@maskit
Copy link
Member

@maskit maskit commented Oct 16, 2023

This PR adds below to enable us to implement/improve gate keeping plugins:

  • Metrics that count the numbers of H2 frames (global)
  • Internal counters that counts the number of H2 frames (session)
  • New TS API, TSHttpSsnInfoIntGet, which enables plugins to access the counters

@bneradt
Copy link
Contributor

bneradt commented Oct 17, 2023

[approve ci freebsd]

@bryancall
Copy link
Contributor

The changes look good. It would be great to have metrics on the outgoing frames too.

@maskit maskit added the HTTP/3 label Oct 25, 2023
@maskit maskit changed the title Add metrics for H2 frames and a way to access them from plugins Add metrics for H2/3 frames and a way to access them from plugins Oct 25, 2023
@maskit maskit marked this pull request as ready for review October 25, 2023 19:47
@maskit
Copy link
Member Author

maskit commented Oct 31, 2023

It would be great to have metrics on the outgoing frames too.

The addition is considered. This PR only has code to count incoming frames but the API itself is capable for outgoing frames as well (we'd need to add TS_SSN_INFO_SENT_FRAME_COUNT). Although I personally don't have plans to add code for it (the focus is more on detecting abusive behavior), it'd be nice if somebody could add it.

@maskit maskit added this to the 10.0.0 milestone Oct 31, 2023
bool cur_frame_from_early_data = false;

// Counter for received frames
std::atomic<uint64_t> _frame_counts_in[HTTP2_FRAME_TYPE_MAX + 1] = {
Copy link
Contributor

@bryancall bryancall Nov 6, 2023

Choose a reason for hiding this comment

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

Why doesd this need to be atomic? h2 connections shouldn't be handled on multiple threads.

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 think that is true, but we have a lot of SCOPED_MUTEX_LOCK in http2 code and other counters for H2 use atomic too. I don't want any surprise from this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Is there an index enum for these values?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is Http2FrameType, and HTTP2_FRAME_TYPE_MAX is the last item. We need one extra space for unknown type.

@bneradt
Copy link
Contributor

bneradt commented Nov 7, 2023

[approve ci clang-format]

1 similar comment
@maskit
Copy link
Member Author

maskit commented Nov 8, 2023

[approve ci clang-format]

@bneradt
Copy link
Contributor

bneradt commented Nov 15, 2023

[approve ci format]

@maskit
Copy link
Member Author

maskit commented Nov 29, 2023

@bryancall This passes all CI now. Is the use of atomic a blocker?

@maskit maskit requested a review from bryancall November 29, 2023 16:53
@bneradt
Copy link
Contributor

bneradt commented Dec 1, 2023

[approve ci format]


virtual PoolableSession *get_server_session() const;

virtual uint64_t is_protocol_framed() const;
Copy link
Member

Choose a reason for hiding this comment

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

Why does this return uintr64_t instead of bool, or alternatively why is it named "is_..." when that should indicate a boolean return?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed it to bool.

};

#define TS_SSN_INFO_RECEIVED_FRAME_COUNT_H2_UNKNOWN 999
#define TS_SSN_INFO_RECEIVED_FRAME_COUNT_H3_UNKNOWN 0x21
Copy link
Member

Choose a reason for hiding this comment

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

Why is this 0x21 when the index enum value is 0x0e?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because 0x0e is just an unassigned number (it could be used later for something). 0x21 is reserved for exercising and will never be used.
https://datatracker.ietf.org/doc/html/rfc9114#name-reserved-frame-types

Metrics::Counter::createPtr("proxy.process.http2.max_concurrent_streams_exceeded_in");
http2_rsb.max_concurrent_streams_exceeded_out =
Metrics::Counter::createPtr("proxy.process.http2.max_concurrent_streams_exceeded_out");
http2_rsb.data_frames_in = Metrics::Counter::createPtr("proxy.process.http2.data_frames_in"),
Copy link
Member

@SolidWallOfCode SolidWallOfCode Dec 8, 2023

Choose a reason for hiding this comment

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

Why use these intermediares? Could this be done using a Metric span and indexing?

Or, alternatively,

http2_frame_metrics_in[0] = Metrics::Counter::createPtr("proxy.process.http2.headers_frames_in");

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't we need to have them in http2_rsb?

uint64_t
Http2ClientSession::get_received_frame_count(uint64_t type) const
{
if (type == 999) { // TS_SSN_INFO_RECEIVED_FRAME_COUNT_H2_UNKNOWN in apidefs.h.in
Copy link
Member

@SolidWallOfCode SolidWallOfCode Dec 8, 2023

Choose a reason for hiding this comment

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

Then why not use that definition?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the definition is for plugins.

@bryancall
Copy link
Contributor

@maskit I am seeing this on the failed rockylinux 8 build:

../src/proxy/http3/Http3FrameCounter.cc:24:10: fatal error: api/Metrics.h: No such file or directory
   24 | #include "api/Metrics.h"
      |          ^~~~~~~~~~~~~~~
compilation terminated.

@maskit
Copy link
Member Author

maskit commented Jan 12, 2024

[approve ci autest]

@maskit
Copy link
Member Author

maskit commented Jan 16, 2024

@bryancall I fixed the compile error. PTAL.

@maskit
Copy link
Member Author

maskit commented Jan 25, 2024

[approve ci autest]

@maskit
Copy link
Member Author

maskit commented Jan 25, 2024

@bryancall Resolved merge conflicts.

@maskit maskit merged commit 3c232f4 into apache:master Jan 29, 2024
phongn pushed a commit to phongn/trafficserver that referenced this pull request Feb 1, 2024
@maskit maskit mentioned this pull request Aug 16, 2024
91 tasks
maskit added a commit to maskit/trafficserver that referenced this pull request Aug 20, 2024
maskit added a commit that referenced this pull request Aug 22, 2024
* Update ATS 10 documenation

This is for #10627 and #10306.

* Fix syntax error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants