mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
PLT-7470: Add metrics for searches. (#7507)
This commit is contained in:
committed by
Christopher Speller
parent
81c18a01bd
commit
e8ca3d64f4
12
api/post.go
12
api/post.go
@@ -6,9 +6,11 @@ package api
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
@@ -474,7 +476,17 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
isOrSearch = val.(bool)
|
||||
}
|
||||
|
||||
startTime := time.Now()
|
||||
|
||||
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 {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
12
api4/post.go
12
api4/post.go
@@ -6,8 +6,10 @@ package api4
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"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)
|
||||
|
||||
startTime := time.Now()
|
||||
|
||||
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 {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -37,4 +37,7 @@ type MetricsInterface interface {
|
||||
|
||||
AddMemCacheHitCounter(cacheName string, amount float64)
|
||||
AddMemCacheMissCounter(cacheName string, amount float64)
|
||||
|
||||
IncrementPostsSearchCounter()
|
||||
ObservePostsSearchDuration(elapsed float64)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user