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

refactor(bigquery/storage/managedwriter): refactor error metrics #8314

Merged
merged 4 commits into from
Jul 25, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions bigquery/storage/managedwriter/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,18 +494,29 @@ func connRecvProcessor(ctx context.Context, co *connection, arc storagepb.BigQue
resp, err := arc.Recv()
co.release(nextWrite)
if err != nil {
// The Recv() itself yielded an error. We increment AppendResponseErrors by one, tagged by the status
// code.
status := grpcstatus.Convert(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if status can be nil here as this err is coming from a grpc stream method. Might worth add the extra check

Copy link
Contributor

Choose a reason for hiding this comment

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

an io.EOF will probably cause grpcstatus.Convert to return 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.

It wraps the error as a code.Unknown if it doesn't embed an rpc status error, ex: https://github.com/grpc/grpc-go/blob/faab8736bf73291f92b867d5dae31c927d53d508/status/status.go#L96-L125

metricCtx := ctx
if tagCtx, tagErr := tag.New(ctx, tag.Insert(keyError, codes.Code(status.Code()).String())); tagErr == nil {
metricCtx = tagCtx
}
recordStat(metricCtx, AppendResponseErrors, 1)

nextWrite.writer.processRetry(nextWrite, co, nil, err)
continue
}
// Record that we did in fact get a response from the backend.
recordStat(ctx, AppendResponses, 1)

if status := resp.GetError(); status != nil {
// The response from the backend embedded a status error. We record that the error
// occurred, and tag it based on the response code of the status.
// The response was received successfully, but the response embeds a status error in the payload.
// Increment AppendResponseErrors, tagged by status code.
metricCtx := ctx
if tagCtx, tagErr := tag.New(ctx, tag.Insert(keyError, codes.Code(status.GetCode()).String())); tagErr == nil {
recordStat(tagCtx, AppendResponseErrors, 1)
metricCtx = tagCtx
}
recordStat(metricCtx, AppendResponseErrors, 1)
respErr := grpcstatus.ErrorProto(status)

nextWrite.writer.processRetry(nextWrite, co, resp, respErr)
Expand Down
Loading