feat: add internal telemetry #10

Open
t.behrendt wants to merge 2 commits from feat-add-internal-telemetry into main
Showing only changes of commit 00944d01ad - Show all commits

View File

@@ -90,19 +90,7 @@ func (m *TTLMap) Add(key string) {
* Removes the trace id from the map if it has expired. * Removes the trace id from the map if it has expired.
*/ */
func (m *TTLMap) Exists(key string) bool { func (m *TTLMap) Exists(key string) bool {
m.mu.RLock() _, ok := m.Get(key)
value, ok := m.m[key]
m.mu.RUnlock()
if ok {
if value < time.Now().Unix() {
m.mu.Lock()
delete(m.m, key)
m.mu.Unlock()
return false
}
}
return ok return ok
} }
@@ -116,6 +104,26 @@ func (m *TTLMap) insertEntry(key string, value int64) {
m.mu.Unlock() m.mu.Unlock()
} }
/**
* Gets an entry from the map.
*/
func (m *TTLMap) Get(key string) (int64, bool) {
m.mu.RLock()
value, ok := m.m[key]
m.mu.RUnlock()
if ok {
if value < time.Now().Unix() {
m.mu.Lock()
delete(m.m, key)
m.mu.Unlock()
return 0, false
}
}
return value, ok
}
/** /**
* Gets an entry from the map. * Gets an entry from the map.
* Only used for testing. * Only used for testing.
@@ -124,7 +132,6 @@ func (m *TTLMap) getEntry(key string) (int64, bool) {
m.mu.RLock() m.mu.RLock()
value, ok := m.m[key] value, ok := m.m[key]
m.mu.RUnlock() m.mu.RUnlock()
return value, ok return value, ok
} }