Add comments about thread-safety

Signed-off-by: glightfoot <glightfoot@rsglab.com>
This commit is contained in:
glightfoot 2021-02-19 14:13:03 -05:00
parent 8b306c8c76
commit a197834f64
2 changed files with 3 additions and 1 deletions

View file

@ -263,6 +263,8 @@ func (m *MetricMapper) InitFromFile(fileName string) error {
return m.InitFromYAMLString(string(mappingStr)) return m.InitFromYAMLString(string(mappingStr))
} }
// UseCache tells the mapper to use a cache that implements the MetricMapperCache interface.
// This cache MUST be thread-safe!
func (m *MetricMapper) UseCache(cache MetricMapperCache) { func (m *MetricMapper) UseCache(cache MetricMapperCache) {
m.mutex.Lock() m.mutex.Lock()
defer m.mutex.Unlock() defer m.mutex.Unlock()

View file

@ -59,7 +59,7 @@ type MetricMapperCacheResult struct {
Labels prometheus.Labels Labels prometheus.Labels
} }
// MetricMapperCache must be thread-safe and should be instrumented with CacheMetrics // MetricMapperCache MUST be thread-safe and should be instrumented with CacheMetrics
type MetricMapperCache interface { type MetricMapperCache interface {
// Get a cached result // Get a cached result
Get(metricKey string) (interface{}, bool) Get(metricKey string) (interface{}, bool)