Commit 0611dcb
authored
Improvements (#87)
* Fix return -> continue in UpdateCache to prevent goroutine death
The UpdateCache goroutine used `return` instead of `continue` on
error paths (empty database, query parse failure, table extraction
failure). A single transient error would permanently kill the
goroutine, stopping all server-response caching for the plugin's
lifetime. Resolves #64.
* Fix IsCacheNeeded to check parsed query instead of cache key
IsCacheNeeded was called with the full cache key (server:db:request_bytes)
instead of the actual SQL query string. Date/time function detection
against raw binary bytes was unreliable. Now the query is parsed first
via GetQueryFromRequest and uppercased before checking.
* Fix ExitOnStartupError ordering and close(nil) panic in main.go
Move config field assignments (including ExitOnStartupError) before
the API client initialization block so the flag is set when first
checked. Also guard the deferred channel close to prevent a panic
when config is nil and the channel was never initialized.
* Add CacheErrorsCounter, fix double-counting misses, and fix typos
Introduce a dedicated CacheErrorsCounter to separate Redis operation
failures from genuine cache misses. Previously CacheMissesCounter was
incremented for SET/DEL/SCAN errors, making the metric unreliable.
Also fix double-counting in OnTrafficFromClient where a single miss
incremented CacheMissesCounter twice. Fix typos: cachedRespnseKey ->
cachedResponseKey, DateFucntion -> DateFunction.
* Extract duplicated startup error handling into helper function
Replace three copies of the ExitOnStartupError check + manual close +
os.Exit(1) pattern with a single handleStartupError helper that
accepts variadic io.Closer resources. Reduces boilerplate and
ensures consistent behavior across all startup error paths.
* Add explicit config validation with sensible defaults
Previously cast.To* silently returned zero-values for invalid config.
Now redisURL, expiry, and scanCount are validated with warnings and
defaults applied when values are missing or invalid.
* Add config validation and graceful goroutine shutdown via WaitGroup
Add a WaitGroup to the Plugin struct so the UpdateCache goroutine
signals completion when the channel is closed, allowing the process
to drain pending cache updates before exit. Tests updated to use
the same mechanism.
* Update gatewayd-plugin-sdk to v0.4.4, gatewayd to v0.11.0, and all direct deps
SDK v0.4.4 brings redis/go-redis/v9, go-plugin v1.7.0, pgx/v5 v5.8.0,
grpc v1.79.1, and protobuf v1.36.11. Also updates miniredis v2.36.1,
sentry v0.42.0, cast v1.10.0, testify v1.11.1, and prometheus v1.23.2
via make update-direct-deps.
* Migrate from go-redis/redis/v8 to redis/go-redis/v9
Replace deprecated github.com/go-redis/redis/v8 with the maintained
github.com/redis/go-redis/v9. Updated import paths in plugin.go,
main.go, plugin_test.go, and the depguard config in .golangci.yaml.
* Update CI actions to v4/v5, add govulncheck to test workflow
Bump actions/checkout to v4, actions/setup-go to v5 (Node 20),
and softprops/action-gh-release to v2. Add govulncheck step to the
test workflow for security scanning. setup-go v5 includes built-in
module caching.
* Add tests for IsCacheNeeded, OnClosed, invalidateDML, and goroutine resilience
- TestIsCacheNeeded: table-driven test covering all PostgreSQL date/time
functions plus positive cases (SELECT, INSERT, empty)
- TestOnClosed: verifies client-to-database key cleanup on connection close
- TestOnClosedNilClient: verifies graceful handling of nil client
- TestInvalidateDML: verifies INSERT invalidates cached SELECT responses
and their table index keys
- TestInvalidateDMLSelectIgnored: verifies SELECT queries don't trigger
invalidation
- TestUpdateCacheContinuesOnError: confirms the goroutine survives errors
and processes subsequent messages (validates the return->continue fix)
* Fix golangci-lint issues: import ordering and nestif complexity
Sort imports alphabetically to satisfy gci linter. Reduce nestif
complexity in UpdateCache by inverting the caching precondition
into an early continue.1 parent 07373a2 commit 0611dcb
9 files changed
Lines changed: 421 additions & 214 deletions
File tree
- .github/workflows
- plugin
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
19 | | - | |
| 18 | + | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
24 | | - | |
| 23 | + | |
25 | 24 | | |
26 | 25 | | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
31 | 35 | | |
32 | 36 | | |
33 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
10 | 10 | | |
11 | | - | |
12 | 11 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
18 | 18 | | |
19 | | - | |
20 | | - | |
| 19 | + | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
| 38 | + | |
40 | 39 | | |
41 | 40 | | |
42 | | - | |
| 41 | + | |
43 | 42 | | |
44 | | - | |
45 | 43 | | |
46 | | - | |
| 44 | + | |
47 | 45 | | |
48 | 46 | | |
49 | 47 | | |
50 | 48 | | |
51 | 49 | | |
| 50 | + | |
52 | 51 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
0 commit comments