mirror of
https://github.com/lukaszraczylo/graphql-monitoring-proxy.git
synced 2026-10-23 06:47:26 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b1af9cafe
|
||
|
|
5f44ce797a
|
||
|
|
1b949583c7
|
@@ -4,9 +4,11 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '**.md'
|
- '**/**.md'
|
||||||
|
- '**/**.yaml'
|
||||||
|
- 'static/**'
|
||||||
branches:
|
branches:
|
||||||
- "*"
|
- 'main'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
shared:
|
shared:
|
||||||
|
|||||||
@@ -33,10 +33,16 @@ I wanted to monitor the queries and responses of our graphql endpoint, but we di
|
|||||||
* `PORT_GRAPHQL` - the port to expose the graphql endpoint on (default: 8080)
|
* `PORT_GRAPHQL` - the port to expose the graphql endpoint on (default: 8080)
|
||||||
* `HOST_GRAPHQL` - the host to proxy the graphql endpoint to (default: `http://localhost/v1/graphql`)
|
* `HOST_GRAPHQL` - the host to proxy the graphql endpoint to (default: `http://localhost/v1/graphql`)
|
||||||
* `JWT_USER_CLAIM_PATH` - the path to the user claim in the JWT token (default: ``)
|
* `JWT_USER_CLAIM_PATH` - the path to the user claim in the JWT token (default: ``)
|
||||||
* `ENABLE_CACHE` - enable the cache (default: `false`)
|
* `ENABLE_GLOBAL_CACHE` - enable the cache (default: `false`)
|
||||||
* `CACHE_TTL` - the cache TTL (default: `60s`)
|
* `CACHE_TTL` - the cache TTL (default: `60s`)
|
||||||
* `LOG_LEVEL` - the log level (default: `info`)
|
* `LOG_LEVEL` - the log level (default: `info`)
|
||||||
* `BLOCK_SCHEMA_INTROSPECTION` - blocks the schema introspection (default: `false`)
|
* `BLOCK_SCHEMA_INTROSPECTION` - blocks the schema introspection (default: `false`)
|
||||||
|
* `ENABLE_ACCESS_LOG` - enable the access log (default: `false`)
|
||||||
|
|
||||||
|
### Caching
|
||||||
|
|
||||||
|
Cache engine is enabled in background as it does not use any additional resources.
|
||||||
|
You can then start using the cache by setting the `ENABLE_GLOBAL_CACHE` environment variable to `true` - which will enable the cache for all queries, without introspection of the query. You can leave the global cache disabled and enable the cache for specific queries by adding the `@cache` directive to the query.
|
||||||
|
|
||||||
### Monitoring endpoint
|
### Monitoring endpoint
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,13 @@ func parseConfig() {
|
|||||||
c.Server.PortMonitoring = envutil.GetInt("MONITORING_PORT", 9393)
|
c.Server.PortMonitoring = envutil.GetInt("MONITORING_PORT", 9393)
|
||||||
c.Server.HostGraphQL = envutil.Getenv("HOST_GRAPHQL", "http://localhost/v1/graphql")
|
c.Server.HostGraphQL = envutil.Getenv("HOST_GRAPHQL", "http://localhost/v1/graphql")
|
||||||
c.Client.JWTUserClaimPath = envutil.Getenv("JWT_USER_CLAIM_PATH", "")
|
c.Client.JWTUserClaimPath = envutil.Getenv("JWT_USER_CLAIM_PATH", "")
|
||||||
c.Cache.CacheEnable = envutil.GetBool("CACHE_ENABLE", false)
|
c.Cache.CacheEnable = envutil.GetBool("ENABLE_GLOBAL_CACHE", false)
|
||||||
c.Cache.CacheTTL = envutil.GetInt("CACHE_TTL", 60)
|
c.Cache.CacheTTL = envutil.GetInt("CACHE_TTL", 60)
|
||||||
c.Security.BlockIntrospection = envutil.GetBool("BLOCK_SCHEMA_INTROSPECTION", false)
|
c.Security.BlockIntrospection = envutil.GetBool("BLOCK_SCHEMA_INTROSPECTION", false)
|
||||||
c.Logger = libpack_logging.NewLogger()
|
c.Logger = libpack_logging.NewLogger()
|
||||||
c.Client.GQLClient = graphql.NewConnection()
|
c.Client.GQLClient = graphql.NewConnection()
|
||||||
c.Client.GQLClient.SetEndpoint(c.Server.HostGraphQL)
|
c.Client.GQLClient.SetEndpoint(c.Server.HostGraphQL)
|
||||||
|
c.Server.AccessLog = envutil.GetBool("ENABLE_ACCESS_LOG", false)
|
||||||
cfg = &c
|
cfg = &c
|
||||||
enableCache() // takes close to no resources, but can be used with dynamic query cache
|
enableCache() // takes close to no resources, but can be used with dynamic query cache
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,9 @@ func processGraphQLRequest(c *fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
time_taken := time.Since(t)
|
time_taken := time.Since(t)
|
||||||
|
|
||||||
cfg.Logger.Info("Request processed", map[string]interface{}{"ip": c.IP(), "user_id": extracted_user_id, "op_type": opType, "op_name": opName, "time": time_taken, "cache": was_cached})
|
if cfg.Server.AccessLog {
|
||||||
|
cfg.Logger.Info("Request processed", map[string]interface{}{"ip": c.IP(), "user_id": extracted_user_id, "op_type": opType, "op_name": opName, "time": time_taken, "cache": was_cached})
|
||||||
|
}
|
||||||
cfg.Monitoring.Increment(libpack_monitoring.MetricsSucceeded, nil)
|
cfg.Monitoring.Increment(libpack_monitoring.MetricsSucceeded, nil)
|
||||||
|
|
||||||
labels := map[string]string{
|
labels := map[string]string{
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ spec:
|
|||||||
value: "9393"
|
value: "9393"
|
||||||
- name: HOST_GRAPHQL
|
- name: HOST_GRAPHQL
|
||||||
value: http://hasura-internal:8080/v1/graphql
|
value: http://hasura-internal:8080/v1/graphql
|
||||||
- name: ENABLE_CACHE
|
- name: ENABLE_GLOBAL_CACHE
|
||||||
value: "true"
|
value: "true"
|
||||||
- name: CACHE_TTL
|
- name: CACHE_TTL
|
||||||
value: "10"
|
value: "10"
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ type config struct {
|
|||||||
PortGraphQL int
|
PortGraphQL int
|
||||||
PortMonitoring int
|
PortMonitoring int
|
||||||
HostGraphQL string
|
HostGraphQL string
|
||||||
|
AccessLog bool
|
||||||
}
|
}
|
||||||
|
|
||||||
Client struct {
|
Client struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user