Issue Diagnosis
After analyzing the logs from the currencyservice pod and examining the source code in src/currencyservice/server.js, I've identified a potential issue with the currency conversion logic.
Problem Description
The currency service contains logic that checks for zero-amount conversions and attempts to "switch back" to the original currency when this occurs. However, this approach has several problems:
- Silent Failure: The logs show only successful conversion messages, but the code contains error handling for zero-amount conversions that may be triggering silently
- Circular Logic: When a conversion results in zero, the service switches back to the original currency, which defeats the purpose of currency conversion
- Lack of Error Visibility: The error condition is logged but may not be properly surfacing to calling services
Code Analysis
In the convert function (lines ~168-195), there's logic that:
- Checks if conversion result is zero:
if (result.units === 0 && result.nanos === 0)
- Logs an error and sends a Slack notification
- Reverts to the original currency instead of failing the request
Recommended Fix
- Remove the automatic fallback logic: Instead of silently switching back to the original currency, the service should return an error when conversion results in zero
- Improve error handling: Return a proper gRPC error with details about why the conversion failed
- Add proper validation: Validate input currencies and amounts before attempting conversion
Proposed Code Changes:
// Replace the current zero-check logic with proper error handling
if (result.units === 0 && result.nanos === 0) {
const errorMsg = `Currency conversion from ${request.from.currency_code} to ${request.to_code} resulted in zero amount`;
logger.error(errorMsg);
notifySlack();
// Return proper gRPC error instead of silently switching back
const error = new Error(errorMsg);
error.code = grpc.status.INVALID_ARGUMENT;
callback(error);
return;
}
Impact
This fix will:
- Provide clear error messages when conversions fail
- Prevent silent failures that could lead to incorrect pricing
- Improve debugging and monitoring capabilities
- Maintain data integrity by not silently changing currencies
Testing Recommendations
- Test with very small amounts that might round to zero
- Test with unsupported currency codes
- Verify error propagation to calling services
- Test the Slack notification functionality
Issue Diagnosis
After analyzing the logs from the currencyservice pod and examining the source code in
src/currencyservice/server.js, I've identified a potential issue with the currency conversion logic.Problem Description
The currency service contains logic that checks for zero-amount conversions and attempts to "switch back" to the original currency when this occurs. However, this approach has several problems:
Code Analysis
In the
convertfunction (lines ~168-195), there's logic that:if (result.units === 0 && result.nanos === 0)Recommended Fix
Proposed Code Changes:
Impact
This fix will:
Testing Recommendations