Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stats: Improved sequencing documentation for server-side stats events and added tests. #7885

Open
wants to merge 30 commits into
base: master
Choose a base branch
from

Conversation

RyanBlaney
Copy link

Response to Issue #7824

RELEASE NOTES:

  • Documentation Clarification: Clarified the expected sequencing of stats events in the server-side stats.Handler.
  • New Test Cases: Added tests to verify the event sequencing for various RPC types, ensuring consistency and accuracy in server-side stats handling.

…s to verify the order of server-side events.
@RyanBlaney RyanBlaney changed the title Documentation, Test: Improved sequencing documentation for server-side stats events and added tests. *: Improved sequencing documentation for server-side stats events and added tests. Dec 2, 2024
Copy link

codecov bot commented Dec 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.25%. Comparing base (4c07bca) to head (b16e1fb).
Report is 131 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7885      +/-   ##
==========================================
+ Coverage   81.84%   82.25%   +0.40%     
==========================================
  Files         377      392      +15     
  Lines       38120    39140    +1020     
==========================================
+ Hits        31201    32194     +993     
- Misses       5603     5610       +7     
- Partials     1316     1336      +20     
Files with missing lines Coverage Δ
stats/stats.go 68.42% <ø> (ø)

... and 126 files with indirect coverage changes

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@RyanBlaney RyanBlaney marked this pull request as ready for review December 2, 2024 03:13
@arjan-bal arjan-bal changed the title *: Improved sequencing documentation for server-side stats events and added tests. stats: Improved sequencing documentation for server-side stats events and added tests. Dec 2, 2024
@arjan-bal arjan-bal self-requested a review December 2, 2024 09:25
@arjan-bal arjan-bal self-assigned this Dec 2, 2024
@arjan-bal arjan-bal added the Type: Documentation Documentation or examples label Dec 2, 2024
@arjan-bal arjan-bal added this to the 1.69 Release milestone Dec 2, 2024
Comment on lines 153 to 156
func (s *testServer) UnaryCall(
ctx context.Context,
in *testpb.SimpleRequest,
) (*testpb.SimpleResponse, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

grpc-go follows the Google style guide. Based on this section in the style guide:

The signature of a function or method declaration should remain on a single line to avoid indentation confusion.

Please revert the changes made to wrap function definationations and calls throughout the PR.

Copy link
Author

Choose a reason for hiding this comment

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

Got it! I'll disable my autoformatter going forward or reconfigure it to follow the Google style guide.

@@ -786,8 +884,14 @@ func checkConnEnd(t *testing.T, d *gotData) {
st.IsClient() // TODO remove this.
}

type event struct {
eventType string
timestamp time.Time
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the use of storing a timestamp? I believe we're only interested in the ordering of the events and not the absolute times they were emitted.

Copy link
Author

Choose a reason for hiding this comment

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

The timestamp was included for debugging purposes in case of test failures, since it could help identify delays or other issues. If you feel this isn’t valuable, I can to remove it for simplicity.

@RyanBlaney
Copy link
Author

I have fixed the wrapping errors for formatting and I removed the timestamps from the event structs. Thank you for your feedback @arjan-bal, is there anything else you need me to do?

…. Added a server stats Server Stream RPC test.
@arjan-bal arjan-bal assigned arjan-bal and unassigned RyanBlaney Dec 3, 2024
@purnesh42H purnesh42H assigned purnesh42H and unassigned arjan-bal Dec 3, 2024
@arjan-bal arjan-bal requested review from purnesh42H and arjan-bal and removed request for arjan-bal December 3, 2024 08:01
@purnesh42H purnesh42H modified the milestones: 1.69 Release, 1.70 Release Dec 5, 2024
@@ -81,6 +83,55 @@ var (
}
// The id for which the service handler should return error.
errorID int32 = 32202

// Server Stats
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix the documentation everywhere. Remove extra spaces at start and end etc.

Copy link
Author

Choose a reason for hiding this comment

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

Everything should be resolved now. Thank you for your help!

@purnesh42H
Copy link
Contributor

purnesh42H commented Feb 4, 2025

@RyanBlaney is it ready for re-review? I see that you have commits for the last comments.

Also, since its been called out, you can revert the style changes for want/expect in existing code but keep want/wantData in the new code that you have written. This is just to make code review focused on new changes. Thanks.

@github-actions github-actions bot removed the stale label Feb 4, 2025
@RyanBlaney
Copy link
Author

Yes, it should be ready! Everything new that I added is using want instead of expected.


select {
case <-ctx.Done():
t.Fatalf("Timed out waiting for events to propagate: Diff (-got +want):\n%s", cmp.Diff(eventCount, len(wantUnarySequence)))
Copy link
Member

Choose a reason for hiding this comment

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

These are just single integers, so using cmp.Diff is just going to make it hard to read. Please change to:

Suggested change
t.Fatalf("Timed out waiting for events to propagate: Diff (-got +want):\n%s", cmp.Diff(eventCount, len(wantUnarySequence)))
t.Fatalf("Timed out waiting for events to propagate. Got %v events; want %v", eventCount, len(wantUnarySequence))


select {
case <-ctx.Done():
t.Fatalf("Timed out waiting for events to propagate: Diff (-got +want):\n%s", cmp.Diff(eventCount, len(wantClientStreamSequence)))
Copy link
Member

Choose a reason for hiding this comment

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

As above.

h.mu.Lock()
defer h.mu.Unlock()
h.gotConn = append(h.gotConn, &gotData{ctx, s.IsClient(), s})
}

func (h *statshandler) HandleRPC(ctx context.Context, s stats.RPCStats) {
switch s.(type) {
case *stats.Begin:
h.recordEvent("Begin")
Copy link
Member

Choose a reason for hiding this comment

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

Could you define constants for these strings please?

@RyanBlaney
Copy link
Author

This PR should be complete, although there are a few more changes I want to make for a second PR.

Implement all TODO tests

  • There are several TODO statements left throughout the code, so I will implement the tests as needed.
  • Test OutTrailer
  • Remove IsClient call (2 instances)

Possible logic error

  • The docs state that the CompressedLength should be equal to the Length if compression is disabled.
  • The Length in this case is the uncompressed InPayload data
	// TODO: check values of WireLength and RecvTime.
	if st.Length > 0 && st.CompressedLength == 0 {
		t.Fatalf("st.WireLength = %v with non-empty data, want <non-zero>",
			st.CompressedLength)
	}

Fix deprecated tests

Diagnostics:
grpc.RPCCompressor is deprecated: use encoding.RegisterCompressor instead. Will be supported throughout 1.x. [default]

Diagnostics:
grpc.NewGZIPCompressor is deprecated: use package encoding/gzip. [default]

Diagnostics:
grpc.RPCDecompressor is deprecated: use encoding.RegisterCompressor instead. Will be supported throughout 1.x. [default]

Diagnostics:
grpc.NewGZIPDecompressor is deprecated: use package encoding/gzip. [default]

Diagnostics:
grpc.WithBlock is deprecated: this DialOption is not supported by NewClient. Will be supported throughout 1.x. [default]

Diagnostics:
grpc.Dial is deprecated: use NewClient instead.  Will be supported throughout 1.x. [default]

@arjan-bal arjan-bal modified the milestones: 1.71 Release, 1.72 Release Feb 19, 2025
@RyanBlaney RyanBlaney removed their assignment Feb 19, 2025
Copy link

This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed.

stats/stats.go Outdated
// InHeader contains stats about header reception.
//
// - Server-side: The first stats event after the RPC request is received.
// - Client-side: Occurs after the `OutPayload` event (after the request payload is sent).
Copy link
Member

Choose a reason for hiding this comment

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

This isn't quite true. InHeader comes any time after OutHeader. This is especially true for bidi- or client- streaming RPCs, since OutPayload isn't guaranteed to come right after OutHeader, like it is for unary or server-streaming RPCs.

Maybe exclude the note about client-side here, but you can add a note to OutHeader for Client-side that says something like Only occurs after 'Begin', as headers are always the first thing sent on a stream.

@@ -800,13 +803,52 @@ func (h *statshandler) TagRPC(ctx context.Context, info *stats.RPCTagInfo) conte
return context.WithValue(ctx, rpcCtxKey{}, info)
}

// recordEvent records an event in the statshandler along with a timestamp.
func (h *statshandler) recordEvent(eventType string) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we need any of this now? I don't think anyone reads this field since the new tests were removed.

Copy link
Author

Choose a reason for hiding this comment

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

Nope! Forgot to remove this. Thanks!

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