Skip to content

stats/opentelemetry: add trace event for name resolution delay #8074

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

Merged
merged 68 commits into from
Apr 4, 2025

Conversation

vinothkumarr227
Copy link
Contributor

@vinothkumarr227 vinothkumarr227 commented Feb 10, 2025

stats/opentelemetry: add trace event for name resolution delay.

RELEASE NOTES:

  • stats/opentelemetry: add trace event for name resolution delay.

Copy link

codecov bot commented Feb 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.03%. Comparing base (775150f) to head (3974776).
Report is 18 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8074      +/-   ##
==========================================
- Coverage   82.25%   82.03%   -0.23%     
==========================================
  Files         393      410      +17     
  Lines       39143    40248    +1105     
==========================================
+ Hits        32197    33016     +819     
- Misses       5616     5867     +251     
- Partials     1330     1365      +35     
Files with missing lines Coverage Δ
clientconn.go 90.56% <100.00%> (+<0.01%) ⬆️
internal/internal.go 100.00% <100.00%> (ø)
stats/opentelemetry/client_metrics.go 89.39% <100.00%> (ø)
stats/opentelemetry/client_tracing.go 84.00% <100.00%> (+7.52%) ⬆️
stats/opentelemetry/opentelemetry.go 75.00% <ø> (ø)
stream.go 81.55% <100.00%> (+0.03%) ⬆️

... and 57 files with indirect coverage changes

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

@arjan-bal arjan-bal requested a review from purnesh42H February 17, 2025 07:16
@arjan-bal arjan-bal added this to the 1.71 Release milestone Feb 17, 2025
@arjan-bal arjan-bal added Type: Feature New features or improvements in behavior Area: Observability Includes Stats, Tracing, Channelz, Healthz, Binlog, Reflection, Admin, GCP Observability labels Feb 17, 2025
@purnesh42H purnesh42H assigned dfawley and unassigned vinothkumarr227 Apr 1, 2025
Comment on lines 273 to 274
// When set, the function should be called before the stream enters
// the blocking state.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// When set, the function should be called before the stream enters
// the blocking state.
// When set, the function will be called before the stream enters
// the blocking state.

Nit: "Should" implies uncertainty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

clientconn.go Outdated
Comment on lines 710 to 712
if internal.NewStreamWaitingForResolver != nil {
internal.NewStreamWaitingForResolver()
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if internal.NewStreamWaitingForResolver != nil {
internal.NewStreamWaitingForResolver()
}
internal.NewStreamWaitingForResolver()

(Combine with suggestion below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// used in tests to synchronize resolver updates and avoid race conditions.
// When set, the function should be called before the stream enters
// the blocking state.
NewStreamWaitingForResolver func()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
NewStreamWaitingForResolver func()
NewStreamWaitingForResolver = func() {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// Add grpcsync.Event to coordinate timing
resolutionWait := grpcsync.NewEvent()
prevHook := internal.NewStreamWaitingForResolver
internal.NewStreamWaitingForResolver = func() { _ = resolutionWait.Fire() }
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
internal.NewStreamWaitingForResolver = func() { _ = resolutionWait.Fire() }
internal.NewStreamWaitingForResolver = func() { resolutionWait.Fire() }

I think this won't fail vet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it won’t fail vet. I’ve made the changes.

if err != nil {
return err
}
if err := stream.Send(&testpb.StreamingOutputCallRequest{}); err != nil && err != io.EOF {
Copy link
Member

Choose a reason for hiding this comment

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

Why the io.EOF check here? The server should never exit until the client does CloseSend.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion; I have removed it.

Comment on lines 1687 to 1689
time.AfterFunc(100*time.Millisecond, func() {
rb.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: ss.Address}}})
})
Copy link
Member

Choose a reason for hiding this comment

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

This will have the same race as in the other tests. It should inject something to hook the resolver blocking, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’ve updated the test to set this to a grpcsync.Event.Fire

if !match {
t.Errorf("Expected span not found: %q (kind: %s)", want.name, want.spanKind)
}

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 1587 to 1591
headerAttempts := len(md["grpc-previous-rpc-attempts"])
if headerAttempts >= 1 {
return &testpb.SimpleResponse{}, nil
}
return nil, status.Error(codes.Unavailable, fmt.Sprintf("retry (%d)", headerAttempts))
Copy link
Member

Choose a reason for hiding this comment

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

I think you want something more like this

Suggested change
headerAttempts := len(md["grpc-previous-rpc-attempts"])
if headerAttempts >= 1 {
return &testpb.SimpleResponse{}, nil
}
return nil, status.Error(codes.Unavailable, fmt.Sprintf("retry (%d)", headerAttempts))
headerAttempts := 0
if h := md["grpc-previous-rpc-attempts"]; len(h) > 0 {
headerAttempts = h[0]
}
if headerAttempts < 2 {
return nil, status.Errorf(codes.Unavailable, "retry (%d)", headerAttempts)
}
return &testpb.SimpleResponse{}, nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return &stubserver.StubServer{
FullDuplexCallF: func(stream testgrpc.TestService_FullDuplexCallServer) error {
md, _ := metadata.FromIncomingContext(stream.Context())
headerAttempts := len(md["grpc-previous-rpc-attempts"])
Copy link
Member

Choose a reason for hiding this comment

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

Similar to above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
}

func waitForReady(cc *grpc.ClientConn) error {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@dfawley dfawley assigned vinothkumarr227 and unassigned dfawley Apr 1, 2025
Comment on lines 1591 to 1593
if val, err := strconv.Atoi(h[0]); err == nil {
headerAttempts = val
}
Copy link
Member

Choose a reason for hiding this comment

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

This is test code, so you don't need to even look at the error (and zero is returned on a parse error anyway).

Suggested change
if val, err := strconv.Atoi(h[0]); err == nil {
headerAttempts = val
}
headerAttempts, _ = strconv.Atoi(h[0])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return status.Error(codes.Unavailable, fmt.Sprintf("retry (%d)", headerAttempts))
headerAttempts := 0
if h := md["grpc-previous-rpc-attempts"]; len(h) > 0 {
if val, err := strconv.Atoi(h[0]); err == nil {
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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@dfawley dfawley assigned vinothkumarr227 and unassigned dfawley Apr 3, 2025
@purnesh42H purnesh42H merged commit ce35fd4 into grpc:master Apr 4, 2025
15 checks passed
purnesh42H pushed a commit to purnesh42H/grpc-go that referenced this pull request Apr 13, 2025
janardhanvissa pushed a commit to janardhanvissa/grpc-go that referenced this pull request Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Observability Includes Stats, Tracing, Channelz, Healthz, Binlog, Reflection, Admin, GCP Observability Type: Feature New features or improvements in behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants