Realign the structs to decrease memory footprint.

Add the timeout settings to address the connection drops.
This commit is contained in:
2023-12-14 17:16:38 +00:00
parent cd9c650226
commit b19b17b7c4
6 changed files with 40 additions and 48 deletions
+3 -3
View File
@@ -9,15 +9,15 @@ import (
) )
type CacheEntry struct { type CacheEntry struct {
Value []byte
ExpiresAt time.Time ExpiresAt time.Time
Value []byte
} }
type Cache struct { type Cache struct {
sync.RWMutex bytePool sync.Pool
entries sync.Map entries sync.Map
globalTTL time.Duration globalTTL time.Duration
bytePool sync.Pool sync.RWMutex
} }
func New(globalTTL time.Duration) *Cache { func New(globalTTL time.Duration) *Cache {
+5 -5
View File
@@ -11,18 +11,18 @@ import (
func (suite *Tests) Test_parseGraphQLQuery() { func (suite *Tests) Test_parseGraphQLQuery() {
type results struct { type results struct {
is_cached bool
cached_ttl int
should_block bool
should_ignore bool
op_name string op_name string
op_type string op_type string
cached_ttl int
returnCode int returnCode int
is_cached bool
should_block bool
should_ignore bool
} }
type queries struct { type queries struct {
body string
headers map[string]string headers map[string]string
body string
} }
tests := []struct { tests := []struct {
+1 -1
View File
@@ -15,9 +15,9 @@ import (
) )
type MetricsSetup struct { type MetricsSetup struct {
metrics_prefix string
metrics_set *metrics.Set metrics_set *metrics.Set
metrics_set_custom *metrics.Set metrics_set_custom *metrics.Set
metrics_prefix string
} }
var ( var (
+2 -2
View File
@@ -8,9 +8,9 @@ import (
) )
type RateLimitConfig struct { type RateLimitConfig struct {
Req int `json:"req"`
Interval string `json:"interval"`
RateCounterTicker *goratecounter.RateCounter RateCounterTicker *goratecounter.RateCounter
Interval string `json:"interval"`
Req int `json:"req"`
} }
var rateLimits map[string]RateLimitConfig var rateLimits map[string]RateLimitConfig
+4 -4
View File
@@ -21,9 +21,9 @@ func StartHTTPProxy() {
server := fiber.New(fiber.Config{ server := fiber.New(fiber.Config{
DisableStartupMessage: true, DisableStartupMessage: true,
AppName: fmt.Sprintf("GraphQL Monitoring Proxy - %s v%s", libpack_config.PKG_NAME, libpack_config.PKG_VERSION), AppName: fmt.Sprintf("GraphQL Monitoring Proxy - %s v%s", libpack_config.PKG_NAME, libpack_config.PKG_VERSION),
IdleTimeout: time.Second * 60, IdleTimeout: time.Duration(cfg.Client.ClientTimeout) * time.Second * 2,
ReadTimeout: time.Second * 60, ReadTimeout: time.Duration(cfg.Client.ClientTimeout) * time.Second * 2,
WriteTimeout: time.Second * 60, WriteTimeout: time.Duration(cfg.Client.ClientTimeout) * time.Second * 2,
}) })
server.Use(cors.New(cors.Config{ server.Use(cors.New(cors.Config{
@@ -154,7 +154,7 @@ func processGraphQLRequest(c *fiber.Ctx) error {
timeTaken := time.Since(startTime) timeTaken := time.Since(startTime)
// Logging & Monitoring // Logging & Monitoring
go logAndMonitorRequest(c, extractedUserID, opType, opName, wasCached, timeTaken, startTime) logAndMonitorRequest(c, extractedUserID, opType, opName, wasCached, timeTaken, startTime)
return nil return nil
} }
+24 -32
View File
@@ -10,47 +10,39 @@ import (
// config is a struct that holds the configuration of the application. // config is a struct that holds the configuration of the application.
type config struct { type config struct {
Cache struct {
CacheClient *libpack_cache.Cache
CacheTTL int
CacheEnable bool
}
Logger *libpack_logging.LogConfig Logger *libpack_logging.LogConfig
Monitoring *libpack_monitoring.MetricsSetup Monitoring *libpack_monitoring.MetricsSetup
Api struct{ BannedUsersFile string }
// Server holds the configuration of the server _ONLY_.
Server struct {
PortGraphQL int
PortMonitoring int
HostGraphQL string
HealthcheckGraphQL string
AccessLog bool
ReadOnlyMode bool
AllowURLs []string
EnableApi bool
ApiPort int
PurgeOnCrawl bool
PurgeEvery int
}
Client struct { Client struct {
JWTUserClaimPath string
JWTRoleClaimPath string
RoleRateLimit bool
RoleFromHeader string
GQLClient *graphql.BaseClient GQLClient *graphql.BaseClient
FastProxyClient *fasthttp.Client FastProxyClient *fasthttp.Client
JWTUserClaimPath string
JWTRoleClaimPath string
RoleFromHeader string
proxy string proxy string
ClientTimeout int ClientTimeout int
RoleRateLimit bool
} }
Cache struct {
CacheEnable bool
CacheTTL int
CacheClient *libpack_cache.Cache
}
Api struct {
BannedUsersFile string
}
Security struct { Security struct {
BlockIntrospection bool
IntrospectionAllowed []string IntrospectionAllowed []string
BlockIntrospection bool
}
Server struct {
HostGraphQL string
HealthcheckGraphQL string
AllowURLs []string
PortGraphQL int
PortMonitoring int
ApiPort int
PurgeEvery int
AccessLog bool
ReadOnlyMode bool
EnableApi bool
PurgeOnCrawl bool
} }
} }