- c = make(map[string]Counter)
- for _, opt := range opts {
- opt.Namespace = m.Namespace
- opt.Subsystem = subsytem
-
- id := m.getFullName(prometheus.Opts(opt), []string{})
- if _, ok := cache_allcounters[id]; !ok {
- cache_allcounters[id] = m.registerCounter(opt)
- }
+ opts.Namespace = m.Namespace
+ opts.Subsystem = subsytem
+ vecid := m.getFullName(prometheus.Opts(opts), []string{})
+ if _, ok := cache_allcounters[vecid]; ok {
+ Logger.Warn("Register new counter vector with opts: %v labelNames: %v, name conflicts existing counter", opts, labelNames)
+ return nil
+ }
+ if _, ok := cache_allcountervects[vecid]; !ok {
+ Logger.Debug("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)
+ return nil
+ }
+ valid := m.getFullName(prometheus.Opts(entry.Opts), labelValues)
+ if _, ok := cache_allcounters[valid]; !ok {
+ Logger.Debug("Register new counter from vector with opts: %v labelValues: %v", entry.Opts, labelValues)
+ cache_allcounters[valid] = entry.Vec.WithLabelValues(labelValues...)
+ }
+ return cache_allcounters[valid]
+}