Skip to content

Commit ad37a17

Browse files
committed
processed feedback on PR #28
1 parent c5860da commit ad37a17

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

dbstats_go1.11.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package ocsql
55
import (
66
"context"
77
"database/sql"
8+
"sync"
89
"time"
910

1011
"go.opencensus.io/stats"
@@ -14,9 +15,10 @@ import (
1415
// interval.
1516
func RecordStats(db *sql.DB, interval time.Duration) (fnStop func()) {
1617
var (
17-
ctx = context.Background()
18-
ticker = time.NewTicker(interval)
19-
done = make(chan struct{})
18+
closeOnce sync.Once
19+
ctx = context.Background()
20+
ticker = time.NewTicker(interval)
21+
done = make(chan struct{})
2022
)
2123

2224
go func() {
@@ -41,6 +43,8 @@ func RecordStats(db *sql.DB, interval time.Duration) (fnStop func()) {
4143
}()
4244

4345
return func() {
44-
close(done)
46+
closeOnce.Do(func() {
47+
close(done)
48+
})
4549
}
4650
}

observability.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func recordCallStats(ctx context.Context, method string) func(err error) {
159159
startTime := time.Now()
160160

161161
return func(err error) {
162-
timeSpent := float64(time.Since(startTime).Nanoseconds()) / 1e6
162+
timeSpentMs := float64(time.Since(startTime).Nanoseconds()) / 1e6
163163

164164
if err != nil {
165165
tags = []tag.Mutator{
@@ -171,6 +171,6 @@ func recordCallStats(ctx context.Context, method string) func(err error) {
171171
}
172172
}
173173

174-
_ = stats.RecordWithTags(ctx, tags, MeasureLatencyMs.M(timeSpent))
174+
_ = stats.RecordWithTags(ctx, tags, MeasureLatencyMs.M(timeSpentMs))
175175
}
176176
}

0 commit comments

Comments
 (0)