Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

add custom metric types #23

Merged
merged 23 commits into from Aug 11, 2016
Commits
Jump to file or symbol
Failed to load files and symbols.
+22 −13
Split
Viewing a subset of changes. View all
View
@@ -1026,10 +1026,10 @@ func TestCounterVector(t *testing.T) {
t.Errorf("cannot set an instance, error: %v", err)
}
- if val, err := cv.Val("m1"); val != 10 {
+ if val, verr := cv.Val("m1"); val != 10 {
t.Errorf("expected m.1[m1] to be 10, got %v", val)
- } else if err != nil {
- t.Errorf("cannot retrieve m.1[m1] value")
+ } else if verr != nil {
+ t.Errorf("cannot retrieve m.1[m1] value, error: %v", err)
}
// Inc
@@ -1039,9 +1039,9 @@ func TestCounterVector(t *testing.T) {
t.Errorf("cannot inc an instance, error: %v", err)
}
- if val, err := cv.Val("m2"); val != 12 {
+ if val, verr := cv.Val("m2"); val != 12 {
t.Errorf("expected m.1[m2] to be 12, got %v", val)
- } else if err != nil {
- t.Errorf("cannot retrieve m.1[m2] value")
+ } else if verr != nil {
+ t.Errorf("cannot retrieve m.1[m2] value, error: %v", err)
}
}
View
@@ -802,8 +802,10 @@ type CounterVector interface {
Val(string) int64
Set(int64, string) error
+ MustSet(int64, string)
Inc(int64, string) error
+ MustInc(int64, string)
Up(string)
}
@@ -862,6 +864,13 @@ func (c *PCPCounterVector) Set(val int64, instance string) error {
return c.PCPInstanceMetric.SetInstance(instance, val)
}
+// MustSet panics if Set fails
+func (c *PCPCounterVector) MustSet(val int64, instance string) {
+ if err := c.Set(val, instance); err != nil {
+ panic(err)
+ }
+}
+
// Inc increments the value of a particular instance of PCPCounterVector
func (c *PCPCounterVector) Inc(inc int64, instance string) error {
if inc < 0 {
@@ -880,14 +889,14 @@ func (c *PCPCounterVector) Inc(inc int64, instance string) error {
return c.Set(v+inc, instance)
}
-// Up increments the value of a particular instance ny 1
-func (c *PCPCounterVector) Up(instance string) error {
- v, err := c.Val(instance)
- if err != nil {
- return err
+// MustInc panics if Inc fails
+func (c *PCPCounterVector) MustInc(inc int64, instance string) {
+ if err := c.Inc(inc, instance); err != nil {
+ panic(err)
}
-
- return c.Set(v+1, instance)
}
+// Up increments the value of a particular instance ny 1
+func (c *PCPCounterVector) Up(instance string) { c.MustInc(1, instance) }
+
///////////////////////////////////////////////////////////////////////////////