Skip to content

feat: updating proxy otel tracing#178

Draft
brandtnewton wants to merge 5 commits intoGoogleCloudPlatform:mainfrom
brandtnewton:proxy/telemetry
Draft

feat: updating proxy otel tracing#178
brandtnewton wants to merge 5 commits intoGoogleCloudPlatform:mainfrom
brandtnewton:proxy/telemetry

Conversation

@brandtnewton
Copy link
Copy Markdown
Collaborator

No description provided.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request integrates OpenTelemetry tracing into the Bigtable adapter and proxy handlers, adds support for the Google Cloud Trace exporter, and implements a parser pool to optimize performance. It also includes dependency updates, pprof profiling, and an increase in default gRPC channels. Review feedback highlights the need for more accurate span naming in generic execution paths, potential resource leaks in error handling where pooled parsers are not released, and the correction of unsafe fmt.Errorf calls. Using the provided Release abstraction on RawQuery is also suggested for better code clarity.


var (
spanExecutePreparedStatement = "executePreparedStatement"
spanMutateRow = "MutateRow"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The span name spanMutateRow ("MutateRow") is misleading when used in the generic Execute method, as it also handles SELECT, DELETE, and DDL operations. Renaming this constant to spanExecute with the value "Execute" improves code readability and accurately reflects the method's purpose.

Suggested change
spanMutateRow = "MutateRow"
spanExecute = "Execute"
References
  1. Prioritize code readability over minor performance optimizations. Clear and accurate naming is essential for maintainable code.

}

func (btc *BigtableAdapter) Execute(ctx context.Context, query types.IExecutableQuery) (message.Message, error) {
ctx, span := btc.otelInst.StartSpan(ctx, spanMutateRow, []attribute.KeyValue{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Use a generic span name for the Execute method since it serves as the entry point for all query types. This improves the readability and logical flow of the tracing implementation.

Suggested change
ctx, span := btc.otelInst.StartSpan(ctx, spanMutateRow, []attribute.KeyValue{
ctx, span := btc.otelInst.StartSpan(ctx, spanExecute, []attribute.KeyValue{
References
  1. Prioritize code readability over minor performance optimizations.

res = BulkOperationResponse{
FailedRows: fmt.Sprintf("failed rowkeys: %v", failedRows),
}
btc.otelInst.RecordError(span, fmt.Errorf(res.FailedRows))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using fmt.Errorf(res.FailedRows) is unsafe because res.FailedRows is a dynamically generated string that may contain format specifiers (e.g., from row keys). This can lead to unexpected formatting errors or panics. Use fmt.Errorf("%s", res.FailedRows) instead.

Suggested change
btc.otelInst.RecordError(span, fmt.Errorf(res.FailedRows))
btc.otelInst.RecordError(span, fmt.Errorf("%s", res.FailedRows))

Comment on lines +511 to +513
if err != nil {
otelErr = err
c.proxy.otelInst.RecordError(span, otelErr)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The parser p is not released back to the pool if parseQueryType(p) fails. This results in a resource leak in the parser pool. Ensure the parser is released in the error path.

Suggested change
if err != nil {
otelErr = err
c.proxy.otelInst.RecordError(span, otelErr)
if err != nil {
p.Release()
otelErr = err
c.proxy.otelInst.RecordError(span, otelErr)

Comment on lines +752 to +754
if err != nil {
otelErr = err
c.proxy.otelInst.RecordError(span, otelErr)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The parser p is not released back to the pool if parseQueryType(p) fails, leading to a resource leak. Ensure the parser is released in the error path.

Suggested change
if err != nil {
otelErr = err
c.proxy.otelInst.RecordError(span, otelErr)
if err != nil {
p.Release()
otelErr = err
c.proxy.otelInst.RecordError(span, otelErr)

}

func (t *TranslatorManager) TranslateQuery(q *types.RawQuery, sessionKeyspace types.Keyspace) (types.IPreparedQuery, error) {
defer q.Parser().Release()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Use q.Release() instead of q.Parser().Release(). The Release method on RawQuery is designed to return the parser to the pool and safely set the internal reference to nil, which is more readable and prevents potential use-after-release bugs.

Suggested change
defer q.Parser().Release()
defer q.Release()
References
  1. Prioritize code readability over minor performance optimizations. Using the intended API abstraction improves clarity and safety.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant