-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove global metrics in store (#14439)
- Loading branch information
1 parent
750743a
commit f3dd510
Showing
22 changed files
with
153 additions
and
49 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
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,56 @@ | ||
package metrics | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/armon/go-metrics" | ||
) | ||
|
||
// StoreMetrics defines the set of metrics for the store package | ||
type StoreMetrics interface { | ||
MeasureSince(keys ...string) | ||
} | ||
|
||
var ( | ||
_ StoreMetrics = Metrics{} | ||
_ StoreMetrics = NoOpMetrics{} | ||
) | ||
|
||
// Metrics defines the metrics wrapper for the store package | ||
type Metrics struct { | ||
Labels []metrics.Label | ||
} | ||
|
||
// NewMetrics returns a new instance of the Metrics with labels set by the node operator | ||
func NewMetrics(labels [][]string) Metrics { | ||
gatherer := Metrics{} | ||
|
||
if numGlobalLables := len(labels); numGlobalLables > 0 { | ||
parsedGlobalLabels := make([]metrics.Label, numGlobalLables) | ||
for i, gl := range labels { | ||
parsedGlobalLabels[i] = metrics.Label{Name: gl[0], Value: gl[1]} | ||
} | ||
|
||
gatherer.Labels = parsedGlobalLabels | ||
} | ||
|
||
return gatherer | ||
} | ||
|
||
// MeasureSince provides a wrapper functionality for emitting a a time measure | ||
// metric with global labels (if any). | ||
func (m Metrics) MeasureSince(keys ...string) { | ||
start := time.Now() | ||
metrics.MeasureSinceWithLabels(keys, start.UTC(), m.Labels) | ||
} | ||
|
||
// NoOpMetrics is a no-op implementation of the StoreMetrics interface | ||
type NoOpMetrics struct{} | ||
|
||
// NewNoOpMetrics returns a new instance of the NoOpMetrics | ||
func NewNoOpMetrics() NoOpMetrics { | ||
return NoOpMetrics{} | ||
} | ||
|
||
// MeasureSince is a no-op implementation of the StoreMetrics interface to avoid time.Now() calls | ||
func (m NoOpMetrics) MeasureSince(keys ...string) {} |
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
Oops, something went wrong.