You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`--out`|`.`| Output directory for snapshot JSON files |
58
64
|`--region`|`us-west-2`| AWS region |
59
65
|`--profile`|| AWS CLI profile name |
66
+
|`--overwrite`|`false`| Replace an existing snapshot file with the same function and label |
60
67
61
68
Log groups are derived as `/aws/lambda/<function-name>`.
62
69
63
70
Duplicate function names are rejected so one capture run cannot silently rescan the same Lambda and overwrite the same snapshot path.
64
71
65
-
Output files are named from sanitized `<function-name>_<label>.json` components in the output directory. Path separators and traversal-style input such as `..` are rewritten so snapshot writes stay inside the chosen output directory. Each function gets its own snapshot file, and the output directory is created automatically when a snapshot is written.
72
+
Output files are named from sanitized `<function-name>_<label>.json` components in the output directory. Path separators and traversal-style input such as `..` are rewritten so snapshot writes stay inside the chosen output directory. Each function gets its own snapshot file, and the output directory is created automatically when a snapshot is written. Existing snapshot files are not replaced unless `--overwrite` is set.
66
73
67
74
The `--offset` flag lets you look further back in time. For example, `--offset 100 --count 20` skips the 100 most recent invocations and captures the 20 after that. This is useful for grabbing a historical baseline to compare against.
|`--b`|| Path to new snapshot JSON file (required) |
83
90
|`--strict`|`false`| Fail if either snapshot is missing `function_name` / `log_group`, or if those fields disagree |
84
91
|`--fail-on-regression`|`false`| Exit non-zero if the new snapshot has more errors or new error patterns |
92
+
|`--max-duration-regression-pct`|`0`| Exit non-zero if new p90 duration exceeds baseline p90 by more than this percentage. `0` disables this gate. |
93
+
|`--max-memory-regression-pct`|`0`| Exit non-zero if new max peak memory exceeds baseline max peak memory by more than this percentage. `0` disables this gate. |
94
+
|`--json`|`false`| Print a machine-readable JSON comparison summary instead of the human report |
85
95
86
96
The comparison includes:
87
97
88
98
-**Error count** — warns if errors increased
89
99
-**Error patterns** — new patterns that appeared, old patterns that disappeared
90
-
-**Regression gate** — `--fail-on-regression` returns a non-zero exit after printing the report if errors increased or new error patterns appeared
100
+
-**Regression gates** — `--fail-on-regression` returns a non-zero exit after printing the report if errors increased or new error patterns appeared; the duration and memory threshold flags also return non-zero when their configured gates are exceeded
91
101
-**Duration stats** — min, avg, p50, p90, max (in milliseconds), ignoring malformed values with an explicit ignored count
92
102
-**Memory usage** — min, avg, max peak memory (in MB), ignoring malformed values with an explicit ignored count
93
-
-**Log pattern diff** — new and gone log line patterns (UUIDs normalized)
103
+
-**Log pattern diff** — new and gone log line patterns, normalizing request-specific values such as UUIDs, request IDs, timestamps, ARNs, long numeric IDs, and durations
104
+
-**JSON output** — `--json` emits counts, pattern diffs, metric stats, warnings, and regression reasons for CI consumers
94
105
-**Snapshot mismatch warnings** — warns when the two files appear to be from different Lambda functions or log groups; `--strict` also fails when snapshot identity fields are missing
95
106
107
+
### `selfupdate`
108
+
109
+
Checks the latest GitHub release, downloads the matching binary and `.sha256` checksum for the current OS/architecture, verifies the checksum, and replaces the running executable when a newer release is available.
110
+
111
+
```
112
+
lambda-deploy-log-compare selfupdate
113
+
```
114
+
115
+
### `version`
116
+
117
+
Prints the current build version and exits. Release builds can set this with `-ldflags "-X main.appVersion=v1.2.3"`.
118
+
119
+
```
120
+
lambda-deploy-log-compare version
121
+
```
122
+
96
123
## Snapshot Format
97
124
98
125
Each snapshot file contains one `Snapshot` object with metadata plus an `invocations` array.
@@ -104,6 +131,7 @@ Important field notes:
104
131
-`max_memory_used_mb` stores Lambda `Max Memory Used`, which is the value used for memory comparison stats and `peak_mem` in compare output.
105
132
- Invocations that never emit a `REPORT` line are still captured, with blank duration and memory fields, so crashes and truncated runs are not silently dropped.
106
133
- Older snapshots that used `mem_used_mb` and `max_mem_mb` still load correctly.
134
+
- Compare rejects files that have neither snapshot metadata nor invocation records, so unrelated JSON is not treated as an empty snapshot.
107
135
108
136
## AWS Authentication
109
137
@@ -117,10 +145,10 @@ The IAM principal needs these permissions:
117
145
## How It Works
118
146
119
147
1.**Stream discovery** — Fetches recent log streams ordered by last event time (most recent first) page by page until the requested `offset + count` is satisfied or the log group is exhausted.
120
-
2.**Invocation parsing** — Reads each stream from newest events backward, tracks invocations from Lambda `START` and `REPORT` markers, and uses inline `RequestId` hints plus current stream context to associate log lines that land outside the normal `START -> logs -> REPORT` sequence. Extracts duration, billed duration, memory size, and max memory used from `REPORT` lines when present, while still preserving recent invocations that crashed or were truncated before `REPORT`. Each stream gets a 30-second timeout, and collection stops early once enough invocations are found.
148
+
2.**Invocation parsing** — Reads each stream from newest events backward, tracks invocations from Lambda `START` and `REPORT` markers, and uses inline `RequestId` hints plus current stream context to associate log lines that land outside the normal `START -> logs -> REPORT` sequence. Extracts duration, billed duration, memory size, and max memory used from `REPORT` lines when present, while still preserving recent invocations that crashed or were truncated before `REPORT`. Each stream gets a 30-second timeout, collection stops early once enough newest invocations have their `START` boundary in the collected pages, and pages fetched before a later stream read failure are still used with a warning.
121
149
3.**Error detection** — Flags explicit error-style log lines such as `error`, `panic`, `fatal`, `traceback`, `exception`, and Lambda runtime failure messages, while skipping common benign counter-style phrases like `error_count=0`.
122
150
4.**Snapshot selection** — From all discovered invocations (sorted by time, most recent first), skips the first `offset` invocations, then takes the next `count`.
123
-
5.**Pattern normalization** — For comparison, log lines are normalized by collapsing UUID-like hex strings (32+ chars) to `<UUID>`and truncating to 100 characters. This lets you compare structural patterns rather than exact values.
151
+
5.**Pattern normalization** — For comparison, log lines are normalized by collapsing request-specific values such as UUID-like hex strings (32+ chars), Lambda request IDs, timestamps, ARNs, long numeric IDs, and durations before truncating to 100 characters. This lets you compare structural patterns rather than exact values.
fmt.Fprintf(stderr, " Warning: failed to get events from stream %s: %v\n", *stream.LogStreamName, err)
78
-
continue
86
+
iflen(events) ==0 {
87
+
fmt.Fprintf(stderr, " Warning: failed to get events from stream %s: %v\n", *stream.LogStreamName, err)
88
+
continue
89
+
}
90
+
fmt.Fprintf(stderr, " Warning: failed to get complete events from stream %s: %v; using %d event(s) fetched before the failure\n", *stream.LogStreamName, err, len(events))
0 commit comments