mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-21 12:24:38 +02:00
add database histogram
This commit is contained in:
parent
d310cd08f8
commit
93116f5d47
@ -10,6 +10,8 @@ import (
|
|||||||
"code.gitea.io/gitea/modules/gtprof"
|
"code.gitea.io/gitea/modules/gtprof"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
|
|
||||||
"xorm.io/xorm/contexts"
|
"xorm.io/xorm/contexts"
|
||||||
)
|
)
|
||||||
@ -21,12 +23,22 @@ type EngineHook struct {
|
|||||||
|
|
||||||
var _ contexts.Hook = (*EngineHook)(nil)
|
var _ contexts.Hook = (*EngineHook)(nil)
|
||||||
|
|
||||||
|
// follows: https://opentelemetry.io/docs/specs/semconv/database/database-metrics/#metric-dbclientoperationduration
|
||||||
|
var durationHistogram = promauto.NewHistogram(prometheus.HistogramOpts{
|
||||||
|
Namespace: "db",
|
||||||
|
Subsystem: "client",
|
||||||
|
Name: "operation.duration",
|
||||||
|
Help: "Duration of database client operations.",
|
||||||
|
// ConstLabels: prometheus.Labels{"db.system.name": BuilderDialect()}, //TODO: add type of database per spec.
|
||||||
|
})
|
||||||
|
|
||||||
func (*EngineHook) BeforeProcess(c *contexts.ContextHook) (context.Context, error) {
|
func (*EngineHook) BeforeProcess(c *contexts.ContextHook) (context.Context, error) {
|
||||||
ctx, _ := gtprof.GetTracer().Start(c.Ctx, gtprof.TraceSpanDatabase)
|
ctx, _ := gtprof.GetTracer().Start(c.Ctx, gtprof.TraceSpanDatabase)
|
||||||
return ctx, nil
|
return ctx, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *EngineHook) AfterProcess(c *contexts.ContextHook) error {
|
func (h *EngineHook) AfterProcess(c *contexts.ContextHook) error {
|
||||||
|
durationHistogram.Observe(c.ExecuteTime.Seconds())
|
||||||
span := gtprof.GetContextSpan(c.Ctx)
|
span := gtprof.GetContextSpan(c.Ctx)
|
||||||
if span != nil {
|
if span != nil {
|
||||||
// Do not record SQL parameters here:
|
// Do not record SQL parameters here:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user