func (s *Store) ClearMetrics() {
	s.insertMu.Lock()
	defer s.insertMu.Unlock()
	s.searchMu.Lock()
	defer s.searchMu.Unlock()
	s.Metrics = make(map[string][]*Metric)
}
ClearMetrics empties the store of all metrics.
package metrics
import (
	"context"
	"encoding/json"
	"io"
	"reflect"
	"sync"
	"time"
	"github.com/golang/glog"
	"github.com/pkg/errors"
)
type Store struct {
	searchMu sync.RWMutex  
	insertMu sync.Mutex    
	Metrics  map[string][]*Metric
}
func NewStore() (s *Store) {
	s = &Store{}
	s.ClearMetrics()
	return
}
func (s *Store) Add(m *Metric) error {
	s.insertMu.Lock()
	defer s.insertMu.Unlock()
	s.searchMu.RLock()
	glog.V(1).Infof("Adding a new metric %v", m)
	dupeIndex := -1
	if len(s.Metrics[m.Name]) > 0 {
		t := s.Metrics[m.Name][0].Kind
		if m.Kind != t {
			s.searchMu.RUnlock()
			return errors.Errorf("Metric %s has different kind %v to existing %v.", m.Name, m.Kind, t)
		}
		for i, v := range s.Metrics[m.Name] {
			if v.Program != m.Program {
				continue
			}
			if v.Type != m.Type {
				continue
			}
			if v.Source != m.Source {
				continue
			}
			dupeIndex = i
			glog.V(2).Infof("v keys: %v m.keys: %v", v.Keys, m.Keys)
			if len(v.Keys) != len(m.Keys) || !reflect.DeepEqual(v.Keys, m.Keys) {
				break
			}
			glog.V(2).Infof("v buckets: %v m.buckets: %v", v.Buckets, m.Buckets)
			glog.V(2).Infof("Found duped metric: %d", dupeIndex)
			for j, oldLabel := range v.LabelValues {
				glog.V(2).Infof("Labels: %d %s", j, oldLabel.Labels)
				d, err := v.GetDatum(oldLabel.Labels...)
				if err != nil {
					return err
				}
				if err = m.RemoveDatum(oldLabel.Labels...); err != nil {
					return err
				}
				lv := &LabelValue{Labels: oldLabel.Labels, Value: d}
				if err := m.AppendLabelValue(lv); err != nil {
					return err
				}
			}
		}
	}
	s.searchMu.RUnlock()
	s.searchMu.Lock()
	s.Metrics[m.Name] = append(s.Metrics[m.Name], m)
	if dupeIndex >= 0 {
		glog.V(2).Infof("removing original, keeping its clone")
		s.Metrics[m.Name] = append(s.Metrics[m.Name][0:dupeIndex], s.Metrics[m.Name][dupeIndex+1:]...)
	}
	s.searchMu.Unlock()
	return nil
}
func (s *Store) FindMetricOrNil(name, prog string) *Metric {
	s.searchMu.RLock()
	defer s.searchMu.RUnlock()
	ml, ok := s.Metrics[name]
	if !ok {
		return nil
	}
	for _, m := range ml {
		if m.Program != prog {
			continue
		}
		return m
	}
	return nil
}