Skip to content

Add prometheus metrics to backend#28

Open
adarshm11 wants to merge 4 commits into
devfrom
Adarsh/07112025_add_prometheus
Open

Add prometheus metrics to backend#28
adarshm11 wants to merge 4 commits into
devfrom
Adarsh/07112025_add_prometheus

Conversation

@adarshm11

Copy link
Copy Markdown

Add Prometheus metrics to backend

@adarshm11 adarshm11 changed the title Adarsh/07112025 add prometheus Add prometheus metrics to backend Jul 13, 2025
@vineeshah vineeshah closed this Apr 8, 2026
@vineeshah vineeshah reopened this Apr 8, 2026
Comment thread backend/utils/db.py
@@ -124,6 +143,9 @@ def update_snack(sku: str, updates: SnackUpdateSchema) -> Snack:
description = updates.description if updates.description is not None else current_snack['description']
category = updates.category if updates.category is not None else current_snack['category']

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calculation of quantity_change as current_snack['quantity'] - quantity can be negative if quantity is greater than current_snack['quantity'], which may lead to incorrect logic downstream. This needs validation or adjustment to handle such cases properly.

Comment thread backend/utils/db.py
@@ -124,6 +143,9 @@ def update_snack(sku: str, updates: SnackUpdateSchema) -> Snack:
description = updates.description if updates.description is not None else current_snack['description']

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic assumes that a decrease in quantity means a purchase was made, but this may not always be true (e.g., returns, adjustments). Consider revising the logic to accurately reflect purchase events.

Comment thread backend/utils/db.py
@@ -146,7 +168,11 @@ def update_snack(sku: str, updates: SnackUpdateSchema) -> Snack:
sku

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In update_snack, purchase_count.labels(sku).inc(quantity_change) is called without checking if quantity_change is positive. Incrementing with negative or zero values can cause incorrect metric reporting. Add validation to ensure only positive increments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants