Add prometheus metrics to backend#28
Conversation
| @@ -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'] | |||
There was a problem hiding this comment.
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.
| @@ -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'] | |||
There was a problem hiding this comment.
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.
| @@ -146,7 +168,11 @@ def update_snack(sku: str, updates: SnackUpdateSchema) -> Snack: | |||
| sku | |||
There was a problem hiding this comment.
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.
Add Prometheus metrics to backend