-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package local | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
"github.com/weaveworks/common/instrument" | ||
) | ||
|
||
const ( | ||
statusFailure = "failure" | ||
statusSuccess = "success" | ||
) | ||
|
||
type boltDBShipperMetrics struct { | ||
// metrics for measuring performance of downloading of files per period initially i.e for the first time | ||
initialFilesDownloadDurationSeconds *prometheus.GaugeVec | ||
initialFilesDownloadSizeBytes *prometheus.GaugeVec | ||
|
||
// duration in seconds spent in serving request on index managed by BoltDB Shipper | ||
requestDurationSeconds *prometheus.HistogramVec | ||
|
||
filesDownloadOperationTotal *prometheus.CounterVec | ||
filesUploadOperationTotal *prometheus.CounterVec | ||
} | ||
|
||
func newBoltDBShipperMetrics(r prometheus.Registerer) *boltDBShipperMetrics { | ||
m := &boltDBShipperMetrics{ | ||
initialFilesDownloadDurationSeconds: promauto.With(r).NewGaugeVec(prometheus.GaugeOpts{ | ||
Namespace: "loki_boltdb_shipper", | ||
Name: "initial_files_download_duration_seconds", | ||
Help: "Time (in seconds) spent in downloading of files per period, initially i.e for the first time", | ||
}, []string{"period"}), | ||
initialFilesDownloadSizeBytes: promauto.With(r).NewGaugeVec(prometheus.GaugeOpts{ | ||
Namespace: "loki_boltdb_shipper", | ||
Name: "initial_files_download_size_bytes", | ||
Help: "Size of files (in bytes) downloaded per period, initially i.e for the first time", | ||
}, []string{"period"}), | ||
requestDurationSeconds: promauto.With(r).NewHistogramVec(prometheus.HistogramOpts{ | ||
Namespace: "loki_boltdb_shipper", | ||
Name: "request_duration_seconds", | ||
Help: "Time (in seconds) spent serving requests when using boltdb shipper", | ||
Buckets: instrument.DefBuckets, | ||
}, []string{"operation", "status_code"}), | ||
filesDownloadOperationTotal: promauto.With(r).NewCounterVec(prometheus.CounterOpts{ | ||
Namespace: "loki_boltdb_shipper", | ||
Name: "files_download_operation_total", | ||
Help: "Total number of download operations done by status", | ||
}, []string{"status"}), | ||
filesUploadOperationTotal: promauto.With(r).NewCounterVec(prometheus.CounterOpts{ | ||
Namespace: "loki_boltdb_shipper", | ||
Name: "files_upload_operation_total", | ||
Help: "Total number of upload operations done by status", | ||
}, []string{"status"}), | ||
} | ||
|
||
return m | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import ( | |
chunk_util "github.com/cortexproject/cortex/pkg/chunk/util" | ||
pkg_util "github.com/cortexproject/cortex/pkg/util" | ||
"github.com/go-kit/kit/log/level" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"go.etcd.io/bbolt" | ||
|
||
"github.com/grafana/loki/pkg/storage/stores/util" | ||
|
@@ -88,12 +89,13 @@ type Shipper struct { | |
uploadedFilesMtime map[string]time.Time | ||
uploadedFilesMtimeMtx sync.RWMutex | ||
|
||
done chan struct{} | ||
wait sync.WaitGroup | ||
done chan struct{} | ||
wait sync.WaitGroup | ||
metrics *boltDBShipperMetrics | ||
} | ||
|
||
// NewShipper creates a shipper for syncing local objects with a store | ||
func NewShipper(cfg ShipperConfig, storageClient chunk.ObjectClient, boltDBGetter BoltDBGetter) (*Shipper, error) { | ||
func NewShipper(cfg ShipperConfig, storageClient chunk.ObjectClient, boltDBGetter BoltDBGetter, registerer prometheus.Registerer) (*Shipper, error) { | ||
err := chunk_util.EnsureDirectory(cfg.CacheLocation) | ||
if err != nil { | ||
return nil, err | ||
|
@@ -106,13 +108,16 @@ func NewShipper(cfg ShipperConfig, storageClient chunk.ObjectClient, boltDBGette | |
storageClient: util.NewPrefixedObjectClient(storageClient, storageKeyPrefix), | ||
done: make(chan struct{}), | ||
uploadedFilesMtime: map[string]time.Time{}, | ||
metrics: newBoltDBShipperMetrics(registerer), | ||
} | ||
|
||
shipper.uploader, err = shipper.getUploaderName() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
level.Info(pkg_util.Logger).Log("msg", fmt.Sprintf("starting boltdb shipper in %d mode", cfg.Mode)) | ||
|
||
shipper.wait.Add(1) | ||
go shipper.loop() | ||
|
||
|
@@ -164,15 +169,21 @@ func (s *Shipper) loop() { | |
for { | ||
select { | ||
case <-resyncTicker.C: | ||
status := statusSuccess | ||
err := s.syncLocalWithStorage(context.Background()) | ||
if err != nil { | ||
status = statusFailure | ||
level.Error(pkg_util.Logger).Log("msg", "error syncing local boltdb files with storage", "err", err) | ||
} | ||
s.metrics.filesDownloadOperationTotal.WithLabelValues(status).Inc() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a defer could do a better job but that's fine ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @cyriltovena here -- defer would help with some code deduplication. |
||
case <-uploadFilesTicker.C: | ||
status := statusSuccess | ||
err := s.uploadFiles(context.Background()) | ||
if err != nil { | ||
status = statusFailure | ||
level.Error(pkg_util.Logger).Log("msg", "error pushing archivable files to store", "err", err) | ||
} | ||
s.metrics.filesUploadOperationTotal.WithLabelValues(status).Inc() | ||
case <-cacheCleanupTicker.C: | ||
err := s.cleanupCache() | ||
if err != nil { | ||
|
@@ -190,10 +201,13 @@ func (s *Shipper) Stop() { | |
s.wait.Wait() | ||
|
||
// Push all boltdb files to storage before returning | ||
status := statusSuccess | ||
err := s.uploadFiles(context.Background()) | ||
if err != nil { | ||
status = statusFailure | ||
level.Error(pkg_util.Logger).Log("msg", "error pushing archivable files to store", "err", err) | ||
} | ||
s.metrics.filesUploadOperationTotal.WithLabelValues(status).Inc() | ||
|
||
s.downloadedPeriodsMtx.Lock() | ||
defer s.downloadedPeriodsMtx.Unlock() | ||
|
@@ -275,8 +289,10 @@ func (s *Shipper) forEach(ctx context.Context, period string, callback func(db * | |
s.downloadedPeriodsMtx.Unlock() | ||
|
||
if err := s.downloadFilesForPeriod(ctx, period, fc); err != nil { | ||
s.metrics.filesDownloadOperationTotal.WithLabelValues(statusFailure).Inc() | ||
return err | ||
} | ||
s.metrics.filesDownloadOperationTotal.WithLabelValues(statusSuccess).Inc() | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like
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.