Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit ed7a6ad

Browse files
committed
Excise old series cache
This was used before we sharded the inserter on a metric-basis, and is no longer useful.
1 parent d0fa4bf commit ed7a6ad

File tree

8 files changed

+3
-158
lines changed

8 files changed

+3
-158
lines changed

cmd/timescale-prometheus/main.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -211,22 +211,6 @@ func main() {
211211
return float64(client.MetricNamesCacheCapacity())
212212
})
213213

214-
cachedSeriesSets := prometheus.NewCounterFunc(prometheus.CounterOpts{
215-
Namespace: promNamespace,
216-
Name: "series_set_cache_elements_stored",
217-
Help: "Total number of labels to series-set id mappings cached.",
218-
}, func() float64 {
219-
return float64(client.NumCachedSeries())
220-
})
221-
222-
seriesSetCacheCap := prometheus.NewGaugeFunc(prometheus.GaugeOpts{
223-
Namespace: promNamespace,
224-
Name: "series_set_cache_capacity",
225-
Help: "Maximum number of elements in the series-set cache.",
226-
}, func() float64 {
227-
return float64(client.SeriesCacheCapacity())
228-
})
229-
230214
cachedLabels := prometheus.NewCounterFunc(prometheus.CounterOpts{
231215
Namespace: promNamespace,
232216
Name: "label_cache_elements_stored",
@@ -245,8 +229,6 @@ func main() {
245229

246230
prometheus.MustRegister(cachedMetricNames)
247231
prometheus.MustRegister(metricNamesCacheCap)
248-
prometheus.MustRegister(cachedSeriesSets)
249-
prometheus.MustRegister(seriesSetCacheCap)
250232
prometheus.MustRegister(cachedLabels)
251233
prometheus.MustRegister(labelsCacheCap)
252234

@@ -264,7 +246,6 @@ func main() {
264246
FailedQueries: failedQueries,
265247
ReceivedQueries: receivedQueries,
266248
CachedMetricNames: cachedMetricNames,
267-
CachedSeriesSets: cachedSeriesSets,
268249
CachedLabels: cachedLabels,
269250
}
270251
writeHandler := timeHandler(httpRequestDuration, "write", api.Write(client, elector, &promMetrics))

pkg/api/metrics.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ type Metrics struct {
1919
FailedQueries prometheus.Counter
2020
QueryBatchDuration prometheus.Histogram
2121
CachedMetricNames prometheus.CounterFunc
22-
CachedSeriesSets prometheus.CounterFunc
2322
CachedLabels prometheus.CounterFunc
2423
}

pkg/pgclient/client.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ func ParseFlags(cfg *Config) *Config {
4848
flag.IntVar(&cfg.ReportInterval, "tput-report", 0, "interval in seconds at which throughput should be reported")
4949
flag.Uint64Var(&cfg.LabelsCacheSize, "labels-cache-size", 10000, "maximum number of labels to cache")
5050
flag.Uint64Var(&cfg.MetricsCacheSize, "metrics-cache-size", pgmodel.DefaultMetricCacheSize, "maximum number of metric names to cache")
51-
flag.Uint64Var(&cfg.SeriesCacheSize, "series-cache-size", pgmodel.DefaultSeriesCacheSize, "maximum number of series-sets to cache")
5251
return cfg
5352
}
5453

@@ -130,14 +129,6 @@ func (c *Client) Read(req *prompb.ReadRequest) (*prompb.ReadResponse, error) {
130129
return c.reader.Read(req)
131130
}
132131

133-
func (c *Client) NumCachedSeries() int {
134-
return c.ingestor.NumCachedSeries()
135-
}
136-
137-
func (c *Client) SeriesCacheCapacity() int {
138-
return c.ingestor.SeriesCacheCapacity()
139-
}
140-
141132
func (c *Client) NumCachedMetricNames() int {
142133
return c.metricCache.NumElements()
143134
}

pkg/pgmodel/cache.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,13 @@ import (
1313

1414
const (
1515
DefaultMetricCacheSize = 10000
16-
DefaultSeriesCacheSize = 100000
1716
)
1817

1918
var (
2019
// ErrEntryNotFound is returned when entry is not found.
2120
ErrEntryNotFound = fmt.Errorf("entry not found")
2221
)
2322

24-
type seriesCache struct {
25-
series *clockcache.Cache
26-
}
27-
28-
var _ SeriesCache = (*seriesCache)(nil)
29-
30-
func (b *seriesCache) GetSeries(lset Labels) (SeriesID, error) {
31-
result, ok := b.series.Get(lset.String())
32-
if !ok {
33-
return 0, ErrEntryNotFound
34-
}
35-
return result.(SeriesID), nil
36-
}
37-
38-
func (b *seriesCache) SetSeries(lset Labels, id SeriesID) error {
39-
b.series.Insert(lset.String(), id)
40-
return nil
41-
}
42-
43-
func (b *seriesCache) NumElements() int {
44-
return b.series.Len()
45-
}
46-
47-
func (b *seriesCache) Capacity() int {
48-
return b.series.Cap()
49-
}
50-
5123
// MetricNameCache stores and retrieves metric table names in a in-memory cache.
5224
type MetricNameCache struct {
5325
Metrics *clockcache.Cache

pkg/pgmodel/cache_test.go

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -12,84 +12,6 @@ import (
1212
"github.com/timescale/timescale-prometheus/pkg/clockcache"
1313
)
1414

15-
func TestCache(t *testing.T) {
16-
cache := seriesCache{
17-
series: clockcache.WithMax(100),
18-
}
19-
20-
label := labels.Labels{
21-
labels.Label{
22-
Name: "name1",
23-
Value: "val1",
24-
},
25-
}
26-
27-
l, err := LabelsFromSlice(label)
28-
if err != nil {
29-
t.Errorf("invalid labels %+v: %v", l, err)
30-
}
31-
if _, err := cache.GetSeries(*l); err == nil {
32-
t.Errorf("found cache for a series that was not stored")
33-
}
34-
35-
testLabels := []labels.Labels{
36-
{
37-
labels.Label{
38-
Name: "name1",
39-
Value: "val1",
40-
},
41-
},
42-
{
43-
labels.Label{
44-
Name: "name1",
45-
Value: "val2",
46-
},
47-
},
48-
{
49-
labels.Label{
50-
Name: "name2",
51-
Value: "val2",
52-
},
53-
},
54-
{
55-
labels.Label{
56-
Name: "name1",
57-
Value: "val1",
58-
},
59-
labels.Label{
60-
Name: "name2",
61-
Value: "val2",
62-
},
63-
},
64-
}
65-
66-
for i, series := range testLabels {
67-
ls, err := LabelsFromSlice(series)
68-
if err != nil {
69-
t.Errorf("invalid series %+v, %v", ls, err)
70-
}
71-
if err := cache.SetSeries(*ls, SeriesID(i)); err != nil {
72-
t.Errorf("got unexpected error while storing series: %d", i)
73-
74-
}
75-
}
76-
77-
for i, series := range testLabels {
78-
var res SeriesID
79-
ls, err := LabelsFromSlice(series)
80-
if err != nil {
81-
t.Errorf("invalid series %+v, %v", ls, err)
82-
}
83-
if res, err = cache.GetSeries(*ls); err != nil {
84-
t.Errorf("got unexpected error while getting series: %v", series)
85-
}
86-
if res != SeriesID(i) {
87-
t.Errorf("wrong id returned: got %v expected %v", res, i)
88-
}
89-
}
90-
91-
}
92-
9315
func TestBigLables(t *testing.T) {
9416
builder := strings.Builder{}
9517
builder.Grow(int(^uint16(0)) + 1) // one greater than uint16 max

pkg/pgmodel/ingestor.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ type samplesInfo struct {
5050

5151
// DBIngestor ingest the TimeSeries data into Timescale database.
5252
type DBIngestor struct {
53-
cache SeriesCache
54-
db inserter
53+
db inserter
5554
}
5655

5756
// Ingest transforms and ingests the timeseries data into Timescale database.
@@ -107,14 +106,6 @@ func (i *DBIngestor) parseData(tts []prompb.TimeSeries, req *prompb.WriteRequest
107106
return dataSamples, rows, nil
108107
}
109108

110-
func (i *DBIngestor) NumCachedSeries() int {
111-
return i.cache.NumElements()
112-
}
113-
114-
func (i *DBIngestor) SeriesCacheCapacity() int {
115-
return i.cache.Capacity()
116-
}
117-
118109
// Close closes the ingestor
119110
func (i *DBIngestor) Close() {
120111
i.db.Close()

pkg/pgmodel/ingestor_test.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,20 +248,14 @@ func TestDBIngestorIngest(t *testing.T) {
248248

249249
for _, c := range testCases {
250250
t.Run(c.name, func(t *testing.T) {
251-
cache := &mockCache{
252-
seriesCache: make(map[string]SeriesID),
253-
setSeriesErr: c.setSeriesErr,
254-
getSeriesErr: c.getSeriesErr,
255-
}
256251
inserter := mockInserter{
257252
insertSeriesErr: c.insertSeriesErr,
258253
insertDataErr: c.insertDataErr,
259254
insertedSeries: make(map[string]SeriesID),
260255
}
261256

262257
i := DBIngestor{
263-
cache: cache,
264-
db: &inserter,
258+
db: &inserter,
265259
}
266260

267261
count, err := i.Ingest(c.metrics, NewWriteRequest())

pkg/pgmodel/pgx.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,7 @@ func NewPgxIngestorWithMetricCache(c *pgxpool.Pool, cache MetricCache, cfg *Cfg)
206206
return nil, err
207207
}
208208

209-
bc := &seriesCache{clockcache.WithMax(cfg.SeriesCacheSize)}
210-
211-
return &DBIngestor{
212-
db: pi,
213-
cache: bc,
214-
}, nil
209+
return &DBIngestor{db: pi}, nil
215210
}
216211

217212
// NewPgxIngestor returns a new Ingestor that write to PostgreSQL using PGX

0 commit comments

Comments
 (0)