Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit 38028b3

Browse files
authored
Merge pull request #1508 from grafana/rollup-indicator-cleanup
Rollup indicator cleanup
2 parents 36a4e0d + 849fa01 commit 38028b3

21 files changed

+352
-230
lines changed

api/ccache_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func newSrv(delSeries, delArchives int) (*Server, *cache.MockCache) {
2424
srv.RegisterRoutes()
2525

2626
mdata.SetSingleAgg(conf.Avg, conf.Min, conf.Max)
27-
mdata.SetSingleSchema(conf.NewRetentionMT(10, 100, 600, 10, 0))
27+
mdata.SetSingleSchema(conf.MustParseRetentions("10s:100s:10min:10:true"))
2828

2929
store := mdata.NewMockStore()
3030
store.Drop = true

api/dataprocessor.go

+1
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ func (s *Server) getTarget(ctx context.Context, ss *models.StorageStats, req mod
358358
// rather than a runtime divide of 2 series
359359
SchemaID: req.SchemaId,
360360
Archive: req.Archive,
361+
ArchInterval: req.ArchInterval,
361362
AggNumNorm: req.AggNum,
362363
ConsolidatorNormFetch: req.Consolidator,
363364
Count: 1,

api/dataprocessor_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ func TestGetSeriesFixed(t *testing.T) {
364364
store.Drop = true
365365

366366
mdata.SetSingleAgg(conf.Avg, conf.Min, conf.Max)
367-
mdata.SetSingleSchema(conf.NewRetentionMT(10, 100, 600, 10, 0))
367+
mdata.SetSingleSchema(conf.MustParseRetentions("10s:100s:10min:10:true"))
368368

369369
metrics := mdata.NewAggMetrics(store, &cache.MockCache{}, false, nil, 0, 0, 0)
370370
srv, _ := NewServer()
@@ -412,7 +412,7 @@ func TestGetSeriesFixedVariableOutInterval(t *testing.T) {
412412
store.Drop = true
413413

414414
mdata.SetSingleAgg(conf.Sum, conf.Avg, conf.Min, conf.Max)
415-
mdata.SetSingleSchema(conf.NewRetentionMT(10, 100, 600, 10, 0))
415+
mdata.SetSingleSchema(conf.MustParseRetentions("10s:100s:10min:10:true"))
416416

417417
cache := cache.NewCCache()
418418
metrics := mdata.NewAggMetrics(store, cache, false, nil, 0, 0, 0)

api/models/series.go

+47-10
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import (
99

1010
"github.com/grafana/metrictank/consolidation"
1111
"github.com/grafana/metrictank/expr/tagquery"
12+
"github.com/grafana/metrictank/mdata"
1213
"github.com/grafana/metrictank/schema"
1314
pickle "github.com/kisielk/og-rek"
1415
)
1516

1617
//go:generate msgp
18+
//msgp:ignore SeriesMetaPropertiesExport
1719

1820
type Series struct {
1921
Target string // for fetched data, set from models.Req.Target, i.e. the metric graphite key. for function output, whatever should be shown as target string (legend)
@@ -37,13 +39,44 @@ type SeriesMeta []SeriesMetaProperties
3739
type SeriesMetaProperties struct {
3840
SchemaID uint16 // id of storage-schemas rule this series corresponds to
3941
Archive uint8 // which archive was being read from
42+
ArchInterval uint32 // the interval of the archive we fetch
4043
AggNumNorm uint32 // aggNum for normalization
4144
AggNumRC uint32 // aggNum runtime consolidation
4245
ConsolidatorNormFetch consolidation.Consolidator // consolidator used for normalization and reading from store (if applicable)
4346
ConsolidatorRC consolidation.Consolidator // consolidator used for runtime consolidation to honor maxdatapoints (if applicable).
4447
Count uint32 // number of series corresponding to these properties
4548
}
4649

50+
// SeriesMetaPropertiesExport is an "export" of a SeriesMetaProperties
51+
// it is a more user friendly representation
52+
type SeriesMetaPropertiesExport struct {
53+
SchemaName string // name of schema rule used
54+
SchemaRetentions string // schema retentions used
55+
ArchiveRead uint8 // which archive was being read from
56+
ArchInterval uint32 // the interval of the archive we fetch
57+
AggNumNorm uint32 // aggNum for normalization
58+
AggNumRC uint32 // aggNum runtime consolidation
59+
ConsolidatorNormFetch consolidation.Consolidator // consolidator used for normalization and reading from store (if applicable)
60+
ConsolidatorRC consolidation.Consolidator // consolidator used for runtime consolidation to honor maxdatapoints (if applicable).
61+
Count uint32 // number of series corresponding to these properties
62+
}
63+
64+
// Export returns a human-friendly version of the SeriesMetaProperties.
65+
func (smp SeriesMetaProperties) Export() SeriesMetaPropertiesExport {
66+
schema := mdata.Schemas.Get(smp.SchemaID)
67+
return SeriesMetaPropertiesExport{
68+
SchemaName: schema.Name,
69+
SchemaRetentions: schema.Retentions.Orig,
70+
ArchiveRead: smp.Archive,
71+
ArchInterval: smp.ArchInterval,
72+
AggNumNorm: smp.AggNumNorm,
73+
AggNumRC: smp.AggNumRC,
74+
ConsolidatorNormFetch: smp.ConsolidatorNormFetch,
75+
ConsolidatorRC: smp.ConsolidatorRC,
76+
Count: smp.Count,
77+
}
78+
}
79+
4780
// Merge merges SeriesMeta b into a
4881
// counts for identical properties get added together
4982
func (a SeriesMeta) Merge(b SeriesMeta) SeriesMeta {
@@ -290,21 +323,25 @@ func (series SeriesByTarget) MarshalJSONFastWithMeta(b []byte) ([]byte, error) {
290323
func (meta SeriesMeta) MarshalJSONFast(b []byte) ([]byte, error) {
291324
b = append(b, '[')
292325
for _, props := range meta {
293-
b = append(b, `{"schema-id":`...)
294-
// TODO make user friendly return the actual rule
295-
b = strconv.AppendUint(b, uint64(props.SchemaID), 10)
296-
b = append(b, `,"archive":`...)
297-
b = strconv.AppendUint(b, uint64(props.Archive), 10)
326+
exp := props.Export()
327+
b = append(b, `{"schema-name":"`...)
328+
b = append(b, exp.SchemaName...)
329+
b = append(b, `","schema-retentions":"`...)
330+
b = append(b, exp.SchemaRetentions...)
331+
b = append(b, `","archive-read":`...)
332+
b = strconv.AppendUint(b, uint64(exp.ArchiveRead), 10)
333+
b = append(b, `,"archive-interval":`...)
334+
b = strconv.AppendUint(b, uint64(exp.ArchInterval), 10)
298335
b = append(b, `,"aggnum-norm":`...)
299-
b = strconv.AppendUint(b, uint64(props.AggNumNorm), 10)
336+
b = strconv.AppendUint(b, uint64(exp.AggNumNorm), 10)
300337
b = append(b, `,"consolidate-normfetch":"`...)
301-
b = append(b, props.ConsolidatorNormFetch.String()...)
338+
b = append(b, exp.ConsolidatorNormFetch.String()...)
302339
b = append(b, `","aggnum-rc":`...)
303-
b = strconv.AppendUint(b, uint64(props.AggNumRC), 10)
340+
b = strconv.AppendUint(b, uint64(exp.AggNumRC), 10)
304341
b = append(b, `,"consolidate-rc":"`...)
305-
b = append(b, props.ConsolidatorRC.String()...)
342+
b = append(b, exp.ConsolidatorRC.String()...)
306343
b = append(b, `","count":`...)
307-
b = strconv.AppendUint(b, uint64(props.Count), 10)
344+
b = strconv.AppendUint(b, uint64(exp.Count), 10)
308345
b = append(b, `},`...)
309346
}
310347
if len(meta) != 0 {

api/models/series_gen.go

+30-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/query_engine.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func alignRequests(now, from, to uint32, reqs []models.Req) ([]models.Req, uint3
5959
var found bool
6060
for i := range reqs {
6161
req := &reqs[i]
62-
retentions := mdata.Schemas.Get(req.SchemaId).Retentions
62+
retentions := mdata.Schemas.Get(req.SchemaId).Retentions.Rets
6363
for i, ret := range retentions {
6464
// skip non-ready option.
6565
if ret.Ready > from {
@@ -116,7 +116,7 @@ func alignRequests(now, from, to uint32, reqs []models.Req) ([]models.Req, uint3
116116
// we have to deliver an interval higher than what we originally came up with
117117

118118
// let's see first if we can deliver it via lower-res rollup archives, if we have any
119-
retentions := mdata.Schemas.Get(req.SchemaId).Retentions
119+
retentions := mdata.Schemas.Get(req.SchemaId).Retentions.Rets
120120
for i, ret := range retentions[req.Archive+1:] {
121121
archInterval := uint32(ret.SecondsPerPoint)
122122
if interval == archInterval && ret.Ready <= from {

0 commit comments

Comments
 (0)