mirror of
https://github.com/lukaszraczylo/graphql-monitoring-proxy.git
synced 2026-06-12 00:19:36 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
b19b17b7c4
|
|||
|
cd9c650226
|
|||
|
d09940ebc4
|
|||
|
3596b03953
|
Vendored
+3
-3
@@ -9,15 +9,15 @@ import (
|
||||
)
|
||||
|
||||
type CacheEntry struct {
|
||||
Value []byte
|
||||
ExpiresAt time.Time
|
||||
Value []byte
|
||||
}
|
||||
|
||||
type Cache struct {
|
||||
sync.RWMutex
|
||||
bytePool sync.Pool
|
||||
entries sync.Map
|
||||
globalTTL time.Duration
|
||||
bytePool sync.Pool
|
||||
sync.RWMutex
|
||||
}
|
||||
|
||||
func New(globalTTL time.Duration) *Cache {
|
||||
|
||||
@@ -13,7 +13,7 @@ require (
|
||||
github.com/json-iterator/go v1.1.12
|
||||
github.com/lukaszraczylo/ask v0.0.0-20230927103145-2ff1123b4415
|
||||
github.com/lukaszraczylo/go-ratecounter v0.1.8
|
||||
github.com/lukaszraczylo/go-simple-graphql v1.2.3
|
||||
github.com/lukaszraczylo/go-simple-graphql v1.2.7
|
||||
github.com/rs/zerolog v1.31.0
|
||||
github.com/stretchr/testify v1.8.4
|
||||
github.com/valyala/fasthttp v1.51.0
|
||||
|
||||
@@ -40,8 +40,8 @@ github.com/lukaszraczylo/ask v0.0.0-20230927103145-2ff1123b4415 h1:lvI8Wlbg4PxkR
|
||||
github.com/lukaszraczylo/ask v0.0.0-20230927103145-2ff1123b4415/go.mod h1:M+UVdyqZs++xtEPrascaVmZdOMhCnxjZ2SgH+xHpR0c=
|
||||
github.com/lukaszraczylo/go-ratecounter v0.1.8 h1:ZYm6Wkn58ZAlFWRmC7PaD4oAYHWcu8/0MUDWGe3PnJQ=
|
||||
github.com/lukaszraczylo/go-ratecounter v0.1.8/go.mod h1:TqXEOCtFJStk1i0tkipprv1kiDHGon1MVUisjSTBSKM=
|
||||
github.com/lukaszraczylo/go-simple-graphql v1.2.3 h1:OwsJsQENDmLH2Qw37nuzUSht+m5tofv5H9T6zhDbckA=
|
||||
github.com/lukaszraczylo/go-simple-graphql v1.2.3/go.mod h1:fYwnUZ1xJqvJSfbU9k8GMMI9Flan2dNXSvg/arS7rzU=
|
||||
github.com/lukaszraczylo/go-simple-graphql v1.2.7 h1:7pG3XAdaYKAmVVQCXNTmaWKr2KC7KHgTQUSIe4fl3AQ=
|
||||
github.com/lukaszraczylo/go-simple-graphql v1.2.7/go.mod h1:fYwnUZ1xJqvJSfbU9k8GMMI9Flan2dNXSvg/arS7rzU=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
|
||||
+5
-5
@@ -11,18 +11,18 @@ import (
|
||||
func (suite *Tests) Test_parseGraphQLQuery() {
|
||||
|
||||
type results struct {
|
||||
is_cached bool
|
||||
cached_ttl int
|
||||
should_block bool
|
||||
should_ignore bool
|
||||
op_name string
|
||||
op_type string
|
||||
cached_ttl int
|
||||
returnCode int
|
||||
is_cached bool
|
||||
should_block bool
|
||||
should_ignore bool
|
||||
}
|
||||
|
||||
type queries struct {
|
||||
body string
|
||||
headers map[string]string
|
||||
body string
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
|
||||
@@ -15,9 +15,9 @@ import (
|
||||
)
|
||||
|
||||
type MetricsSetup struct {
|
||||
metrics_prefix string
|
||||
metrics_set *metrics.Set
|
||||
metrics_set_custom *metrics.Set
|
||||
metrics_prefix string
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -18,9 +18,11 @@ func createFasthttpClient(timeout int) *fasthttp.Client {
|
||||
TLSConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
MaxConnsPerHost: 200,
|
||||
MaxConnsPerHost: 2048,
|
||||
ReadTimeout: time.Second * time.Duration(timeout),
|
||||
WriteTimeout: time.Second * time.Duration(timeout),
|
||||
MaxIdleConnDuration: time.Second * time.Duration(timeout),
|
||||
MaxConnDuration: time.Second * time.Duration(timeout),
|
||||
DisableHeaderNamesNormalizing: true,
|
||||
}
|
||||
}
|
||||
@@ -35,6 +37,7 @@ func proxyTheRequest(c *fiber.Ctx) error {
|
||||
c.Request().Header.DisableNormalizing()
|
||||
c.Request().Header.Add("X-Real-IP", c.IP())
|
||||
c.Request().Header.Add(fiber.HeaderXForwardedFor, string(c.Request().Header.Peek("X-Forwarded-For")))
|
||||
c.Request().Header.Del(fiber.HeaderAcceptEncoding)
|
||||
|
||||
proxy.WithClient(cfg.Client.FastProxyClient)
|
||||
|
||||
|
||||
+2
-2
@@ -8,9 +8,9 @@ import (
|
||||
)
|
||||
|
||||
type RateLimitConfig struct {
|
||||
Req int `json:"req"`
|
||||
Interval string `json:"interval"`
|
||||
RateCounterTicker *goratecounter.RateCounter
|
||||
Interval string `json:"interval"`
|
||||
Req int `json:"req"`
|
||||
}
|
||||
|
||||
var rateLimits map[string]RateLimitConfig
|
||||
|
||||
@@ -21,6 +21,9 @@ func StartHTTPProxy() {
|
||||
server := fiber.New(fiber.Config{
|
||||
DisableStartupMessage: true,
|
||||
AppName: fmt.Sprintf("GraphQL Monitoring Proxy - %s v%s", libpack_config.PKG_NAME, libpack_config.PKG_VERSION),
|
||||
IdleTimeout: time.Duration(cfg.Client.ClientTimeout) * time.Second * 2,
|
||||
ReadTimeout: time.Duration(cfg.Client.ClientTimeout) * time.Second * 2,
|
||||
WriteTimeout: time.Duration(cfg.Client.ClientTimeout) * time.Second * 2,
|
||||
})
|
||||
|
||||
server.Use(cors.New(cors.Config{
|
||||
@@ -151,7 +154,7 @@ func processGraphQLRequest(c *fiber.Ctx) error {
|
||||
timeTaken := time.Since(startTime)
|
||||
|
||||
// Logging & Monitoring
|
||||
go logAndMonitorRequest(c, extractedUserID, opType, opName, wasCached, timeTaken, startTime)
|
||||
logAndMonitorRequest(c, extractedUserID, opType, opName, wasCached, timeTaken, startTime)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
+25
-33
@@ -10,47 +10,39 @@ import (
|
||||
|
||||
// config is a struct that holds the configuration of the application.
|
||||
type config struct {
|
||||
Cache struct {
|
||||
CacheClient *libpack_cache.Cache
|
||||
CacheTTL int
|
||||
CacheEnable bool
|
||||
}
|
||||
Logger *libpack_logging.LogConfig
|
||||
Monitoring *libpack_monitoring.MetricsSetup
|
||||
|
||||
// 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 {
|
||||
JWTUserClaimPath string
|
||||
JWTRoleClaimPath string
|
||||
RoleRateLimit bool
|
||||
RoleFromHeader string
|
||||
Api struct{ BannedUsersFile string }
|
||||
Client struct {
|
||||
GQLClient *graphql.BaseClient
|
||||
FastProxyClient *fasthttp.Client
|
||||
JWTUserClaimPath string
|
||||
JWTRoleClaimPath string
|
||||
RoleFromHeader string
|
||||
proxy string
|
||||
ClientTimeout int
|
||||
RoleRateLimit bool
|
||||
}
|
||||
|
||||
Cache struct {
|
||||
CacheEnable bool
|
||||
CacheTTL int
|
||||
CacheClient *libpack_cache.Cache
|
||||
}
|
||||
|
||||
Api struct {
|
||||
BannedUsersFile string
|
||||
}
|
||||
|
||||
Security struct {
|
||||
BlockIntrospection bool
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user