Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boltdb shipper metrics changes #2790

Merged
merged 3 commits into from
Oct 25, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 12 additions & 2 deletions pkg/storage/stores/shipper/downloads/table_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,20 @@ func (tm *TableManager) getOrCreateTable(spanCtx context.Context, tableName stri
return table
}

func (tm *TableManager) syncTables(ctx context.Context) error {
func (tm *TableManager) syncTables(ctx context.Context) (err error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the other style of not defining the variable name in the method.

This is usually how we do it and I like that return nil at the end is a little more explicit.

tm.tablesMtx.RLock()
defer tm.tablesMtx.RUnlock()

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 {
Expand All @@ -176,7 +186,7 @@ func (tm *TableManager) syncTables(ctx context.Context) error {
}
}

return nil
return
}

func (tm *TableManager) cleanupCache() error {
Expand Down