Skip to content

Commit

Permalink
feat(otelch): add more metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed May 24, 2022
1 parent 04d1945 commit 46cc21c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
18 changes: 18 additions & 0 deletions otelch/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const (
ErrorNameKey = attribute.Key("ch.error.name")
BlocksSentKey = attribute.Key("ch.blocks_sent")
BlocksReceivedKey = attribute.Key("ch.blocks_received")
ColumnsReceivedKey = attribute.Key("ch.columns_received")
RowsReceivedKey = attribute.Key("ch.rows_received")
RowsKey = attribute.Key("ch.rows")
BytesKey = attribute.Key("ch.bytes")
)
Expand All @@ -33,6 +35,22 @@ func BlocksReceived(v int) attribute.KeyValue {
}
}

// RowsReceived is cumulative rows received count during query execution.
func RowsReceived(v int) attribute.KeyValue {
return attribute.KeyValue{
Key: RowsReceivedKey,
Value: attribute.IntValue(v),
}
}

// ColumnsReceived is count of columns in result.
func ColumnsReceived(v int) attribute.KeyValue {
return attribute.KeyValue{
Key: ColumnsReceivedKey,
Value: attribute.IntValue(v),
}
}

// Rows is cumulative rows processed count during query execution.
func Rows(v int) attribute.KeyValue {
return attribute.KeyValue{
Expand Down
8 changes: 7 additions & 1 deletion query.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ func (c *Client) decodeBlock(ctx context.Context, opt decodeOptions) error {
if block.End() {
return nil
}
c.metricsInc(ctx, queryMetrics{BlocksReceived: 1})
c.metricsInc(ctx, queryMetrics{
BlocksReceived: 1,
RowsReceived: block.Rows,
ColumnsReceived: block.Columns,
})
if err := opt.Handler(ctx, block); err != nil {
return errors.Wrap(err, "handler")
}
Expand Down Expand Up @@ -531,6 +535,8 @@ func (c *Client) Do(ctx context.Context, q Query) (err error) {
span.SetAttributes(
otelch.BlocksSent(m.BlocksSent),
otelch.BlocksReceived(m.BlocksReceived),
otelch.RowsReceived(m.RowsReceived),
otelch.ColumnsReceived(m.ColumnsReceived),
otelch.Rows(m.Rows),
otelch.Bytes(m.Bytes),
)
Expand Down
15 changes: 11 additions & 4 deletions query_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import "context"
type (
ctxQueryKey struct{}
queryMetrics struct {
BlocksReceived int
BlocksSent int
Rows int
Bytes int
ColumnsReceived int
RowsReceived int
BlocksReceived int
BlocksSent int
Rows int
Bytes int
}
)

Expand All @@ -23,6 +25,11 @@ func (c *Client) metricsInc(ctx context.Context, delta queryMetrics) {

v.Bytes += delta.Bytes
v.Rows += delta.Rows
v.RowsReceived += delta.RowsReceived
v.BlocksReceived += delta.BlocksReceived
v.BlocksSent += delta.BlocksSent

if delta.ColumnsReceived > 0 {
v.ColumnsReceived = delta.ColumnsReceived
}
}

0 comments on commit 46cc21c

Please sign in to comment.