PLT-7470: Add metrics for searches. (#7507)

This commit is contained in:
George Goldberg
2017-09-25 21:44:44 +01:00
committed by Christopher Speller
parent 81c18a01bd
commit e8ca3d64f4
3 changed files with 27 additions and 0 deletions

View File

@@ -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