Fix minor issues with metric labels and tests

This commit is contained in:
Alan Bernstein 2020-04-09 17:00:20 -05:00 • committed by Matt Jaffee
parent c2c0a5c32f
commit 389acfc8ed
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
4 changed files with 24 additions and 9 deletions

View file

@ -3217,7 +3217,11 @@ func (e *executor) executeBulkSetRowAttrs(ctx context.Context, index string, cal
if err := field.RowAttrStore().SetBulkAttrs(fieldMap); err != nil {
return nil, err
}
field.Stats.Count(MetricSetRowAttrs, 1, 1.0)
}
if !opt.Remote {
tags := []string{"index:" + index, "bulk:true"}
e.Holder.Stats.CountWithCustomTags(MetricSetRowAttrs, int64(len(m)), 1.0, tags)
}
// Do not forward call if this is already being forwarded.

View file

@ -277,12 +277,16 @@ func (h *Handler) collectStats(next http.Handler) http.Handler {
}
h.logger.Printf("%s %s %v %s", r.Method, r.URL.String(), dur, queryString)
statsTags = append(statsTags, "speed:true")
statsTags = append(statsTags, "slow:true")
} else {
statsTags = append(statsTags, "slow:false")
}
pathParts := strings.Split(r.URL.Path, "/")
if externalPrefixFlag[pathParts[1]] {
statsTags = append(statsTags, "where:external")
} else {
statsTags = append(statsTags, "where:internal")
}
statsTags = append(statsTags, "useragent:"+r.UserAgent())

View file

@ -302,7 +302,7 @@ func tagsToLabels(tags []string, logger logger.Logger) (labels prometheus.Labels
tagParts := strings.SplitAfterN(tag, ":", 2)
if len(tagParts) != 2 {
// only process tags in "key:value" form
logger.Debugf("Invalid Prometheus label: %v\n", tag)
logger.Printf("Error: invalid Prometheus label: %v\n", tag)
continue
}
labels[tagParts[0][0:len(tagParts[0])-1]] = tagParts[1]

View file

@ -152,7 +152,7 @@ func TestStatsCount_Bitmap(t *testing.T) {
}
}
func TestStatsCount_SetColumnAttrs(t *testing.T) {
func TestStatsCount_SetRowAttrsBulk(t *testing.T) {
c := test.MustRunCluster(t, 1)
defer c.Close()
hldr := test.Holder{Holder: c[0].Server.Holder()}
@ -166,11 +166,15 @@ func TestStatsCount_SetColumnAttrs(t *testing.T) {
t.Fatal("field not found")
}
field.Stats = &MockStats{
mockCount: func(name string, value int64, rate float64) {
hldr.Holder.Stats = &MockStats{
mockCountWithTags: func(name string, value int64, rate float64, tags []string) {
if name != pilosa.MetricSetRowAttrs {
t.Errorf("Expected %v, Results %s", pilosa.MetricSetRowAttrs, name)
}
if tags[0] != "index:d" {
t.Errorf("Expected db, Results %s", tags[0])
}
called = true
},
}
@ -182,7 +186,7 @@ func TestStatsCount_SetColumnAttrs(t *testing.T) {
}
}
func TestStatsCount_SetProfileAttrs(t *testing.T) {
func TestStatsCount_SetColumnAttrs(t *testing.T) {
c := test.MustRunCluster(t, 1)
defer c.Close()
hldr := test.Holder{Holder: c[0].Server.Holder()}
@ -196,12 +200,15 @@ func TestStatsCount_SetProfileAttrs(t *testing.T) {
t.Fatal("idex not found")
}
idx.Stats = &MockStats{
mockCount: func(name string, value int64, rate float64) {
hldr.Holder.Stats = &MockStats{
mockCountWithTags: func(name string, value int64, rate float64, tags []string) {
if name != pilosa.MetricSetColumnAttrs {
t.Errorf("Expected %v, Results %s", pilosa.MetricSetColumnAttrs, name)
}
if tags[0] != "index:d" {
t.Errorf("Expected db, Results %s", tags[0])
}
called = true
},
}