Skip to content

Commit

Permalink
metrics: separate autocomplete requests metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
msaf1980 committed Nov 5, 2022
1 parent 3308f78 commit 71a2378
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions autocomplete/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (h *Handler) ServeTags(w http.ResponseWriter, r *http.Request) {
http.Error(w, answer, status)
}
d := time.Since(start).Milliseconds()
metrics.SendFindMetrics(metrics.FindRequestMetric, status, d, 0, h.config.Metrics.ExtendedStat, metricsCount)
metrics.SendFindMetrics(metrics.TagsRequestMetric, status, d, 0, h.config.Metrics.ExtendedStat, metricsCount)
if !findCache && chReadRows != 0 && chReadBytes != 0 {
errored := status != http.StatusOK && status != http.StatusNotFound
metrics.SendQueryRead(metrics.AutocompleteQMetric, 0, 0, d, metricsCount, readBytes, chReadRows, chReadBytes, errored)
Expand Down Expand Up @@ -332,7 +332,7 @@ func (h *Handler) ServeValues(w http.ResponseWriter, r *http.Request) {
http.Error(w, answer, status)
}
d := time.Since(start).Milliseconds()
metrics.SendFindMetrics(metrics.FindRequestMetric, status, d, 0, h.config.Metrics.ExtendedStat, metricsCount)
metrics.SendFindMetrics(metrics.TagsRequestMetric, status, d, 0, h.config.Metrics.ExtendedStat, metricsCount)
if !findCache && chReadRows > 0 && chReadBytes > 0 {
errored := status != http.StatusOK && status != http.StatusNotFound
metrics.SendQueryRead(metrics.AutocompleteQMetric, 0, 0, d, metricsCount, int64(len(body)), chReadRows, chReadBytes, errored)
Expand Down
1 change: 1 addition & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ sample-thereafter = 12
assert.Equal(t, expected.Logging, config.Logging)

metrics.FindRequestMetric = nil
metrics.TagsRequestMetric = nil
metrics.RenderRequestMetric = nil
metrics.UnregisterAll()
}
Expand Down
2 changes: 2 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type RenderMetrics struct {

var RenderRequestMetric *RenderMetrics
var FindRequestMetric *FindMetrics
var TagsRequestMetric *FindMetrics

func initFindCacheMetrics(c *Config) {
FinderCacheMetrics = &CacheMetric{
Expand Down Expand Up @@ -581,6 +582,7 @@ func InitMetrics(c *Config) {
}
initFindCacheMetrics(c)
FindRequestMetric = initFindMetrics("find", c)
TagsRequestMetric = initFindMetrics("tags", c)
RenderRequestMetric = initRenderMetrics("render", c)
}

Expand Down
1 change: 1 addition & 0 deletions metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ func TestInitMetrics(t *testing.T) {
for n, tt := range tests {
t.Run(tt.name+"#"+strconv.Itoa(n), func(t *testing.T) {
FindRequestMetric = nil
TagsRequestMetric = nil
RenderRequestMetric = nil
UnregisterAll()
c := tt.c
Expand Down

0 comments on commit 71a2378

Please sign in to comment.