alexcasalboni / alexcasalboni/aws-lambda-power-tuning
Invalid JSON log does not contain initDurationMs/restoreDurationMs
- Ngôn ngữ chính
- JavaScript
- Star
- 6.1k
- Fork
- 415
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
## Description
When a Lambda function has its log format set to **JSON** (via AWS Advanced Logging Controls), the `executor` Lambda fails with:
```
Error: Invalid JSON log does not contain initDurationMs
```
or
```
Error: Invalid JSON log does not contain restoreDurationMs
```
or
```
Error: Invalid JSON log does not contain billedRestoreDurationMs
```
## Root Cause
After a quickly investigation the problem, apparently, is in `lambda/utils.js`, the function `extractDurationFromJSON` performs a strict string check:
```javascript
if (!log.includes(durationType)) {
throw new Error(`Invalid JSON log does not contain ${durationType}`);
}
```
This throws an exception when `initDurationMs` (or `restoreDurationMs` or `billedRestoreDurationMs`) is absent from the log:
- initDurationMs — absent on warm start invocations (only present on cold starts)
- restoreDurationMs — absent on non-SnapStart Lambda functions
- billedRestoreDurationMs — absent on non-SnapStart Lambda functions
By contrast, the **text** log path (`extractDurationFromText`) handles this gracefully by returning `0` when the regex doesn't match:
```javascript
if (match == null) return 0;
```
The JSON path should behave the same way — return `0` instead of throwing.
## Steps to Reproduce
1. Deploy a Lambda function with log format set to **JSON** (Monitoring and operations tools → Logging configuration → Log format → JSON)
2. Run the Power Tuning state machine targeting that function
3. The `executor` step fails on the second or subsequent invocations (warm starts) because `initDurationMs` is not present in the log
## Expected Behavior
The `extractDurationFromJSON` and `extractDurationFromText` functions should work in the same way giving the same outputs.
The tool should work and complete the happy flow without any exception.
## Workaround
Temporarily switch the Lambda's log format from JSON to Text before running the tuning, then switch it back.
## Environment
- Power Tuning version: latest (deployed via SAR on 2026-04-22)
- Region: eu-central-1 (tool) / eu-south-1 (target Lambda)
- Lambda log format: JSON (AWS Advanced Logging Controls)
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Đánh giá
Issue này chưa được đánh giá.