mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 06:20:54 +00:00
seperate orm alone
This commit is contained in:
parent
325a0821c1
commit
c5d43e87fe
@ -23,7 +23,6 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
|
||||||
"github.com/astaxie/beego/pkg/client/orm"
|
"github.com/astaxie/beego/pkg/client/orm"
|
||||||
"github.com/astaxie/beego/pkg/server/web"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// FilterChainBuilder is an extension point,
|
// FilterChainBuilder is an extension point,
|
||||||
@ -35,27 +34,24 @@ import (
|
|||||||
// actually we only records metrics of invoking "QueryTable" and "QueryTableWithCtx"
|
// actually we only records metrics of invoking "QueryTable" and "QueryTableWithCtx"
|
||||||
type FilterChainBuilder struct {
|
type FilterChainBuilder struct {
|
||||||
summaryVec prometheus.ObserverVec
|
summaryVec prometheus.ObserverVec
|
||||||
|
AppName string
|
||||||
|
ServerName string
|
||||||
|
RunMode string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFilterChainBuilder() *FilterChainBuilder {
|
func (builder *FilterChainBuilder) FilterChain(next orm.Filter) orm.Filter {
|
||||||
summaryVec := prometheus.NewSummaryVec(prometheus.SummaryOpts{
|
|
||||||
|
builder.summaryVec = prometheus.NewSummaryVec(prometheus.SummaryOpts{
|
||||||
Name: "beego",
|
Name: "beego",
|
||||||
Subsystem: "orm_operation",
|
Subsystem: "orm_operation",
|
||||||
ConstLabels: map[string]string{
|
ConstLabels: map[string]string{
|
||||||
"server": web.BConfig.ServerName,
|
"server": builder.ServerName,
|
||||||
"env": web.BConfig.RunMode,
|
"env": builder.RunMode,
|
||||||
"appname": web.BConfig.AppName,
|
"appname": builder.AppName,
|
||||||
},
|
},
|
||||||
Help: "The statics info for orm operation",
|
Help: "The statics info for orm operation",
|
||||||
}, []string{"method", "name", "duration", "insideTx", "txName"})
|
}, []string{"method", "name", "duration", "insideTx", "txName"})
|
||||||
|
|
||||||
prometheus.MustRegister(summaryVec)
|
|
||||||
return &FilterChainBuilder{
|
|
||||||
summaryVec: summaryVec,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (builder *FilterChainBuilder) FilterChain(next orm.Filter) orm.Filter {
|
|
||||||
return func(ctx context.Context, inv *orm.Invocation) []interface{} {
|
return func(ctx context.Context, inv *orm.Invocation) []interface{} {
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
res := next(ctx, inv)
|
res := next(ctx, inv)
|
||||||
|
@ -24,14 +24,15 @@ import (
|
|||||||
"github.com/astaxie/beego/pkg/client/orm"
|
"github.com/astaxie/beego/pkg/client/orm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFilterChainBuilder_FilterChain(t *testing.T) {
|
func TestFilterChainBuilder_FilterChain1(t *testing.T) {
|
||||||
builder := NewFilterChainBuilder()
|
next := func(ctx context.Context, inv *orm.Invocation) []interface{} {
|
||||||
assert.NotNil(t, builder.summaryVec)
|
|
||||||
|
|
||||||
filter := builder.FilterChain(func(ctx context.Context, inv *orm.Invocation) []interface{} {
|
|
||||||
inv.Method = "coming"
|
inv.Method = "coming"
|
||||||
return []interface{}{}
|
return []interface{}{}
|
||||||
})
|
}
|
||||||
|
builder := &FilterChainBuilder{}
|
||||||
|
filter := builder.FilterChain(next)
|
||||||
|
|
||||||
|
assert.NotNil(t, builder.summaryVec)
|
||||||
assert.NotNil(t, filter)
|
assert.NotNil(t, filter)
|
||||||
|
|
||||||
inv := &orm.Invocation{}
|
inv := &orm.Invocation{}
|
||||||
|
Loading…
Reference in New Issue
Block a user