diff options
-rw-r--r-- | api/post.go | 12 | ||||
-rw-r--r-- | api4/post.go | 12 | ||||
-rw-r--r-- | einterfaces/metrics.go | 3 |
3 files changed, 27 insertions, 0 deletions
diff --git a/api/post.go b/api/post.go index 703c070c5..41cd7564b 100644 --- a/api/post.go +++ b/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 diff --git a/api4/post.go b/api4/post.go index 297c70a87..0cd791c6f 100644 --- a/api4/post.go +++ b/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 diff --git a/einterfaces/metrics.go b/einterfaces/metrics.go index 58a803067..a88fe63cf 100644 --- a/einterfaces/metrics.go +++ b/einterfaces/metrics.go @@ -37,4 +37,7 @@ type MetricsInterface interface { AddMemCacheHitCounter(cacheName string, amount float64) AddMemCacheMissCounter(cacheName string, amount float64) + + IncrementPostsSearchCounter() + ObservePostsSearchDuration(elapsed float64) } |