Skip to content

Commit aaf5010

Browse files
committed
refactor(fracmanager): reorganize package metrics
1 parent 990f82d commit aaf5010

File tree

6 files changed

+97
-113
lines changed

6 files changed

+97
-113
lines changed

fracmanager/fetcher.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
"sort"
77
"sync"
88

9-
"github.com/prometheus/client_golang/prometheus"
10-
"github.com/prometheus/client_golang/prometheus/promauto"
119
"go.uber.org/zap"
1210

1311
"github.com/ozontech/seq-db/frac"
@@ -18,35 +16,6 @@ import (
1816
"github.com/ozontech/seq-db/util"
1917
)
2018

21-
var (
22-
fetcherStagesSeconds = promauto.NewHistogramVec(prometheus.HistogramOpts{
23-
Namespace: "seq_db_store",
24-
Subsystem: "fetcher",
25-
Name: "stages_seconds",
26-
Buckets: metric.SecondsBuckets,
27-
}, []string{"stage"})
28-
fetcherIDsPerFraction = promauto.NewSummary(prometheus.SummaryOpts{
29-
Namespace: "seq_db_store",
30-
Subsystem: "fetcher",
31-
Name: "ids_per_fraction",
32-
})
33-
fetcherWithHints = promauto.NewCounter(prometheus.CounterOpts{
34-
Namespace: "seq_db_store",
35-
Subsystem: "fetcher",
36-
Name: "requests_with_hints",
37-
})
38-
fetcherWithoutHint = promauto.NewCounter(prometheus.CounterOpts{
39-
Namespace: "seq_db_store",
40-
Subsystem: "fetcher",
41-
Name: "requests_without_hints",
42-
})
43-
fetcherHintMisses = promauto.NewCounter(prometheus.CounterOpts{
44-
Namespace: "seq_db_store",
45-
Subsystem: "fetcher",
46-
Name: "hint_misses",
47-
})
48-
)
49-
5019
type Fetcher struct {
5120
sem chan struct{}
5221
}

fracmanager/fracmanager.go

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@ import (
77
"sync"
88
"time"
99

10-
"github.com/prometheus/client_golang/prometheus"
11-
"github.com/prometheus/client_golang/prometheus/promauto"
1210
"go.uber.org/atomic"
1311
"go.uber.org/zap"
1412

1513
"github.com/ozontech/seq-db/config"
1614
"github.com/ozontech/seq-db/consts"
1715
"github.com/ozontech/seq-db/frac"
1816
"github.com/ozontech/seq-db/logger"
19-
"github.com/ozontech/seq-db/metric"
2017
"github.com/ozontech/seq-db/storage"
2118
"github.com/ozontech/seq-db/storage/s3"
2219
"github.com/ozontech/seq-db/util"
@@ -251,7 +248,7 @@ func (fm *FracManager) determineOutsiders() []frac.Fraction {
251248
}
252249
}
253250

254-
metric.MaintenanceTruncateTotal.Add(float64(truncated))
251+
maintenanceTruncateTotal.Add(float64(truncated))
255252
return outsiders
256253
}
257254

@@ -276,8 +273,8 @@ func (fm *FracManager) cleanupFractions(cleanupWg *sync.WaitGroup) {
276273
offloadStart := time.Now()
277274
remote, err := fm.fracProvider.Offload(fm.ctx, outsider)
278275
if err != nil {
279-
metric.OffloadingTotal.WithLabelValues("failure").Inc()
280-
metric.OffloadingDurationSeconds.Observe(float64(time.Since(offloadStart).Seconds()))
276+
offloadingTotal.WithLabelValues("failure").Inc()
277+
offloadingDurationSeconds.Observe(float64(time.Since(offloadStart).Seconds()))
281278

282279
logger.Error(
283280
"will call Suicide() on fraction: failed to offload fraction",
@@ -298,8 +295,8 @@ func (fm *FracManager) cleanupFractions(cleanupWg *sync.WaitGroup) {
298295
return
299296
}
300297

301-
metric.OffloadingTotal.WithLabelValues("success").Inc()
302-
metric.OffloadingDurationSeconds.Observe(float64(time.Since(offloadStart).Seconds()))
298+
offloadingTotal.WithLabelValues("success").Inc()
299+
offloadingDurationSeconds.Observe(float64(time.Since(offloadStart).Seconds()))
303300

304301
logger.Info(
305302
"successully offloaded fraction",
@@ -396,13 +393,13 @@ func (fm *FracManager) processFracsStats() {
396393
util.ZapUint64AsSizeStr("index", ft.index),
397394
)
398395

399-
metric.DataSizeTotal.WithLabelValues("total", st).Set(float64(ft.totalSize))
400-
metric.DataSizeTotal.WithLabelValues("docs_raw", st).Set(float64(ft.docsRaw))
401-
metric.DataSizeTotal.WithLabelValues("docs_on_disk", st).Set(float64(ft.docsDisk))
402-
metric.DataSizeTotal.WithLabelValues("index", st).Set(float64(ft.index))
396+
dataSizeTotal.WithLabelValues("total", st).Set(float64(ft.totalSize))
397+
dataSizeTotal.WithLabelValues("docs_raw", st).Set(float64(ft.docsRaw))
398+
dataSizeTotal.WithLabelValues("docs_on_disk", st).Set(float64(ft.docsDisk))
399+
dataSizeTotal.WithLabelValues("index", st).Set(float64(ft.index))
403400

404401
if oldest != 0 {
405-
metric.OldestFracTime.WithLabelValues(st).
402+
oldestFracTime.WithLabelValues(st).
406403
Set((time.Duration(oldest) * time.Millisecond).Seconds())
407404
}
408405
}
@@ -501,19 +498,6 @@ func (fm *FracManager) Append(ctx context.Context, docs, metas storage.DocBlock)
501498
}
502499
}
503500

504-
var (
505-
sealsTotal = promauto.NewCounter(prometheus.CounterOpts{
506-
Namespace: "seq_db",
507-
Subsystem: "main",
508-
Name: "seals_total",
509-
})
510-
sealsDoneSeconds = promauto.NewSummary(prometheus.SummaryOpts{
511-
Namespace: "seq_db",
512-
Subsystem: "main",
513-
Name: "seals_done_seconds",
514-
})
515-
)
516-
517501
func (fm *FracManager) seal(activeRef activeRef) {
518502
sealsTotal.Inc()
519503
now := time.Now()

fracmanager/fraction_provider.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import (
88
"time"
99

1010
"github.com/oklog/ulid/v2"
11-
"github.com/prometheus/client_golang/prometheus"
12-
"github.com/prometheus/client_golang/prometheus/promauto"
1311

1412
"github.com/ozontech/seq-db/frac"
1513
"github.com/ozontech/seq-db/frac/common"
@@ -19,12 +17,6 @@ import (
1917
"github.com/ozontech/seq-db/storage/s3"
2018
)
2119

22-
var storeBytesRead = promauto.NewCounter(prometheus.CounterOpts{
23-
Namespace: "seq_db_store",
24-
Subsystem: "common",
25-
Name: "bytes_read",
26-
})
27-
2820
// fractionProvider is a factory for creating different types of fractions
2921
// Contains all necessary dependencies for creating and managing fractions
3022
type fractionProvider struct {

fracmanager/metrics.go

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ package fracmanager
33
import (
44
"github.com/prometheus/client_golang/prometheus"
55
"github.com/prometheus/client_golang/prometheus/promauto"
6+
7+
"github.com/ozontech/seq-db/metric"
68
)
79

810
var (
11+
// cache's metrics
912
cacheOldest = promauto.NewGaugeVec(prometheus.GaugeOpts{
1013
Namespace: "seq_db_store",
1114
Subsystem: "cache",
@@ -31,7 +34,6 @@ var (
3134
Subsystem: "cache",
3235
Name: "change_generations",
3336
}, []string{"cleaner"})
34-
3537
cacheSizeReleased = promauto.NewCounterVec(prometheus.CounterOpts{
3638
Namespace: "seq_db_store",
3739
Subsystem: "cache",
@@ -88,10 +90,94 @@ var (
8890
Name: "miss_latency_sec",
8991
}, []string{"layer"})
9092

93+
// fetcher's metrics
94+
fetcherStagesSeconds = promauto.NewHistogramVec(prometheus.HistogramOpts{
95+
Namespace: "seq_db_store",
96+
Subsystem: "fetcher",
97+
Name: "stages_seconds",
98+
Buckets: metric.SecondsBuckets,
99+
}, []string{"stage"})
100+
fetcherIDsPerFraction = promauto.NewSummary(prometheus.SummaryOpts{
101+
Namespace: "seq_db_store",
102+
Subsystem: "fetcher",
103+
Name: "ids_per_fraction",
104+
})
105+
fetcherWithHints = promauto.NewCounter(prometheus.CounterOpts{
106+
Namespace: "seq_db_store",
107+
Subsystem: "fetcher",
108+
Name: "requests_with_hints",
109+
})
110+
fetcherWithoutHint = promauto.NewCounter(prometheus.CounterOpts{
111+
Namespace: "seq_db_store",
112+
Subsystem: "fetcher",
113+
Name: "requests_without_hints",
114+
})
115+
fetcherHintMisses = promauto.NewCounter(prometheus.CounterOpts{
116+
Namespace: "seq_db_store",
117+
Subsystem: "fetcher",
118+
Name: "hint_misses",
119+
})
120+
121+
// searchers's metrics
122+
searchSubSearches = promauto.NewHistogram(prometheus.HistogramOpts{
123+
Namespace: "seq_db_store",
124+
Subsystem: "search",
125+
Name: "sub_searches",
126+
Buckets: []float64{0.99, 1, 1.01, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048},
127+
})
128+
129+
// fraction lifecycle metrics
130+
sealsTotal = promauto.NewCounter(prometheus.CounterOpts{
131+
Namespace: "seq_db",
132+
Subsystem: "main",
133+
Name: "seals_total",
134+
})
135+
sealsDoneSeconds = promauto.NewSummary(prometheus.SummaryOpts{
136+
Namespace: "seq_db",
137+
Subsystem: "main",
138+
Name: "seals_done_seconds",
139+
})
140+
maintenanceTruncateTotal = promauto.NewCounter(prometheus.CounterOpts{
141+
Namespace: "seq_db_store",
142+
Subsystem: "maintenance",
143+
Name: "truncate_total",
144+
Help: "",
145+
})
146+
offloadingTotal = promauto.NewCounterVec(prometheus.CounterOpts{
147+
Namespace: "seq_db_store",
148+
Subsystem: "offloading",
149+
Name: "total",
150+
Help: "How many fractions were offloaded",
151+
}, []string{"status"})
152+
offloadingDurationSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
153+
Namespace: "seq_db_store",
154+
Subsystem: "offloading",
155+
Name: "duration_seconds",
156+
Help: "How many seconds it took to offload fraction to remote storage",
157+
Buckets: metric.SecondsBuckets,
158+
})
159+
dataSizeTotal = promauto.NewGaugeVec(prometheus.GaugeOpts{
160+
Namespace: "seq_db_store",
161+
Subsystem: "common",
162+
Name: "data_size_total",
163+
}, []string{"kind", "storage_type"})
164+
oldestFracTime = promauto.NewGaugeVec(prometheus.GaugeOpts{
165+
Namespace: "seq_db_store",
166+
Subsystem: "common",
167+
Name: "oldest_frac_time",
168+
Help: "",
169+
}, []string{"storage_type"})
91170
fractionLoadErrors = promauto.NewCounter(prometheus.CounterOpts{
92171
Namespace: "seq_db_store",
93172
Subsystem: "main",
94173
Name: "fraction_load_errors",
95174
Help: "Doc file load errors (missing or invalid doc file)",
96175
})
176+
177+
// disk load metric
178+
storeBytesRead = promauto.NewCounter(prometheus.CounterOpts{
179+
Namespace: "seq_db_store",
180+
Subsystem: "common",
181+
Name: "bytes_read",
182+
})
97183
)

fracmanager/searcher.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import (
66
"sort"
77
"sync"
88

9-
"github.com/prometheus/client_golang/prometheus"
10-
"github.com/prometheus/client_golang/prometheus/promauto"
11-
129
"github.com/ozontech/seq-db/consts"
1310
"github.com/ozontech/seq-db/frac"
1411
"github.com/ozontech/seq-db/frac/processor"
@@ -18,16 +15,6 @@ import (
1815
"github.com/ozontech/seq-db/util"
1916
)
2017

21-
var (
22-
searchSubSearches = promauto.NewHistogram(prometheus.HistogramOpts{
23-
Namespace: "seq_db_store",
24-
Subsystem: "search",
25-
Name: "sub_searches",
26-
Help: "",
27-
Buckets: []float64{0.99, 1, 1.01, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048},
28-
})
29-
)
30-
3118
type SearcherCfg struct {
3219
MaxFractionHits int // the maximum number of fractions used in the search
3320
FractionsPerIteration int

metric/store.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,6 @@ import (
66
)
77

88
var (
9-
DataSizeTotal = promauto.NewGaugeVec(prometheus.GaugeOpts{
10-
Namespace: "seq_db_store",
11-
Subsystem: "common",
12-
Name: "data_size_total",
13-
Help: "",
14-
}, []string{"kind", "storage_type"})
15-
16-
OldestFracTime = promauto.NewGaugeVec(prometheus.GaugeOpts{
17-
Namespace: "seq_db_store",
18-
Subsystem: "common",
19-
Name: "oldest_frac_time",
20-
Help: "",
21-
}, []string{"storage_type"})
22-
239
BulkDurationSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
2410
Namespace: "seq_db_store",
2511
Subsystem: "bulk",
@@ -116,12 +102,6 @@ var (
116102
Help: "",
117103
Buckets: prometheus.ExponentialBuckets(256, 4, 32),
118104
})
119-
MaintenanceTruncateTotal = promauto.NewCounter(prometheus.CounterOpts{
120-
Namespace: "seq_db_store",
121-
Subsystem: "maintenance",
122-
Name: "truncate_total",
123-
Help: "",
124-
})
125105

126106
StoreReady = promauto.NewGauge(prometheus.GaugeOpts{
127107
Namespace: "seq_db_store",
@@ -154,18 +134,4 @@ var (
154134
SkippedIndexesBytesText = skippedIndexesBytes.WithLabelValues("text")
155135
SkippedIndexesBytesKeyword = skippedIndexesBytes.WithLabelValues("keyword")
156136
SkippedIndexesBytesPath = skippedIndexesBytes.WithLabelValues("path")
157-
158-
OffloadingTotal = promauto.NewCounterVec(prometheus.CounterOpts{
159-
Namespace: "seq_db_store",
160-
Subsystem: "offloading",
161-
Name: "total",
162-
Help: "How many fractions were offloaded",
163-
}, []string{"status"})
164-
OffloadingDurationSeconds = promauto.NewHistogram(prometheus.HistogramOpts{
165-
Namespace: "seq_db_store",
166-
Subsystem: "offloading",
167-
Name: "duration_seconds",
168-
Help: "How many seconds it took to offload fraction to remote storage",
169-
Buckets: SecondsBuckets,
170-
})
171137
)

0 commit comments

Comments
 (0)