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

some metrics for measuring performance and failures in boltdb shipper #2034

Merged
merged 3 commits into from
May 13, 2020

Conversation

sandeepsukhani
Copy link
Contributor

What this PR does / why we need it:
Adds following metrics for measuring performance and failures in boltdb shipper.

  • loki_boltdb_shipper_files_download_failures_total: Total number of failures in downloading files from shared store.
  • loki_boltdb_shipper_files_upload_failures_total: Total number of failures in uploading files from shared store.
  • loki_boltdb_shipper_initial_files_download_duration_seconds: Measures download time per period only for initial download since that is what would impact query performance.
  • loki_boltdb_shipper_initial_files_download_size_bytes: Measures total files size per period only for initial download since that is what would impact query performance.
  • loki_boltdb_shipper_request_duration_seconds: Histogram measuring time(in seconds) spent in processing requests. We do only read requests for now.

@codecov-io
Copy link

codecov-io commented May 4, 2020

Codecov Report

Merging #2034 into master will decrease coverage by 0.01%.
The diff coverage is 84.46%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2034      +/-   ##
==========================================
- Coverage   64.05%   64.03%   -0.02%     
==========================================
  Files         133      134       +1     
  Lines       10217    10296      +79     
==========================================
+ Hits         6544     6593      +49     
- Misses       3185     3210      +25     
- Partials      488      493       +5     
Impacted Files Coverage Δ
pkg/loki/loki.go 0.00% <0.00%> (ø)
pkg/storage/stores/local/uploads.go 55.93% <54.54%> (+0.37%) ⬆️
pkg/storage/stores/local/downloads.go 63.20% <63.63%> (+1.38%) ⬆️
pkg/storage/stores/local/shipper.go 54.19% <80.00%> (+0.97%) ⬆️
pkg/storage/store.go 70.79% <100.00%> (+0.52%) ⬆️
pkg/storage/stores/local/boltdb_index_client.go 62.96% <100.00%> (+1.42%) ⬆️
pkg/storage/stores/local/metrics.go 100.00% <100.00%> (ø)
pkg/promtail/positions/positions.go 47.32% <0.00%> (-13.40%) ⬇️
pkg/promtail/targets/tailer.go 73.86% <0.00%> (-4.55%) ⬇️
pkg/promtail/targets/filetarget.go 68.29% <0.00%> (-1.83%) ⬇️
... and 1 more

Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

I think it would be nice to count error and success of download, not just error.

@@ -235,6 +243,7 @@ func (s *Shipper) syncLocalWithStorage(ctx context.Context) error {

for period := range s.downloadedPeriods {
if err := s.syncFilesForPeriod(ctx, period, s.downloadedPeriods[period]); err != nil {
s.metrics.filesDownloadFailures.Inc()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't you track success and failure via the same counter ? I think it gives better possibilities.

level.Error(pkg_util.Logger).Log("msg", "error syncing local boltdb files with storage", "err", err)
}
s.metrics.filesDownloadOperationTotal.WithLabelValues(status).Inc()
Copy link
Contributor

Choose a reason for hiding this comment

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

a defer could do a better job but that's fine !

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @cyriltovena here -- defer would help with some code deduplication.

Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@owen-d owen-d left a comment

Choose a reason for hiding this comment

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

A few questions/nits, but great work.


type boltDBShipperMetrics struct {
// metrics for measuring performance of downloading of files per period initially i.e for the first time
initialFilesDownloadDurationSeconds *prometheus.GaugeVec
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if these are good metrics - won't they be too irregular? I expect it'll be hard to query these in prom if they're not regularly populated. I wonder if gauges which aren't updated regularly are still scraped regularly, hrm...

Also I'm wary of creating labels based on the table name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that these metrics are irregular but they are there just to help understand slow queries which would most likely happen when downloading large index file. Without this metric we would have to rely on logs to find if query is slow because of downloading of files or some other contention is there.
Regarding labels based on table names, there would not be too many tables at a time. Also without that label, we would not have much visibility because otherwise the same metric would be updated for all the table downloads and the last one which was updated before prometheus scrapes would be visible, which would not be much of a use. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The other we have is adding a span in traces and getting rid of this metric.

Copy link
Member

@owen-d owen-d May 8, 2020

Choose a reason for hiding this comment

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

My concerns about sparsely populated gauges have been alleviated (this is handled via our instrumentation lib).

However, it seems weird to be creating per-table gauges that are only written on startup/first pull. This is even more costly if tables are/eventually become per-tenant. Could this instead be calculated across all tables? I find it hard to imagine needing this level of granularity: we'll be pulling tables from the same object stores. I suspect having one gauge across all tables will be enough to help us and if we need to find one problematic table, we can use logs (we'll need to ensure per-table downloads are logged).

Did I explain that well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I understand your concern. The problem here is IndexClients get per table query so we can't have a metric across all tables downloaded for a query. Best option we have here is adding a span to the trace.

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking some shared struct which keeps individual download times/bytes for each table, then updates one gauge whenever a new table is downloaded. The gauge can be calculated from the sum of download times/bytes from each table.

Copy link
Member

Choose a reason for hiding this comment

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

Something like

type DownloadTableMetrics struct{
  gauge *prometheus.Gauge
  tables map[string]struct{
    dur time.Duration
    bytes int
  }
}

Then when downloading a table you can do

downloadTableMetrics.Add(tableName, downloadTime, byteCt), which will internally add that value then recalculate/update its underlying gauge.

level.Error(pkg_util.Logger).Log("msg", "error syncing local boltdb files with storage", "err", err)
}
s.metrics.filesDownloadOperationTotal.WithLabelValues(status).Inc()
Copy link
Member

Choose a reason for hiding this comment

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

I agree with @cyriltovena here -- defer would help with some code deduplication.

@cyriltovena
Copy link
Contributor

@owen-d I'll you take care of merging this.

Copy link
Member

@owen-d owen-d left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes, :lgtm:

@owen-d owen-d merged commit 3a28a17 into grafana:master May 13, 2020
@sandeepsukhani sandeepsukhani deleted the boltdb-shipper-metrics branch October 22, 2020 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants