PLT-7470: Add metrics for searches. (#7507)
Этот коммит содержится в:
коммит произвёл
Christopher Speller
родитель
81c18a01bd
Коммит
e8ca3d64f4
12
api/post.go
12
api/post.go
@@ -6,9 +6,11 @@ package api
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
l4g "github.com/alecthomas/log4go"
|
l4g "github.com/alecthomas/log4go"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/app"
|
"github.com/mattermost/mattermost-server/app"
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
"github.com/mattermost/mattermost-server/utils"
|
||||||
@@ -474,7 +476,17 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
isOrSearch = val.(bool)
|
isOrSearch = val.(bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startTime := time.Now()
|
||||||
|
|
||||||
posts, err := c.App.SearchPostsInTeam(terms, c.Session.UserId, c.TeamId, isOrSearch)
|
posts, err := c.App.SearchPostsInTeam(terms, c.Session.UserId, c.TeamId, isOrSearch)
|
||||||
|
|
||||||
|
elapsedTime := float64(time.Since(startTime)) / float64(time.Second)
|
||||||
|
metrics := c.App.Metrics
|
||||||
|
if metrics != nil {
|
||||||
|
metrics.IncrementPostsSearchCounter()
|
||||||
|
metrics.ObservePostsSearchDuration(elapsedTime)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
|
|||||||
12
api4/post.go
12
api4/post.go
@@ -6,8 +6,10 @@ package api4
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
l4g "github.com/alecthomas/log4go"
|
l4g "github.com/alecthomas/log4go"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/app"
|
"github.com/mattermost/mattermost-server/app"
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
"github.com/mattermost/mattermost-server/utils"
|
"github.com/mattermost/mattermost-server/utils"
|
||||||
@@ -299,7 +301,17 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
isOrSearch, _ := props["is_or_search"].(bool)
|
isOrSearch, _ := props["is_or_search"].(bool)
|
||||||
|
|
||||||
|
startTime := time.Now()
|
||||||
|
|
||||||
posts, err := c.App.SearchPostsInTeam(terms, c.Session.UserId, c.Params.TeamId, isOrSearch)
|
posts, err := c.App.SearchPostsInTeam(terms, c.Session.UserId, c.Params.TeamId, isOrSearch)
|
||||||
|
|
||||||
|
elapsedTime := float64(time.Since(startTime)) / float64(time.Second)
|
||||||
|
metrics := c.App.Metrics
|
||||||
|
if metrics != nil {
|
||||||
|
metrics.IncrementPostsSearchCounter()
|
||||||
|
metrics.ObservePostsSearchDuration(elapsedTime)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -37,4 +37,7 @@ type MetricsInterface interface {
|
|||||||
|
|
||||||
AddMemCacheHitCounter(cacheName string, amount float64)
|
AddMemCacheHitCounter(cacheName string, amount float64)
|
||||||
AddMemCacheMissCounter(cacheName string, amount float64)
|
AddMemCacheMissCounter(cacheName string, amount float64)
|
||||||
|
|
||||||
|
IncrementPostsSearchCounter()
|
||||||
|
ObservePostsSearchDuration(elapsed float64)
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user