44 Commits

Author SHA1 Message Date
lukaszraczylo 3aa83d4480 chore(security,refactor): extract sanitization and improve code quality (#41)
* chore(security,refactor): extract sanitization and improve code quality

- [x] Extract sanitization functions to dedicated sanitization.go module
- [x] Add comprehensive golangci-lint v2 configuration with security rules
- [x] Replace interface{} with any type throughout codebase
- [x] Add admin API authentication security warning
- [x] Extract WebSocket and stats streaming constants
- [x] Add best-effort error handling comments for resource cleanup
- [x] Expand sensitive field patterns for improved PII redaction
- [x] Simplify safety checks and remove redundant nil validations
- [x] Improve test coverage for password field redaction patterns

* refactor: replace interface{} with any type alias

- [x] Replace all `map[string]interface{}` with `map[string]any`
- [x] Replace all `interface{}` with `any` in function signatures and type definitions
- [x] Update sync.Pool New function returns from `interface{}` to `any`
- [x] Add package documentation comments to 8 package files
- [x] Update type assertions and casts to work with `any` type
2026-01-17 00:04:12 +00:00
lukaszraczylo 39dc7b49cf Improve caching by adding user ids and roles to hash. 2025-11-22 17:02:16 +00:00
lukaszraczylo 94c097bc6c fixup! Race condition in parseGraphQLQuery result pooling 2025-11-18 17:27:55 +00:00
lukaszraczylo cedee416a8 improvements mid may 2025 (#24)
* General improvements and bug fixes.

* Improve tests coverage.

* fixup! Improve tests coverage.

* Update README.md with latest changes.

* Fix the uint32

* Resolve issue with race condition for logging.

* fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025

* Fix the test of the rate limiter

* Add default ratelimit.json file

* Update dependencies.

* Significant refactor.

* fixup! Significant refactor.

* fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025

* fixup! fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025

* fixup! fixup! fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025

* fixup! fixup! fixup! fixup! fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025

* fixup! fixup! fixup! fixup! fixup! fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025

* fixup! fixup! fixup! fixup! fixup! fixup! fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025

* fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025

* fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025

* fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! fixup! Merge remote-tracking branch 'origin/main' into improvements-mid-apr-2025
2025-09-30 18:27:33 +01:00
lukaszraczylo 1b7890f322 Gofmt the codebase. 2025-02-26 00:47:41 +00:00
lukaszraczylo 2ab78d35ce Configuration Management:
Optimized the getDetailsFromEnv function to reduce redundant lookups and improve type handling
Added direct environment variable access for better performance

Memory Cache Optimization:

Implemented a size-based compression threshold (1KB) to avoid compressing small payloads
Added cache size limits (10,000 entries) to prevent memory leaks
Implemented efficient eviction strategies for the oldest entries
Added atomic counter for thread-safe cache size tracking
Improved cleanup routines with GC triggering for large caches

Proxy Implementation:

Refactored the proxy code into smaller, focused functions for better maintainability
Optimized gzip handling for better performance
Improved error handling and logging
Enhanced tracing integration

GraphQL Processing:

Optimized introspection query checking with fast-path returns
Improved object pool usage
Added detailed comments for better code understanding
Split complex functions into smaller, more focused ones
Fixed test compatibility issues with introspection checking

Request Processing:

Refactored the request processing logic into smaller, focused functions
Separated user extraction, caching, and request handling for better maintainability
Improved error handling and response generation

Tracing Enhancements:

Added better span context management
Implemented custom attributes for more detailed tracing
Added sampling configuration to reduce overhead
Improved resource attribution with host and process information
Added timeout handling for tracing operations

Application Lifecycle:

Implemented graceful shutdown with proper signal handling
Added goroutine management with wait groups
Improved startup sequence with better error handling
Added timeout handling for shutdown operations
2025-02-25 23:34:39 +00:00
lukaszraczylo 6af5aefe54 Add tracing and relevant tests (#21)
* Add tracing and relevant tests.

* fixup! Add tracing and relevant tests.

* gofmt the code 🤷

* fixup! gofmt the code 🤷
2025-01-08 18:29:25 +00:00
lukaszraczylo 6b31e5c4c0 Little code cleanup. (#19) 2024-10-10 10:34:23 +01:00
lukaszraczylo 9150b25227 Fixing the proxy timeout settings which were not passed to the client and and graphql server. 2024-08-20 11:38:40 +01:00
lukaszraczylo a24e6c8c4d fixup! Fix the introduced bug where RO endpoint could've been accidentally used. (#17) 2024-06-29 08:52:41 +01:00
lukaszraczylo b10a28bf52 General code optimisations. (#16)
* General code optimisations.
2024-06-28 12:31:01 +01:00
lukaszraczylo 61d7a45d00 Update cache library, use miniredis for testing, add additional benchmarks. (#14)
Update cache library,
Update logging library,
use miniredis for testing, add additional benchmarks.
2024-06-19 23:10:36 +01:00
lukaszraczylo 12e0294945 Add distibuted cache with Redis 2024-06-11 11:35:50 +01:00
lukaszraczylo a01a4da9b5 Add metrics for cached queries + cache hit/miss 2024-06-11 11:35:49 +01:00
lukaszraczylo 371d51f96f Update dependencies. 2024-06-11 11:35:49 +01:00
lukaszraczylo 5a01ec3876 Improve logging and cache sub-packages to decrease the number of allocations
and improve performance.
2024-05-14 09:21:16 +01:00
lukaszraczylo e495cf23d9 Read only endpoint support (#10)
* This change introduces ability to set additional endpoint leading to the
instance of the graphql server connected to the read only database.
If regular query is detected and endpoint for `HOST_GRAPHQL_READONLY` value is set,
the query will be proxied to it. Mutations and non-graphql will be sent
to the `HOST_GRAPHQL` endpoint.
2024-03-12 11:16:35 +00:00
lukaszraczylo 3a18e0e935 Improve stats gathering and tests improvements. (#8) 2024-03-05 22:40:06 +00:00
lukaszraczylo ebbb1c53f5 Micro fixes. 2024-02-15 10:21:51 +00:00
lukaszraczylo 0bdea741bf Move results to the struct for ease of management. 2024-02-15 09:50:51 +00:00
lukaszraczylo 4cb0d22874 Return 403 on blocked queries. 2024-02-15 09:34:57 +00:00
lukaszraczylo bb28f2fcd8 Change the json library to the fully compatible ( and fast ) one. 2024-02-05 15:30:59 +00:00
lukaszraczylo b19b17b7c4 Realign the structs to decrease memory footprint.
Add the timeout settings to address the connection drops.
2023-12-14 17:16:38 +00:00
lukaszraczylo d09940ebc4 Update connection settings. 2023-12-13 22:50:41 +00:00
lukaszraczylo bc305dd8e9 Improve tests and speed things up a little. 2023-11-20 11:38:02 +00:00
lukaszraczylo 9c9fa94140 Add ability to set cache via query header. 2023-11-14 09:52:51 +00:00
lukaszraczylo b497ad1d1c Add generation of query uuid logs and easier debugging. 2023-10-25 14:11:44 +01:00
lukaszraczylo 35e6069f5e Add the healtcheck checks on the end server. 2023-10-19 15:43:49 +01:00
lukaszraczylo 92359c1114 Cleanup pt 1 (#4)
* Disable startup headers.

* Add banning / unbanning of specific user.
2023-10-19 14:36:16 +01:00
lukaszraczylo 57cf36ba02 Add /livez endpoint. 2023-10-16 09:09:46 +01:00
lukaszraczylo bf18f36e45 If proxying of the query fails - return 500. 2023-10-13 14:48:53 +01:00
lukaszraczylo 815a6841ed Add ability to set up allowed paths for proxying. 2023-10-12 14:12:03 +01:00
lukaszraczylo f41b2ae46f New: Proxy all the requests to the graphql server 2023-10-11 11:26:55 +01:00
lukaszraczylo 1a3628837f Extract helper libraries from private repo of telegram-bot.app 2023-10-10 22:16:50 +01:00
lukaszraczylo 0758cd5b52 fixup! Add ability to look for the role in header. 2023-10-10 19:49:43 +01:00
lukaszraczylo 51dfc8d9be Add ability to look for the role in header. 2023-10-10 19:48:56 +01:00
lukaszraczylo 917ee1a431 Add cache ttl support (#3)
* Add ability to use `@cached(ttl: 120)`

* Update documentation.
2023-10-10 19:21:25 +01:00
lukaszraczylo bc128493b0 Add tests (#2)
* Initial tests draft.

* Add tests for parsing jwt token

* Further code optimisations
2023-10-10 13:54:03 +01:00
lukaszraczylo ac44056a00 Add role ratelimit (#1)
* Add ratelimit configuration.
* Add rate limiting :party:
2023-10-09 17:46:50 +01:00
lukaszraczylo 743eed7f71 Add ability to enable / disable access log.
In high frequency environments it can be a little bit noisy.
2023-10-09 17:46:50 +01:00
lukaszraczylo 3ac7c115aa Blocking introspection queries. 2023-10-08 18:07:24 +01:00
lukaszraczylo 3b8df8ee76 Temporary fix to disable healthcheck. 2023-10-07 14:44:49 +01:00
lukaszraczylo 8673f1caf8 Remove println and replace it with our logging 2023-10-07 14:13:29 +01:00
lukaszraczylo 39d3afdd05 Initial commit. 2023-10-07 11:14:20 +01:00