Labeled metrics interface 07/6807/1 v0.9.5
authorJuha Hyttinen <juha.hyttinen@nokia.com>
Thu, 30 Sep 2021 21:13:12 +0000 (00:13 +0300)
committerJuha Hyttinen <juha.hyttinen@nokia.com>
Thu, 30 Sep 2021 21:13:12 +0000 (00:13 +0300)
Shall replace old vector Register+Get approach.

Signed-off-by: Juha Hyttinen <juha.hyttinen@nokia.com>
Change-Id: I9069e50ad457f20c8d5e135136f29f79c3cb02e2

pkg/xapp/metrics.go
pkg/xapp/metrics_test.go

index 4f673d0..a90aaed 100644 (file)
@@ -233,9 +233,9 @@ func (m *Metrics) getFullName(opts prometheus.Opts, labels []string) string {
        return fmt.Sprintf("%s_%s_%s_%s", opts.Namespace, opts.Subsystem, opts.Name, labelname)
 }
 
-/*
- * Handling counters
- */
+//
+//
+//
 func (m *Metrics) RegisterCounter(opts CounterOpts, subsytem string) Counter {
        globalLock.Lock()
        defer globalLock.Unlock()
@@ -249,6 +249,9 @@ func (m *Metrics) RegisterCounter(opts CounterOpts, subsytem string) Counter {
        return cache_allcounters[id]
 }
 
+//
+//
+//
 func (m *Metrics) RegisterCounterGroup(optsgroup []CounterOpts, subsytem string) map[string]Counter {
        c := make(map[string]Counter)
        for _, opts := range optsgroup {
@@ -257,9 +260,51 @@ func (m *Metrics) RegisterCounterGroup(optsgroup []CounterOpts, subsytem string)
        return c
 }
 
-/*
- * Handling gauges
- */
+//
+//
+//
+func (m *Metrics) RegisterLabeledCounter(opts CounterOpts, labelNames []string, labelValues []string, subsytem string) Counter {
+       globalLock.Lock()
+       defer globalLock.Unlock()
+       opts.Namespace = m.Namespace
+       opts.Subsystem = subsytem
+       vecid := m.getFullName(prometheus.Opts(opts), []string{})
+       if _, ok := cache_allcountervects[vecid]; !ok {
+               Logger.Info("Register new counter vector with opts: %v labelNames: %v", opts, labelNames)
+               entry := CounterVec{}
+               entry.Opts = opts
+               entry.Labels = labelNames
+               entry.Vec = promauto.NewCounterVec(prometheus.CounterOpts(entry.Opts), entry.Labels)
+               cache_allcountervects[vecid] = entry
+       }
+       entry := cache_allcountervects[vecid]
+       if strSliceCompare(entry.Labels, labelNames) == false {
+               Logger.Warn("id:%s cached counter vec labels dont match %v != %v", vecid, entry.Labels, labelNames)
+       }
+
+       valid := m.getFullName(prometheus.Opts(entry.Opts), labelValues)
+       if _, ok := cache_allcounters[valid]; !ok {
+               Logger.Info("Register new counter from vector with opts: %v labelValues: %v", entry.Opts, labelValues)
+               cache_allcounters[valid] = entry.Vec.WithLabelValues(labelValues...)
+       }
+       return cache_allcounters[valid]
+
+}
+
+//
+//
+//
+func (m *Metrics) RegisterLabeledCounterGroup(optsgroup []CounterOpts, labelNames []string, labelValues []string, subsytem string) map[string]Counter {
+       c := make(map[string]Counter)
+       for _, opts := range optsgroup {
+               c[opts.Name] = m.RegisterLabeledCounter(opts, labelNames, labelValues, subsytem)
+       }
+       return c
+}
+
+//
+//
+//
 func (m *Metrics) RegisterGauge(opts CounterOpts, subsytem string) Gauge {
        globalLock.Lock()
        defer globalLock.Unlock()
@@ -273,6 +318,9 @@ func (m *Metrics) RegisterGauge(opts CounterOpts, subsytem string) Gauge {
        return cache_allgauges[id]
 }
 
+//
+//
+//
 func (m *Metrics) RegisterGaugeGroup(optsgroup []CounterOpts, subsytem string) map[string]Gauge {
        c := make(map[string]Gauge)
        for _, opts := range optsgroup {
@@ -281,6 +329,47 @@ func (m *Metrics) RegisterGaugeGroup(optsgroup []CounterOpts, subsytem string) m
        return c
 }
 
+//
+//
+//
+func (m *Metrics) RegisterLabeledGauge(opt CounterOpts, labelNames []string, labelValues []string, subsytem string) Gauge {
+       globalLock.Lock()
+       defer globalLock.Unlock()
+       opt.Namespace = m.Namespace
+       opt.Subsystem = subsytem
+       vecid := m.getFullName(prometheus.Opts(opt), []string{})
+       if _, ok := cache_allgaugevects[vecid]; !ok {
+               Logger.Info("Register new gauge vector with opt: %v labelNames: %v", opt, labelNames)
+               entry := GaugeVec{}
+               entry.Opts = opt
+               entry.Labels = labelNames
+               entry.Vec = promauto.NewGaugeVec(prometheus.GaugeOpts(entry.Opts), entry.Labels)
+               cache_allgaugevects[vecid] = entry
+       }
+       entry := cache_allgaugevects[vecid]
+       if strSliceCompare(entry.Labels, labelNames) == false {
+               Logger.Warn("id:%s cached gauge vec labels dont match %v != %v", vecid, entry.Labels, labelNames)
+       }
+       valid := m.getFullName(prometheus.Opts(entry.Opts), labelValues)
+       if _, ok := cache_allgauges[valid]; !ok {
+               Logger.Info("Register new gauge from vector with opts: %v labelValues: %v", entry.Opts, labelValues)
+               cache_allgauges[valid] = entry.Vec.WithLabelValues(labelValues...)
+       }
+       return cache_allgauges[valid]
+
+}
+
+//
+//
+//
+func (m *Metrics) RegisterLabeledGaugeGroup(opts []CounterOpts, labelNames []string, labelValues []string, subsytem string) map[string]Gauge {
+       c := make(map[string]Gauge)
+       for _, opt := range opts {
+               c[opt.Name] = m.RegisterLabeledGauge(opt, labelNames, labelValues, subsytem)
+       }
+       return c
+}
+
 /*
  * Handling counter vectors
  *
@@ -308,6 +397,7 @@ func (m *Metrics) RegisterGaugeGroup(optsgroup []CounterOpts, subsytem string) m
        stats["counter1"].Inc()
 */
 
+// Deprecated: Use RegisterLabeledCounter
 func (m *Metrics) RegisterCounterVec(opts CounterOpts, labelNames []string, subsytem string) CounterVec {
        globalLock.Lock()
        defer globalLock.Unlock()
@@ -329,6 +419,7 @@ func (m *Metrics) RegisterCounterVec(opts CounterOpts, labelNames []string, subs
        return entry
 }
 
+// Deprecated: Use RegisterLabeledCounterGroup
 func (m *Metrics) RegisterCounterVecGroup(optsgroup []CounterOpts, labelNames []string, subsytem string) map[string]CounterVec {
        c := make(map[string]CounterVec)
        for _, opts := range optsgroup {
@@ -337,6 +428,7 @@ func (m *Metrics) RegisterCounterVecGroup(optsgroup []CounterOpts, labelNames []
        return c
 }
 
+// Deprecated: Use RegisterLabeledCounter
 func (m *Metrics) GetCounterFromVect(labelValues []string, vec CounterVec) (c Counter) {
        globalLock.Lock()
        defer globalLock.Unlock()
@@ -348,6 +440,7 @@ func (m *Metrics) GetCounterFromVect(labelValues []string, vec CounterVec) (c Co
        return cache_allcounters[id]
 }
 
+// Deprecated: Use RegisterLabeledCounterGroup
 func (m *Metrics) GetCounterGroupFromVects(labelValues []string, vects ...map[string]CounterVec) map[string]Counter {
        c := make(map[string]Counter)
        for _, vect := range vects {
@@ -358,6 +451,7 @@ func (m *Metrics) GetCounterGroupFromVects(labelValues []string, vects ...map[st
        return c
 }
 
+// Deprecated: Use RegisterLabeledCounterGroup
 func (m *Metrics) GetCounterGroupFromVectsWithPrefix(prefix string, labelValues []string, vects ...map[string]CounterVec) map[string]Counter {
        c := make(map[string]Counter)
        for _, vect := range vects {
@@ -395,6 +489,7 @@ func (m *Metrics) GetCounterGroupFromVectsWithPrefix(prefix string, labelValues
        stats["gauge1"].Inc()
 */
 
+// Deprecated: Use RegisterLabeledGauge
 func (m *Metrics) RegisterGaugeVec(opt CounterOpts, labelNames []string, subsytem string) GaugeVec {
        globalLock.Lock()
        defer globalLock.Unlock()
@@ -416,6 +511,7 @@ func (m *Metrics) RegisterGaugeVec(opt CounterOpts, labelNames []string, subsyte
        return entry
 }
 
+// Deprecated: Use RegisterLabeledGaugeGroup
 func (m *Metrics) RegisterGaugeVecGroup(opts []CounterOpts, labelNames []string, subsytem string) map[string]GaugeVec {
        c := make(map[string]GaugeVec)
        for _, opt := range opts {
@@ -424,6 +520,7 @@ func (m *Metrics) RegisterGaugeVecGroup(opts []CounterOpts, labelNames []string,
        return c
 }
 
+// Deprecated: Use RegisterLabeledGauge
 func (m *Metrics) GetGaugeFromVect(labelValues []string, vec GaugeVec) Gauge {
        globalLock.Lock()
        defer globalLock.Unlock()
@@ -435,6 +532,7 @@ func (m *Metrics) GetGaugeFromVect(labelValues []string, vec GaugeVec) Gauge {
        return cache_allgauges[id]
 }
 
+// Deprecated: Use RegisterLabeledGaugeGroup
 func (m *Metrics) GetGaugeGroupFromVects(labelValues []string, vects ...map[string]GaugeVec) map[string]Gauge {
        c := make(map[string]Gauge)
        for _, vect := range vects {
@@ -445,6 +543,7 @@ func (m *Metrics) GetGaugeGroupFromVects(labelValues []string, vects ...map[stri
        return c
 }
 
+// Deprecated: Use RegisterLabeledGaugeGroup
 func (m *Metrics) GetGaugeGroupFromVectsWithPrefix(prefix string, labelValues []string, vects ...map[string]GaugeVec) map[string]Gauge {
        c := make(map[string]Gauge)
        for _, vect := range vects {
index 4c98c95..aad90b1 100755 (executable)
@@ -23,48 +23,6 @@ import (
        "testing"
 )
 
-var mCVect CounterVec
-var mGVect GaugeVec
-
-var mCGroupVect map[string]CounterVec
-var mGGroupVect map[string]GaugeVec
-
-func TestMetricSetup(t *testing.T) {
-       mCVect = Metric.RegisterCounterVec(CounterOpts{Name: "counter1", Help: "counter1"}, []string{"name", "event"}, "SUBSYSTEM0")
-
-       mCGroupVect = Metric.RegisterCounterVecGroup(
-               []CounterOpts{
-                       {Name: "counter1", Help: "counter1"},
-               },
-               []string{"name", "event"},
-               "SUBSYSTEM1")
-
-       mGVect = Metric.RegisterGaugeVec(CounterOpts{Name: "gauge1", Help: "gauge1"}, []string{"name", "event"}, "SUBSYSTEM0")
-
-       mGGroupVect = Metric.RegisterGaugeVecGroup(
-               []CounterOpts{
-                       {Name: "gauge1", Help: "gauge1"},
-               },
-               []string{"name", "event"},
-               "SUBSYSTEM1")
-
-       tmpCVect := Metric.RegisterCounterVec(CounterOpts{Name: "counter1", Help: "counter1"}, []string{"name", "event"}, "SUBSYSTEM0")
-
-       if tmpCVect.Vec != mCVect.Vec {
-               t.Errorf("tmpCVect not same than mCVect. cache not working?")
-       }
-
-       tmpGVect := Metric.RegisterGaugeVec(CounterOpts{Name: "gauge1", Help: "gauge1"}, []string{"name", "event"}, "SUBSYSTEM0")
-
-       if tmpGVect.Vec != mGVect.Vec {
-               t.Errorf("tmpGVect not same than mGVect. cache not working?")
-       }
-
-       Metric.RegisterCounterVec(CounterOpts{Name: "counter1", Help: "counter1"}, []string{"name", "eventMismatch"}, "SUBSYSTEM0")
-       Metric.RegisterGaugeVec(CounterOpts{Name: "gauge1", Help: "gauge1"}, []string{"name", "eventMismatch"}, "SUBSYSTEM0")
-
-}
-
 func TestMetricCounter(t *testing.T) {
        TestCounterOpt := CounterOpts{Name: "CounterBlaah1", Help: "CounterBlaah1"}
        ret1 := Metric.RegisterCounter(TestCounterOpt, "TestMetricCounter")
@@ -111,6 +69,98 @@ func TestMetricCounterGroup(t *testing.T) {
        }
 }
 
+func TestMetricLabeledCounter(t *testing.T) {
+       //
+       //
+       c_1_1 := Metric.RegisterLabeledCounter(
+               CounterOpts{Name: "counter1", Help: "counter1"},
+               []string{"name", "event"},
+               []string{"name1", "event1"},
+               "SUBSYSTEML0")
+
+       c_1_2 := Metric.RegisterLabeledCounter(
+               CounterOpts{Name: "counter1", Help: "counter1"},
+               []string{"name", "event"},
+               []string{"name1", "event1"},
+               "SUBSYSTEML0")
+
+       c_1_1.Inc()
+       c_1_2.Inc()
+       if c_1_1 != c_1_2 {
+               t.Errorf("c_1_1 not same than c_1_2. cache not working?")
+       }
+
+       //
+       //
+       c_2_1 := Metric.RegisterLabeledCounter(
+               CounterOpts{Name: "counter1", Help: "counter1"},
+               []string{"name", "event"},
+               []string{"name1", "event2"},
+               "SUBSYSTEML0")
+
+       c_2_2 := Metric.RegisterLabeledCounter(
+               CounterOpts{Name: "counter1", Help: "counter1"},
+               []string{"name", "event"},
+               []string{"name1", "event2"},
+               "SUBSYSTEML0")
+
+       c_2_1.Inc()
+       c_2_2.Inc()
+       if c_2_1 != c_2_2 {
+               t.Errorf("c_2_1 not same than c_2_2. cache not working?")
+       }
+
+       if c_1_1 == c_2_1 {
+               t.Errorf("c_1_1 same than c_2_1. what?")
+       }
+       if c_1_2 == c_2_2 {
+               t.Errorf("c_1_2 same than c_2_2. what?")
+       }
+
+}
+
+func TestMetricLabeledCounterMismatch(t *testing.T) {
+       Metric.RegisterLabeledCounter(
+               CounterOpts{Name: "counter1", Help: "counter1"},
+               []string{"name", "event"},
+               []string{"name1", "event1"},
+               "SUBSYSTEMLERR")
+
+       Metric.RegisterLabeledCounter(
+               CounterOpts{Name: "counter1", Help: "counter1"},
+               []string{"name", "eventmismatch"},
+               []string{"name1", "event1"},
+               "SUBSYSTEMLERR")
+}
+
+func TestMetricLabeledCounterGroup(t *testing.T) {
+       //
+       //
+       c_grp1 := Metric.RegisterLabeledCounterGroup(
+               []CounterOpts{{Name: "counter1", Help: "counter1"}},
+               []string{"name", "event"},
+               []string{"name1", "event1"},
+               "SUBSYSTEML1")
+
+       if _, ok := c_grp1["counter1"]; ok == false {
+               t.Errorf("c_grp1 counter1 not exists")
+       }
+       c_grp1["counter1"].Inc()
+
+       //
+       //
+       c_grp2 := Metric.RegisterLabeledCounterGroup(
+               []CounterOpts{{Name: "counter1", Help: "counter1"}},
+               []string{"name", "event"},
+               []string{"name1", "event2"},
+               "SUBSYSTEML1")
+
+       if _, ok := c_grp2["counter1"]; ok == false {
+               t.Errorf("c_grp2 counter1 not exists")
+       }
+       c_grp2["counter1"].Inc()
+}
+
 func TestMetricGauge(t *testing.T) {
        TestGaugeOpts := CounterOpts{Name: "GaugeBlaah1", Help: "GaugeBlaah1"}
        ret1 := Metric.RegisterGauge(TestGaugeOpts, "TestMetricGauge")
@@ -157,6 +207,233 @@ func TestMetricGaugeGroup(t *testing.T) {
        }
 }
 
+func TestMetricLabeledGauge(t *testing.T) {
+       //
+       //
+       c_1_1 := Metric.RegisterLabeledGauge(
+               CounterOpts{Name: "gauge1", Help: "gauge1"},
+               []string{"name", "event"},
+               []string{"name1", "event1"},
+               "SUBSYSTEML0")
+
+       c_1_2 := Metric.RegisterLabeledGauge(
+               CounterOpts{Name: "gauge1", Help: "gauge1"},
+               []string{"name", "event"},
+               []string{"name1", "event1"},
+               "SUBSYSTEML0")
+
+       c_1_1.Inc()
+       c_1_2.Inc()
+       if c_1_1 != c_1_2 {
+               t.Errorf("c_1_1 not same than c_1_2. cache not working?")
+       }
+
+       //
+       //
+       c_2_1 := Metric.RegisterLabeledGauge(
+               CounterOpts{Name: "gauge1", Help: "gauge1"},
+               []string{"name", "event"},
+               []string{"name1", "event2"},
+               "SUBSYSTEML0")
+
+       c_2_2 := Metric.RegisterLabeledGauge(
+               CounterOpts{Name: "gauge1", Help: "gauge1"},
+               []string{"name", "event"},
+               []string{"name1", "event2"},
+               "SUBSYSTEML0")
+
+       c_2_1.Inc()
+       c_2_2.Inc()
+       if c_2_1 != c_2_2 {
+               t.Errorf("c_2_1 not same than c_2_2. cache not working?")
+       }
+
+       if c_1_1 == c_2_1 {
+               t.Errorf("c_1_1 same than c_2_1. what?")
+       }
+       if c_1_2 == c_2_2 {
+               t.Errorf("c_1_2 same than c_2_2. what?")
+       }
+
+}
+
+func TestMetricLabeledGaugeMismatch(t *testing.T) {
+       Metric.RegisterLabeledGauge(
+               CounterOpts{Name: "gauge1", Help: "gauge1"},
+               []string{"name", "event"},
+               []string{"name1", "event1"},
+               "SUBSYSTEMLERR")
+
+       Metric.RegisterLabeledGauge(
+               CounterOpts{Name: "gauge1", Help: "gauge1"},
+               []string{"name", "eventmismatch"},
+               []string{"name1", "event1"},
+               "SUBSYSTEMLERR")
+}
+
+func TestMetricLabeledGaugeGroup(t *testing.T) {
+       //
+       //
+       g_grp1 := Metric.RegisterLabeledGaugeGroup(
+               []CounterOpts{{Name: "gauge1", Help: "gauge1"}},
+               []string{"name", "event"},
+               []string{"name1", "event1"},
+               "SUBSYSTEML1")
+
+       if _, ok := g_grp1["gauge1"]; ok == false {
+               t.Errorf("g_grp1 gauge1 not exists")
+       }
+       g_grp1["gauge1"].Inc()
+
+       //
+       //
+       g_grp2 := Metric.RegisterLabeledGaugeGroup(
+               []CounterOpts{{Name: "gauge1", Help: "gauge1"}},
+               []string{"name", "event"},
+               []string{"name1", "event2"},
+               "SUBSYSTEML1")
+
+       if _, ok := g_grp2["gauge1"]; ok == false {
+               t.Errorf("g_grp2 gauge1 not exists")
+       }
+       g_grp2["gauge1"].Inc()
+}
+
+func TestMetricGroupCache(t *testing.T) {
+       //
+       //
+       c_grp1 := Metric.RegisterLabeledCounterGroup(
+               []CounterOpts{{Name: "counter1", Help: "counter1"}},
+               []string{"name", "event"},
+               []string{"name1", "event1"},
+               "SUBSYSTEML1")
+       if _, ok := c_grp1["counter1"]; ok == false {
+               t.Errorf("c_grp1 counter1 not exists")
+       }
+       c_grp1["counter1"].Inc()
+
+       //
+       //
+       c_grp2 := Metric.RegisterLabeledCounterGroup(
+               []CounterOpts{{Name: "counter1", Help: "counter1"}},
+               []string{"name", "event"},
+               []string{"name1", "event2"},
+               "SUBSYSTEML1")
+       if _, ok := c_grp2["counter1"]; ok == false {
+               t.Errorf("c_grp2 counter1 not exists")
+       }
+       c_grp2["counter1"].Inc()
+
+       //
+       //
+       g_grp1 := Metric.RegisterLabeledGaugeGroup(
+               []CounterOpts{{Name: "gauge1", Help: "gauge1"}},
+               []string{"name", "event"},
+               []string{"name1", "event1"},
+               "SUBSYSTEML1")
+       if _, ok := g_grp1["gauge1"]; ok == false {
+               t.Errorf("g_grp1 gauge1 not exists")
+       }
+       g_grp1["gauge1"].Inc()
+
+       //
+       //
+       g_grp2 := Metric.RegisterLabeledGaugeGroup(
+               []CounterOpts{{Name: "gauge1", Help: "gauge1"}},
+               []string{"name", "event"},
+               []string{"name1", "event2"},
+               "SUBSYSTEML1")
+       if _, ok := g_grp2["gauge1"]; ok == false {
+               t.Errorf("g_grp2 gauge1 not exists")
+       }
+       g_grp2["gauge1"].Inc()
+
+       //
+       //
+       m_grp := NewMetricGroupsCache()
+       m_grp.CombineCounterGroupsWithPrefix("event1_", c_grp1)
+       m_grp.CombineCounterGroupsWithPrefix("event2_", c_grp2)
+       m_grp.CombineGaugeGroupsWithPrefix("event1_", g_grp1)
+       m_grp.CombineGaugeGroupsWithPrefix("event2_", g_grp2)
+
+       if m_grp == nil {
+               t.Errorf("Cache failed")
+       }
+
+       if m_grp.CIs("event1_counter1") == false {
+               t.Errorf("m_grp.Counters event1_counter1 not exists")
+       }
+       m_grp.CInc("event1_counter1")
+
+       if m_grp.CIs("event2_counter1") == false {
+               t.Errorf("m_grp.Counters event2_counter1 not exists")
+       }
+       m_grp.CInc("event2_counter1")
+
+       if m_grp.GIs("event1_gauge1") == false {
+               t.Errorf("m_grp.Gauges event1_gauge1 not exists")
+       }
+       m_grp.GInc("event1_gauge1")
+
+       if m_grp.GIs("event2_gauge1") == false {
+               t.Errorf("m_grp.Gauges event2_gauge1 not exists")
+       }
+       m_grp.GInc("event2_gauge1")
+
+       m_grp.CAdd("event2_counter1", 1)
+       m_grp.CGet("event2_counter1")
+       m_grp.GGet("event2_gauge1")
+       m_grp.GDec("event2_gauge1")
+       m_grp.GSet("event2_gauge1", 1)
+}
+
+// ----
+// VECTORS ARE OLD WAY
+// *Labeled* will do all work under the hood
+// ----
+
+var mCVect CounterVec
+var mGVect GaugeVec
+
+var mCGroupVect map[string]CounterVec
+var mGGroupVect map[string]GaugeVec
+
+func TestMetricSetup(t *testing.T) {
+       mCVect = Metric.RegisterCounterVec(CounterOpts{Name: "counter1", Help: "counter1"}, []string{"name", "event"}, "SUBSYSTEM0")
+
+       mCGroupVect = Metric.RegisterCounterVecGroup(
+               []CounterOpts{
+                       {Name: "counter1", Help: "counter1"},
+               },
+               []string{"name", "event"},
+               "SUBSYSTEM1")
+
+       mGVect = Metric.RegisterGaugeVec(CounterOpts{Name: "gauge1", Help: "gauge1"}, []string{"name", "event"}, "SUBSYSTEM0")
+
+       mGGroupVect = Metric.RegisterGaugeVecGroup(
+               []CounterOpts{
+                       {Name: "gauge1", Help: "gauge1"},
+               },
+               []string{"name", "event"},
+               "SUBSYSTEM1")
+
+       tmpCVect := Metric.RegisterCounterVec(CounterOpts{Name: "counter1", Help: "counter1"}, []string{"name", "event"}, "SUBSYSTEM0")
+
+       if tmpCVect.Vec != mCVect.Vec {
+               t.Errorf("tmpCVect not same than mCVect. cache not working?")
+       }
+
+       tmpGVect := Metric.RegisterGaugeVec(CounterOpts{Name: "gauge1", Help: "gauge1"}, []string{"name", "event"}, "SUBSYSTEM0")
+
+       if tmpGVect.Vec != mGVect.Vec {
+               t.Errorf("tmpGVect not same than mGVect. cache not working?")
+       }
+
+       Metric.RegisterCounterVec(CounterOpts{Name: "counter1", Help: "counter1"}, []string{"name", "eventMismatch"}, "SUBSYSTEM0")
+       Metric.RegisterGaugeVec(CounterOpts{Name: "gauge1", Help: "gauge1"}, []string{"name", "eventMismatch"}, "SUBSYSTEM0")
+
+}
+
 func TestMetricCounterVector(t *testing.T) {
        //
        //
@@ -320,14 +597,14 @@ func TestMetricGaugeGroupVectorPrefix(t *testing.T) {
        m_grp.GSet("event2_gauge1", 1)
 }
 
-func TestMetricGroupCache(t *testing.T) {
+func TestMetricGroupCacheWithVect(t *testing.T) {
        //
        //
-       c_grp1 := Metric.GetCounterGroupFromVectsWithPrefix("event1_", []string{"name1", "event1"}, mCGroupVect)
-       if _, ok := c_grp1["event1_counter1"]; ok == false {
-               t.Errorf("c_grp1 event1_counter1 not exists")
+       c_grp1 := Metric.GetCounterGroupFromVects([]string{"name1", "event1"}, mCGroupVect)
+       if _, ok := c_grp1["counter1"]; ok == false {
+               t.Errorf("c_grp1 counter1 not exists")
        }
-       c_grp1["event1_counter1"].Inc()
+       c_grp1["counter1"].Inc()
 
        //
        //
@@ -339,11 +616,11 @@ func TestMetricGroupCache(t *testing.T) {
 
        //
        //
-       g_grp1 := Metric.GetGaugeGroupFromVectsWithPrefix("event1_", []string{"name1", "event1"}, mGGroupVect)
-       if _, ok := g_grp1["event1_gauge1"]; ok == false {
-               t.Errorf("g_grp1 event1_gauge1 not exists")
+       g_grp1 := Metric.GetGaugeGroupFromVects([]string{"name1", "event1"}, mGGroupVect)
+       if _, ok := g_grp1["gauge1"]; ok == false {
+               t.Errorf("g_grp1 gauge1 not exists")
        }
-       g_grp1["event1_gauge1"].Inc()
+       g_grp1["gauge1"].Inc()
 
        //
        //
@@ -356,9 +633,9 @@ func TestMetricGroupCache(t *testing.T) {
        //
        //
        m_grp := NewMetricGroupsCache()
-       m_grp.CombineCounterGroups(c_grp1)
+       m_grp.CombineCounterGroupsWithPrefix("event1_", c_grp1)
        m_grp.CombineCounterGroupsWithPrefix("event2_", c_grp2)
-       m_grp.CombineGaugeGroups(g_grp1)
+       m_grp.CombineGaugeGroupsWithPrefix("event1_", g_grp1)
        m_grp.CombineGaugeGroupsWithPrefix("event2_", g_grp2)
 
        if m_grp == nil {