/
githubmirror
/
grafana
Обзор
Документация
Войти
/
githubmirror
/
grafana
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
pkg/infra/log/databaseQueryTimer.go
44 строки
1021 B
Alexander Akhmetov
logging: fix db_query_time always reporting zero (#116824)
26 янв 2026, 15:25
Не верифицирован
26 янв 2026, 15:25
9d329eb
Код
Авторство
О чём код?
package log import ( "context" "sync/atomic" ) type dbCallQueryTimerContextKey struct{} var dbCallQueryTimerKey = dbCallQueryTimerContextKey{} // InitDBQueryTimer creates a pointer on the context that can be incremented later func InitDBQueryTimer(ctx context.Context) context.Context { var ptr = new(int64) return context.WithValue(ctx, dbCallQueryTimerKey, ptr) } // IncDBQueryTimer increments the database query timer on the context. func IncDBQueryTimer(ctx context.Context, queryTimeInMs int64) context.Context { if val := ctx.Value(dbCallQueryTimerKey); val == nil { ctx = InitDBQueryTimer(ctx) } if val := ctx.Value(dbCallQueryTimerKey); val != nil { v2, ok := val.(*int64) if ok { atomic.AddInt64(v2, queryTimeInMs) } } return ctx } // TotalDBQueryTime returns the total number of query time for this context func TotalDBQueryTime(ctx context.Context) int64 { if val := ctx.Value(dbCallQueryTimerKey); val != nil { v2, ok := val.(*int64) if ok { return *v2 } } return 0 }