Skip to content

Commit

Permalink
Boltdb shipper metrics changes (#2790)
Browse files Browse the repository at this point in the history
* rename boltdb shipper metrics to have table in their name instead of files

* Increment tables_sync_operation_total metric during periodic syncs as well

* tweak error handling

Co-authored-by: Edward Welch <edward.welch@grafana.com>
  • Loading branch information
sandeepsukhani and slim-bean authored Oct 25, 2020
1 parent 7d195a4 commit 2793499
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
20 changes: 10 additions & 10 deletions pkg/storage/stores/shipper/downloads/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,32 @@ func (m *downloadTableBytesMetric) add(period string, downloadedBytes int64) {

type metrics struct {
// metrics for measuring performance of downloading of files per period initially i.e for the first time
filesDownloadDurationSeconds *downloadTableDurationMetric
filesDownloadSizeBytes *downloadTableBytesMetric
tablesDownloadDurationSeconds *downloadTableDurationMetric
tablesDownloadSizeBytes *downloadTableBytesMetric

filesDownloadOperationTotal *prometheus.CounterVec
tablesSyncOperationTotal *prometheus.CounterVec
}

func newMetrics(r prometheus.Registerer) *metrics {
m := &metrics{
filesDownloadDurationSeconds: &downloadTableDurationMetric{
tablesDownloadDurationSeconds: &downloadTableDurationMetric{
periods: map[string]float64{},
gauge: promauto.With(r).NewGauge(prometheus.GaugeOpts{
Namespace: "loki_boltdb_shipper",
Name: "initial_files_download_duration_seconds",
Name: "initial_tables_download_duration_seconds",
Help: "Time (in seconds) spent in downloading of files per table, initially i.e for the first time",
})},
filesDownloadSizeBytes: &downloadTableBytesMetric{
tablesDownloadSizeBytes: &downloadTableBytesMetric{
periods: map[string]int64{},
gauge: promauto.With(r).NewGauge(prometheus.GaugeOpts{
Namespace: "loki_boltdb_shipper",
Name: "initial_files_download_size_bytes",
Name: "initial_tables_download_size_bytes",
Help: "Size of files (in bytes) downloaded per table, initially i.e for the first time",
})},
filesDownloadOperationTotal: promauto.With(r).NewCounterVec(prometheus.CounterOpts{
tablesSyncOperationTotal: promauto.With(r).NewCounterVec(prometheus.CounterOpts{
Namespace: "loki_boltdb_shipper",
Name: "files_download_operation_total",
Help: "Total number of download operations done by status",
Name: "tables_sync_operation_total",
Help: "Total number of tables sync operations done by status",
}, []string{"status"}),
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/storage/stores/shipper/downloads/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (t *Table) init(ctx context.Context, spanLogger log.Logger) (err error) {
}
}
}
t.metrics.filesDownloadOperationTotal.WithLabelValues(status).Inc()
t.metrics.tablesSyncOperationTotal.WithLabelValues(status).Inc()
}()

startTime := time.Now()
Expand Down Expand Up @@ -174,8 +174,8 @@ func (t *Table) init(ctx context.Context, spanLogger log.Logger) (err error) {
}

duration := time.Since(startTime).Seconds()
t.metrics.filesDownloadDurationSeconds.add(t.name, duration)
t.metrics.filesDownloadSizeBytes.add(t.name, totalFilesSize)
t.metrics.tablesDownloadDurationSeconds.add(t.name, duration)
t.metrics.tablesDownloadSizeBytes.add(t.name, totalFilesSize)
level.Debug(spanLogger).Log("total-files-size", totalFilesSize)

return
Expand Down
13 changes: 12 additions & 1 deletion pkg/storage/stores/shipper/downloads/table_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,21 @@ func (tm *TableManager) syncTables(ctx context.Context) error {
tm.tablesMtx.RLock()
defer tm.tablesMtx.RUnlock()

var err error

defer func() {
status := statusSuccess
if err != nil {
status = statusFailure
}

tm.metrics.tablesSyncOperationTotal.WithLabelValues(status).Inc()
}()

level.Info(pkg_util.Logger).Log("msg", "syncing tables")

for _, table := range tm.tables {
err := table.Sync(ctx)
err = table.Sync(ctx)
if err != nil {
return err
}
Expand Down

0 comments on commit 2793499

Please sign in to comment.