MM-39215: Add DBStatsCollector to metrics (#21957)
https://mattermost.atlassian.net/browse/MM-39215 ```release-note We now have Grafana metrics for DB connection metrics. They are: max_open_connections open_connections in_use_connections idle_connections wait_count_total wait_duration_seconds_total max_idle_closed_total max_idle_time_closed_total max_lifetime_closed_total ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
74a20cbf7e
Коммит
a9bac806f3
@@ -141,6 +141,7 @@ func TestMetrics(t *testing.T) {
|
||||
mockMetricsImpl := &mocks.MetricsInterface{}
|
||||
mockMetricsImpl.On("Register").Return()
|
||||
mockMetricsImpl.On("ObserveStoreMethodDuration", mock.Anything, mock.Anything, mock.Anything).Return()
|
||||
mockMetricsImpl.On("RegisterDBCollector", mock.AnythingOfType("*sql.DB"), "master")
|
||||
|
||||
th := Setup(t, StartMetrics(), func(ps *PlatformService) error {
|
||||
ps.metricsIFace = mockMetricsImpl
|
||||
|
||||
@@ -4,12 +4,15 @@
|
||||
package einterfaces
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
||||
)
|
||||
|
||||
type MetricsInterface interface {
|
||||
Register()
|
||||
RegisterDBCollector(db *sql.DB, name string)
|
||||
|
||||
IncrementPostCreate()
|
||||
IncrementWebhookPost()
|
||||
|
||||
@@ -9,6 +9,8 @@ import (
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
|
||||
model "github.com/mattermost/mattermost-server/v6/model"
|
||||
|
||||
sql "database/sql"
|
||||
)
|
||||
|
||||
// MetricsInterface is an autogenerated mock type for the MetricsInterface type
|
||||
@@ -302,6 +304,11 @@ func (_m *MetricsInterface) Register() {
|
||||
_m.Called()
|
||||
}
|
||||
|
||||
// RegisterDBCollector provides a mock function with given fields: db, name
|
||||
func (_m *MetricsInterface) RegisterDBCollector(db *sql.DB, name string) {
|
||||
_m.Called(db, name)
|
||||
}
|
||||
|
||||
// SetReplicaLagAbsolute provides a mock function with given fields: node, value
|
||||
func (_m *MetricsInterface) SetReplicaLagAbsolute(node string, value float64) {
|
||||
_m.Called(node, value)
|
||||
|
||||
@@ -301,6 +301,9 @@ func (ss *SqlStore) initConnection() {
|
||||
if ss.DriverName() == model.DatabaseDriverMysql {
|
||||
ss.masterX.MapperFunc(noOpMapper)
|
||||
}
|
||||
if ss.metrics != nil {
|
||||
ss.metrics.RegisterDBCollector(ss.masterX.DB.DB, "master")
|
||||
}
|
||||
|
||||
if len(ss.settings.DataSourceReplicas) > 0 {
|
||||
ss.ReplicaXs = make([]*sqlxDBWrapper, len(ss.settings.DataSourceReplicas))
|
||||
@@ -312,6 +315,9 @@ func (ss *SqlStore) initConnection() {
|
||||
if ss.DriverName() == model.DatabaseDriverMysql {
|
||||
ss.ReplicaXs[i].MapperFunc(noOpMapper)
|
||||
}
|
||||
if ss.metrics != nil {
|
||||
ss.metrics.RegisterDBCollector(ss.ReplicaXs[i].DB.DB, "replica-"+strconv.Itoa(i))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,6 +331,9 @@ func (ss *SqlStore) initConnection() {
|
||||
if ss.DriverName() == model.DatabaseDriverMysql {
|
||||
ss.searchReplicaXs[i].MapperFunc(noOpMapper)
|
||||
}
|
||||
if ss.metrics != nil {
|
||||
ss.metrics.RegisterDBCollector(ss.searchReplicaXs[i].DB.DB, "searchreplica-"+strconv.Itoa(i))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/mattermost/mattermost-server/v6/db"
|
||||
"github.com/mattermost/mattermost-server/v6/einterfaces/mocks"
|
||||
"github.com/mattermost/mattermost-server/v6/model"
|
||||
"github.com/mattermost/mattermost-server/v6/plugin/plugintest/mock"
|
||||
"github.com/mattermost/mattermost-server/v6/store"
|
||||
"github.com/mattermost/mattermost-server/v6/store/searchtest"
|
||||
"github.com/mattermost/mattermost-server/v6/store/storetest"
|
||||
@@ -731,6 +732,7 @@ func TestReplicaLagQuery(t *testing.T) {
|
||||
defer mockMetrics.AssertExpectations(t)
|
||||
mockMetrics.On("SetReplicaLagAbsolute", tableName, float64(1))
|
||||
mockMetrics.On("SetReplicaLagTime", tableName, float64(1))
|
||||
mockMetrics.On("RegisterDBCollector", mock.AnythingOfType("*sql.DB"), "master")
|
||||
|
||||
store := &SqlStore{
|
||||
rrCounter: 0,
|
||||
|
||||
Ссылка в новой задаче
Block a user