-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple output improvements (also make simple output format default) (#…
…519) * make two reporter implementations - zap and console * make simple log format default and use new reporters * separated metrics into several smaller files * linter fixes * completely separated metrics data from reporters * linter fixes
- Loading branch information
1 parent
1db31d7
commit 8ac3e4e
Showing
7 changed files
with
294 additions
and
208 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package metrics | ||
|
||
// Accumulator for statistical metrics for use in a single job. Requires Flush()-ing to Reporter. | ||
// Not concurrency-safe. | ||
type Accumulator struct { | ||
jobID string | ||
stats [NumStats]map[string]uint64 // Array of metrics by Stat. Each metric is a map of uint64 values by target. | ||
metrics *Metrics | ||
} | ||
|
||
type dimensions struct { | ||
jobID string | ||
target string | ||
} | ||
|
||
// Add n to the Accumulator Stat value. Returns self for chaining. | ||
func (a *Accumulator) Add(target string, s Stat, n uint64) *Accumulator { | ||
a.stats[s][target] += n | ||
|
||
return a | ||
} | ||
|
||
// Inc increases Accumulator Stat value by 1. Returns self for chaining. | ||
func (a *Accumulator) Inc(target string, s Stat) *Accumulator { return a.Add(target, s, 1) } | ||
|
||
// Flush Accumulator contents to the Reporter. | ||
func (a *Accumulator) Flush() { | ||
for stat := RequestsAttemptedStat; stat < NumStats; stat++ { | ||
for target, value := range a.stats[stat] { | ||
a.metrics[stat].Store(dimensions{jobID: a.jobID, target: target}, value) | ||
} | ||
} | ||
} | ||
|
||
// Clone a new, blank metrics Accumulator with the same Reporter as the original. | ||
func (a *Accumulator) Clone(jobID string) *Accumulator { | ||
if a == nil { | ||
return nil | ||
} | ||
|
||
return newAccumulator(jobID, a.metrics) | ||
} | ||
|
||
func newAccumulator(jobID string, data *Metrics) *Accumulator { | ||
res := &Accumulator{ | ||
jobID: jobID, | ||
metrics: data, | ||
} | ||
|
||
for s := RequestsAttemptedStat; s < NumStats; s++ { | ||
res.stats[s] = make(map[string]uint64) | ||
} | ||
|
||
return res | ||
} |
Oops, something went wrong.