-
Notifications
You must be signed in to change notification settings - Fork 9
Add metrics for measure delete progress #181
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
19248aa
Add metrics for measure delete progress
leborchuk 1023b61
Add reporting deletion progress to logs
leborchuk 8841717
Potential fix for pull request finding
leborchuk eaa4431
Rename delete gauge metric to avoid _total suffix
Copilot 65e3c9b
Do not report delete metrics for untrashify operation
leborchuk 8ae9d3f
Revert reporting level for some message types back to INFO
leborchuk 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 hidden or 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 hidden or 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 hidden or 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,103 @@ | ||
| package metrics | ||
|
|
||
| import ( | ||
| "sync/atomic" | ||
| "time" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/prometheus/client_golang/prometheus/promauto" | ||
| ) | ||
|
|
||
| // ProgressLogInterval is how often (in cumulative processed items) callers | ||
| // should emit an Info-level progress log line, to keep log volume bounded | ||
| // during long-running delete/untrashify operations. | ||
| const ProgressLogInterval = 50000 | ||
|
|
||
| var ( | ||
| itemCountBuckets = []float64{1, 10, 50, 100, 500, 1000, 5000, 10000, 50000} | ||
|
|
||
| DeleteProcessTotal = promauto.NewGaugeVec(prometheus.GaugeOpts{ | ||
| Name: "delete_process_items", | ||
| Help: "Size of the current batch of items found to process by delete/untrashify handlers", | ||
| }, []string{"bucket", "operation"}) | ||
|
|
||
| DeleteProcessRemaining = promauto.NewGaugeVec(prometheus.GaugeOpts{ | ||
| Name: "delete_process_remaining", | ||
| Help: "Items left to process by delete/untrashify handlers", | ||
| }, []string{"bucket", "operation"}) | ||
|
|
||
| DeleteProcessProcessed = promauto.NewCounterVec(prometheus.CounterOpts{ | ||
| Name: "delete_process_processed_total", | ||
| Help: "Cumulative number of items delete/untrashify handlers attempted to delete or move", | ||
| }, []string{"bucket", "operation"}) | ||
|
|
||
| DeleteProcessDeleted = promauto.NewCounterVec(prometheus.CounterOpts{ | ||
| Name: "delete_process_deleted_total", | ||
| Help: "Cumulative number of items successfully deleted or moved", | ||
| }, []string{"bucket", "operation"}) | ||
|
|
||
| DeleteProcessKept = promauto.NewCounterVec(prometheus.CounterOpts{ | ||
| Name: "delete_process_kept_total", | ||
| Help: "Cumulative number of items intentionally left in place (skipped or failed after retries)", | ||
| }, []string{"bucket", "operation"}) | ||
|
|
||
| DeleteRequestLatency = promauto.NewHistogramVec(prometheus.HistogramOpts{ | ||
| Name: "delete_request_latency_seconds", | ||
| Help: "Latency of delete-handler list/delete operations", | ||
| Buckets: latencyBuckets, | ||
| }, []string{"bucket", "operation", "stage"}) | ||
|
|
||
| DeleteRequestSize = promauto.NewHistogramVec(prometheus.HistogramOpts{ | ||
| Name: "delete_request_size", | ||
| Help: "Number of items returned by a delete-handler list operation", | ||
| Buckets: itemCountBuckets, | ||
| }, []string{"bucket", "operation"}) | ||
| ) | ||
|
|
||
| // DeleteOpTracker reports per-bucket, per-operation progress metrics for the | ||
| // long-running delete/untrashify handlers in pkg/proc/delete_handler.go. | ||
| type DeleteOpTracker struct { | ||
| bucket string | ||
| operation string | ||
| processed atomic.Int64 | ||
| } | ||
|
|
||
| func NewDeleteOpTracker(bucket, operation string) *DeleteOpTracker { | ||
| return &DeleteOpTracker{bucket: bucket, operation: operation} | ||
| } | ||
|
|
||
| func (t *DeleteOpTracker) labels() prometheus.Labels { | ||
| return prometheus.Labels{"bucket": t.bucket, "operation": t.operation} | ||
| } | ||
|
|
||
| func (t *DeleteOpTracker) SetTotal(n int) { | ||
| DeleteProcessTotal.With(t.labels()).Set(float64(n)) | ||
| } | ||
|
|
||
| func (t *DeleteOpTracker) SetRemaining(n int) { | ||
| DeleteProcessRemaining.With(t.labels()).Set(float64(n)) | ||
| } | ||
|
|
||
| func (t *DeleteOpTracker) ObserveList(d time.Duration, itemCount int) { | ||
| DeleteRequestLatency.With(prometheus.Labels{"bucket": t.bucket, "operation": t.operation, "stage": "list"}).Observe(d.Seconds()) | ||
| DeleteRequestSize.With(t.labels()).Observe(float64(itemCount)) | ||
| } | ||
|
|
||
| func (t *DeleteOpTracker) ObserveDelete(d time.Duration) { | ||
| DeleteRequestLatency.With(prometheus.Labels{"bucket": t.bucket, "operation": t.operation, "stage": "delete"}).Observe(d.Seconds()) | ||
| } | ||
|
|
||
| // AddProcessed records n more processed items and returns the cumulative | ||
| // processed count for this tracker, for use with ProgressLogInterval. | ||
| func (t *DeleteOpTracker) AddProcessed(n int) int64 { | ||
| DeleteProcessProcessed.With(t.labels()).Add(float64(n)) | ||
| return t.processed.Add(int64(n)) | ||
| } | ||
|
|
||
| func (t *DeleteOpTracker) AddDeleted(n int) { | ||
| DeleteProcessDeleted.With(t.labels()).Add(float64(n)) | ||
| } | ||
|
|
||
| func (t *DeleteOpTracker) AddKept(n int) { | ||
| DeleteProcessKept.With(t.labels()).Add(float64(n)) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.