Add ability to enable / disable access log.

In high frequency environments it can be a little bit noisy.
This commit is contained in:
2023-10-09 08:41:05 +01:00
parent b89053c015
commit 743eed7f71
4 changed files with 6 additions and 1 deletions
+1
View File
@@ -37,6 +37,7 @@ I wanted to monitor the queries and responses of our graphql endpoint, but we di
* `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 ### Caching
+1
View File
@@ -28,6 +28,7 @@ func parseConfig() {
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
} }
+3 -1
View File
@@ -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{
+1
View File
@@ -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 {