mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 17:15:56 +00:00
Move logging and reporting back to defer'd track()
This commit is contained in:
parent
0e5ba0c56f
commit
57f9dcf44a
1 changed files with 15 additions and 13 deletions
28
fragment.go
28
fragment.go
|
|
@ -995,11 +995,26 @@ func (f *Fragment) Snapshot() error {
|
|||
defer f.mu.Unlock()
|
||||
return f.snapshot()
|
||||
}
|
||||
func track(start time.Time, message string, stats StatsClient, logger *log.Logger) {
|
||||
elapsed := time.Since(start)
|
||||
logger.Printf("%s took %s", message, elapsed)
|
||||
stats.Count("snapshot.count", 1)
|
||||
stats.Histogram("snapshot.duration", elapsed.Seconds())
|
||||
}
|
||||
|
||||
func (f *Fragment) snapshot() error {
|
||||
logger := f.logger()
|
||||
logger.Printf("fragment: snapshotting %s/%s/%s/%d", f.db, f.frame, f.view, f.slice)
|
||||
completeMessage := fmt.Sprintf("fragment: snapshot complete %s/%s/%s/%d", f.db, f.frame, f.view, f.slice)
|
||||
statsTags := []string{
|
||||
"db:" + f.db,
|
||||
"frame:" + f.frame,
|
||||
"view:" + f.view,
|
||||
fmt.Sprintf("slice:%d", f.slice),
|
||||
}
|
||||
stats := f.stats.WithTags(statsTags...)
|
||||
start := time.Now()
|
||||
defer track(start, completeMessage, stats, logger)
|
||||
|
||||
// Create a temporary file to snapshot to.
|
||||
snapshotPath := f.path + SnapshotExt
|
||||
|
|
@ -1035,19 +1050,6 @@ func (f *Fragment) snapshot() error {
|
|||
// Reset operation count.
|
||||
f.opN = 0
|
||||
|
||||
elapsed := time.Since(start)
|
||||
message := fmt.Sprintf("fragment: snapshot complete %s/%s/%s/%d", f.db, f.frame, f.view, f.slice)
|
||||
logger.Printf("%s took %s", message, elapsed)
|
||||
|
||||
statsTags := []string{
|
||||
"db:" + f.db,
|
||||
"frame:" + f.frame,
|
||||
"view:" + f.view,
|
||||
fmt.Sprintf("slice:%d", f.slice),
|
||||
}
|
||||
stats := f.stats.WithTags(statsTags...)
|
||||
stats.Count("snapshot.count", 1)
|
||||
stats.Histogram("snapshot.duration", elapsed.Seconds())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue