PCA (Prometheus Certified Associate) sample exam question with answer 516

Question:
Which of the following is the correct way to increment a Counter metric in Prometheus with Python?

  1. my_counter += 1
  2. my_counter.inc()
  3. my_counter.increment()
  4. my_counter.set(my_counter.get() + 1)
Answer:
B - is the correct answer
A - is incorrect as it uses the += operator, which is not supported by the Counter object
C - is incorrect as the increment() method is not defined for the Counter object
D - is incorrect as it uses the .set() method to manually set the value of the metric, which is not the correct way to increment a counter