From 8c9db373d0e112e3f55ce4e79d19ffdd40e9d36d Mon Sep 17 00:00:00 2001 From: Alan Bernstein Date: Fri, 3 Apr 2020 12:10:27 -0500 Subject: [PATCH] Fix some metrics names --- executor.go | 2 +- metrics.go | 18 ++++++++++++++++-- prometheus/prometheus.go | 4 ++-- stats/stats_test.go | 32 ++++++++++++++++---------------- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/executor.go b/executor.go index d5bd70483..daf3f1320 100644 --- a/executor.go +++ b/executor.go @@ -463,7 +463,7 @@ func (e *executor) executeCall(ctx context.Context, index string, c *pql.Call, s return nil, errors.Wrap(err, "validating args") } indexTag := "index:" + index - metricName := "query_" + c.Name + metricName := "query_" + strings.ToLower(c.Name) + "_total" // Fixes #2009 // See: https://github.com/pilosa/pilosa/issues/2009 diff --git a/metrics.go b/metrics.go index cc39d32e8..fc451772f 100644 --- a/metrics.go +++ b/metrics.go @@ -1,3 +1,17 @@ +// Copyright 2020 Pilosa Corp. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package pilosa const ( @@ -12,8 +26,8 @@ const ( MetricCacheThresholdReached = "cache_threshold_reached_total" MetricRow = "query_row_total" MetricRowBSI = "query_row_bsi_total" - MetricSetRowAttrs = "query_set_row_attrs_total" - MetricSetColumnAttrs = "query_set_column_attrs_total" + MetricSetRowAttrs = "query_setrowattrs_total" + MetricSetColumnAttrs = "query_setcolumnattrs_total" MetricMaximumRow = "maximum_row" MetricSetBit = "set_bit_total" MetricClearBit = "clear_bit_total" diff --git a/prometheus/prometheus.go b/prometheus/prometheus.go index 3cebb0c32..4208e29a5 100644 --- a/prometheus/prometheus.go +++ b/prometheus/prometheus.go @@ -252,8 +252,8 @@ func (c *prometheusClient) Set(name string, value string, rate float64) { // Timing tracks timing information for a metric. func (c *prometheusClient) Timing(name string, value time.Duration, rate float64) { - durationMs := value / time.Second - c.Histogram(name, float64(durationMs), rate) + durationS := value / time.Second + c.Histogram(name, float64(durationS), rate) } // SetLogger sets the logger for client. diff --git a/stats/stats_test.go b/stats/stats_test.go index 5c730bf97..a710cd08d 100644 --- a/stats/stats_test.go +++ b/stats/stats_test.go @@ -101,8 +101,8 @@ func TestStatsCount_TopN(t *testing.T) { called := false hldr.Holder.Stats = &MockStats{ mockCountWithTags: func(name string, value int64, rate float64, tags []string) { - if name != "TopN" { - t.Errorf("Expected TopN, Results %s", name) + if name != "query_topn_total" { + t.Errorf("Expected query_topn_total, Results %s", name) } if tags[0] != "index:d" { @@ -130,8 +130,8 @@ func TestStatsCount_Bitmap(t *testing.T) { called := false hldr.Holder.Stats = &MockStats{ mockCountWithTags: func(name string, value int64, rate float64, tags []string) { - if name != "Row" { - t.Errorf("Expected Row, Results %s", name) + if name != "query_row_total" { + t.Errorf("Expected query_row_total, Results %s", name) } if tags[0] != "index:d" { @@ -165,8 +165,8 @@ func TestStatsCount_SetColumnAttrs(t *testing.T) { field.Stats = &MockStats{ mockCount: func(name string, value int64, rate float64) { - if name != "SetRowAttrs" { - t.Errorf("Expected SetRowAttrs, Results %s", name) + if name != "query_setrowattrs_total" { + t.Errorf("Expected query_setrowattrs_total, Results %s", name) } called = true }, @@ -195,8 +195,8 @@ func TestStatsCount_SetProfileAttrs(t *testing.T) { idx.Stats = &MockStats{ mockCount: func(name string, value int64, rate float64) { - if name != "SetProfileAttrs" { - t.Errorf("Expected SetProfilepAttrs, Results %s", name) + if name != "query_setcolumnattrs_total" { + t.Errorf("Expected query_setcolumnattrs_total, Results %s", name) } called = true @@ -222,8 +222,8 @@ func TestStatsCount_APICalls(t *testing.T) { called := false hldr.Stats = &MockStats{ mockCount: func(name string, value int64, rate float64) { - if name != "createIndex" { - t.Errorf("Expected createIndex, Results %s", name) + if name != "create_index_total" { + t.Errorf("Expected create_index_total, Results %s", name) } called = true }, @@ -239,8 +239,8 @@ func TestStatsCount_APICalls(t *testing.T) { called := false hldr.Stats = &MockStats{ mockCountWithTags: func(name string, value int64, rate float64, index []string) { - if name != "createField" { - t.Errorf("Expected createField, Results %s", name) + if name != "create_field_total" { + t.Errorf("Expected create_field_total, Results %s", name) } if index[0] != "index:i" { t.Errorf("Expected index:i, Results %s", index) @@ -260,8 +260,8 @@ func TestStatsCount_APICalls(t *testing.T) { called := false hldr.Stats = &MockStats{ mockCountWithTags: func(name string, value int64, rate float64, index []string) { - if name != "deleteField" { - t.Errorf("Expected deleteField, Results %s", name) + if name != "delete_field_total" { + t.Errorf("Expected delete_field_total, Results %s", name) } if index[0] != "index:i" { t.Errorf("Expected index:i, Results %s", index) @@ -281,8 +281,8 @@ func TestStatsCount_APICalls(t *testing.T) { called := false hldr.Stats = &MockStats{ mockCount: func(name string, value int64, rate float64) { - if name != "deleteIndex" { - t.Errorf("Expected deleteIndex, Results %s", name) + if name != "delete_index_total" { + t.Errorf("Expected delete_index_total, Results %s", name) } called = true