Skip to content

v1/topdown/graphql: Cache GraphQL schema parse results (#5377) #7457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/content/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -863,17 +863,19 @@ Caching represents the configuration of the inter-query cache that built-in func
functions provided by OPA, `http.send` is currently the only one to utilize the inter-query cache. See the documentation
on the [http.send built-in function](../policy-reference/#http) for information about the available caching options.

It also represents the configuration of the inter-query _value_ cache that built-in functions can utilize. Currently,
It also represents the configuration of the inter-query _value_ cache that built-in functions can utilize. Currently,
this cache is utilized by the `regex` and `glob` built-in functions for compiled regex and glob match patterns
respectively, and the `json.schema_match` built-in function for compiled JSON schemas.
respectively, the `json.schema_match` built-in function for compiled JSON schemas, and any `graphql` built-in function
that requires GraphQL schemas.

| Field | Type | Required | Description |
|--------------------------------------------------------------------------|---------|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `caching.inter_query_builtin_cache.max_size_bytes` | `int64` | No | Inter-query cache size limit in bytes. OPA will drop old items from the cache if this limit is exceeded. By default, no limit is set. |
| `caching.inter_query_builtin_cache.forced_eviction_threshold_percentage` | `int64` | No | Threshold limit configured as percentage of `caching.inter_query_builtin_cache.max_size_bytes`, when exceeded OPA will start dropping old items permaturely. By default, set to `100`. |
| `caching.inter_query_builtin_cache.forced_eviction_threshold_percentage` | `int64` | No | Threshold limit configured as percentage of `caching.inter_query_builtin_cache.max_size_bytes`, when exceeded OPA will start dropping old items prematurely. By default, set to `100`. |
| `caching.inter_query_builtin_cache.stale_entry_eviction_period_seconds` | `int64` | No | Stale entry eviction period in seconds. OPA will drop expired items from the cache every `stale_entry_eviction_period_seconds`. By default, set to `0` indicating stale entry eviction is disabled. |
| `caching.inter_query_builtin_value_cache.max_num_entries` | `int` | No | Maximum number of entries in the Inter-query value cache. OPA will drop random items from the cache if this limit is exceeded. By default, set to `0` indicating unlimited size. |
| `caching.inter_query_builtin_value_cache.named.io_jwt.max_num_entries` | `int` | No | Maximum number of entries in the `io_jwt` cache, used by the [`io.jwt` token verification](../policy-reference/#tokens) built-in functions. OPA will drop random items from the cache if this limit is exceeded. By default, this cache is disabled. |
| `caching.inter_query_builtin_value_cache.named.graphql.max_num_entries` | `int` | No | Maximum number of entries in the `graphql` cache, used by the [`graphql` builtins](../policy-reference/#graphql) built-in functions to cache parsed schemas. OPA will drop random items from the cache if this limit is exceeded. By default, this cache is set to a maximum of 10 entries. |

## Distributed tracing

Expand Down
16 changes: 12 additions & 4 deletions v1/plugins/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1721,8 +1721,9 @@ func TestReconfigureWithLocalOverride(t *testing.T) {
"inter_query_builtin_cache": {"max_size_bytes": 10000000, "forced_eviction_threshold_percentage": 90},
"inter_query_builtin_value_cache": {
"named": {
"io_jwt": {"max_num_entries": 55}
}
"io_jwt": {"max_num_entries": 55},
"graphql": {"max_num_entries": 10}
}
}
}
}`)
Expand Down Expand Up @@ -1888,8 +1889,9 @@ func TestReconfigureWithLocalOverride(t *testing.T) {
"inter_query_builtin_cache": {"max_size_bytes": 200, "stale_entry_eviction_period_seconds": 10, "forced_eviction_threshold_percentage": 200},
"inter_query_builtin_value_cache": {
"named": {
"io_jwt": {"max_num_entries": 10}
}
"io_jwt": {"max_num_entries": 10},
"graphql": {"max_num_entries": 11}
}
}
}
}
Expand All @@ -1906,6 +1908,7 @@ func TestReconfigureWithLocalOverride(t *testing.T) {
"caching.inter_query_builtin_cache.max_size_bytes",
"caching.inter_query_builtin_cache.forced_eviction_threshold_percentage",
"caching.inter_query_builtin_value_cache.named.io_jwt.max_num_entries",
"caching.inter_query_builtin_value_cache.named.graphql.max_num_entries",
}
for _, k := range expectedOverriddenKeys {
if !strings.Contains(disco.status.Message, k) {
Expand All @@ -1928,6 +1931,8 @@ func TestReconfigureWithLocalOverride(t *testing.T) {
*maxNumEntriesInterQueryValueCache = 0
maxNumEntriesJWTValueCache := new(int)
*maxNumEntriesJWTValueCache = 55
maxNumEntriesGraphQLValueCache := new(int)
*maxNumEntriesGraphQLValueCache = 10

expectedCacheConf := &cache.Config{
InterQueryBuiltinCache: cache.InterQueryBuiltinCacheConfig{
Expand All @@ -1941,6 +1946,9 @@ func TestReconfigureWithLocalOverride(t *testing.T) {
"io_jwt": {
MaxNumEntries: maxNumEntriesJWTValueCache,
},
"graphql": {
MaxNumEntries: maxNumEntriesGraphQLValueCache,
},
},
},
}
Expand Down
Loading
Loading