From a197834f64385ea836cbac56761913b01da72f6c Mon Sep 17 00:00:00 2001 From: glightfoot Date: Fri, 19 Feb 2021 14:13:03 -0500 Subject: [PATCH] Add comments about thread-safety Signed-off-by: glightfoot --- pkg/mapper/mapper.go | 2 ++ pkg/mapper/mapper_cache.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/mapper/mapper.go b/pkg/mapper/mapper.go index e610e1a..33ea5c3 100644 --- a/pkg/mapper/mapper.go +++ b/pkg/mapper/mapper.go @@ -263,6 +263,8 @@ func (m *MetricMapper) InitFromFile(fileName string) error { 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) { m.mutex.Lock() defer m.mutex.Unlock() diff --git a/pkg/mapper/mapper_cache.go b/pkg/mapper/mapper_cache.go index 2c37fa3..9d65f8c 100644 --- a/pkg/mapper/mapper_cache.go +++ b/pkg/mapper/mapper_cache.go @@ -59,7 +59,7 @@ type MetricMapperCacheResult struct { 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 { // Get a cached result Get(metricKey string) (interface{}, bool)