Open
Description
I find metrics in my celery task will lead to memory leak. And I reproduced this problem issue locally.
import tracemalloc
from prometheus_client import Counter
counter_a = Counter('request_count_a', 'request count to a', ['name'])
counter_b = Counter('request_count_b', 'request count to b')
tracemalloc.start()
for _ in range(10):
counter_a.labels('a').inc()
curr_mem, peak_mem = tracemalloc.get_traced_memory()
print(f"curr mem: {curr_mem / 10**3} Kb, peak mem: {peak_mem / 10**3} Kb")
print("*****************************************")
for _ in range(10):
counter_b.inc()
curr_mem, peak_mem = tracemalloc.get_traced_memory()
print(f"curr mem: {curr_mem / 10 ** 3} Kb, peak mem: {peak_mem / 10 ** 3} Kb")
It seems to be caused by the labels
method. PS: prometheus-client==0.17.1