Compare commits
4 Commits
v1.1.18
...
v1.1.18_hf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb9e50bdf6 | ||
|
|
cd0d177f57 | ||
|
|
ecc12f6493 | ||
|
|
b6b274eba2 |
@@ -1,11 +1,8 @@
|
|||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import "encoding/json"
|
|
||||||
|
|
||||||
// Label hold an map[string]interface{} value that can be set arbitrarily.
|
// Label hold an map[string]interface{} value that can be set arbitrarily.
|
||||||
type Label interface {
|
type Label interface {
|
||||||
Value() map[string]interface{}
|
Value() map[string]interface{}
|
||||||
String() string
|
|
||||||
Mark(map[string]interface{})
|
Mark(map[string]interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +24,6 @@ func NewStandardLabel() *StandardLabel {
|
|||||||
// StandardLabel is the standard implementation of a Label.
|
// StandardLabel is the standard implementation of a Label.
|
||||||
type StandardLabel struct {
|
type StandardLabel struct {
|
||||||
value map[string]interface{}
|
value map[string]interface{}
|
||||||
jsonStr string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Value returns label values.
|
// Value returns label values.
|
||||||
@@ -37,12 +33,5 @@ func (l *StandardLabel) Value() map[string]interface{} {
|
|||||||
|
|
||||||
// Mark records the label.
|
// Mark records the label.
|
||||||
func (l *StandardLabel) Mark(value map[string]interface{}) {
|
func (l *StandardLabel) Mark(value map[string]interface{}) {
|
||||||
buf, _ := json.Marshal(value)
|
|
||||||
l.jsonStr = string(buf)
|
|
||||||
l.value = value
|
l.value = value
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns label by JSON format.
|
|
||||||
func (l *StandardLabel) String() string {
|
|
||||||
return l.jsonStr
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -100,7 +100,11 @@ func (c *collector) addResettingTimer(name string, m metrics.ResettingTimer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) addLabel(name string, m metrics.Label) {
|
func (c *collector) addLabel(name string, m metrics.Label) {
|
||||||
c.writeLabel(mutateKey(name), m.String())
|
labels := make([]string, 0, len(m.Value()))
|
||||||
|
for k, v := range m.Value() {
|
||||||
|
labels = append(labels, fmt.Sprintf(`%s="%s"`, mutateKey(k), fmt.Sprint(v)))
|
||||||
|
}
|
||||||
|
c.writeLabel(mutateKey(name), "{"+strings.Join(labels, ", ")+"}")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) writeLabel(name string, value interface{}) {
|
func (c *collector) writeLabel(name string, value interface{}) {
|
||||||
@@ -126,5 +130,7 @@ func (c *collector) writeSummaryPercentile(name, p string, value interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func mutateKey(key string) string {
|
func mutateKey(key string) string {
|
||||||
return strings.Replace(key, "/", "_", -1)
|
key = strings.Replace(key, "/", "_", -1)
|
||||||
|
key = strings.Replace(key, "-", "_", -1)
|
||||||
|
return key
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user