@@ -970,117 +970,58 @@ Users are recommended to do performance testing to determine the optimal configu
970970
971971## Performance Metrics
972972
973- OPA exposes metrics for each phase of policy evaluation :
973+ OPA exposes metrics for policy evaluation performance. These are available through :
974974
975- - ** System-wide metrics** are available at the ` /metrics ` Prometheus endpoint
976- - ** Per-query metrics** are returned with individual API responses when ` ?metrics=true ` is specified
975+ - ** System-wide metrics** at the ` /metrics ` Prometheus endpoint
976+ - ** Per-query metrics** with individual API responses when ` ?metrics=true ` is specified
977977
978- See [ Monitoring] ( ./monitoring#metrics-overview ) for the distinction between these metric types .
978+ See [ Monitoring] ( ./monitoring#metrics-overview ) for more details .
979979
980- ### Query Evaluation Metrics
980+ ### Common Built-in Function Metrics
981981
982- Query evaluation phases:
983-
984- - ` timer_rego_query_parse_ns ` - Time spent parsing the query string into AST
985- - ` timer_rego_query_compile_ns ` - Time spent compiling the query for evaluation
986- - ` timer_rego_query_eval_ns ` - Time spent executing the compiled query
987-
988- Compilation time often dominates in complex policies.
989-
990- ### Module and Policy Metrics
991-
992- Policy compilation and parsing:
993-
994- - ` timer_rego_module_parse_ns ` - Time to parse policy modules from source
995- - ` timer_rego_module_compile_ns ` - Time to compile parsed modules into evaluation form
996- - ` timer_rego_data_parse_ns ` - Time to parse data documents
997- - ` timer_rego_input_parse_ns ` - Time to parse input documents
998-
999- Module compilation runs once at load time. Slow compilation impacts bundle updates.
1000-
1001- ### File and Bundle Loading
1002-
1003- Policy and data loading:
1004-
1005- - ` timer_rego_load_files_ns ` - Time to load policy files from disk
1006- - ` timer_rego_load_bundles_ns ` - Time to load and activate bundles
1007- - ` timer_bundle_request_ns ` - Time spent downloading bundles
1008-
1009- ### Compilation and Partial Evaluation Metrics
1010-
1011- Compilation and partial evaluation:
1012-
1013- - ` timer_rego_partial_eval_ns ` - Total partial evaluation time
1014- - ` timer_compile_prep_partial_ns ` - Time preparing for partial evaluation
1015- - ` timer_compile_eval_constraints_ns ` - Time evaluating constraints
1016- - ` timer_compile_translate_queries_ns ` - Time translating queries
1017- - ` timer_compile_extract_annotations_unknowns_ns ` - Time extracting unknowns
1018- - ` timer_compile_extract_annotations_mask_ns ` - Time extracting masks
1019- - ` timer_compile_eval_mask_rule_ns ` - Time evaluating mask rules
1020- - ` timer_compile_stage_check_imports_ns ` - Time checking imports
1021- - ` counter_compile_stage_comprehension_index_build ` - Comprehension indices built
1022-
1023- High partial evaluation times indicate optimization opportunities.
1024-
1025- ### Evaluation Operation Metrics
1026-
1027- Evaluation operations produce both timer and histogram metrics:
982+ #### HTTP Built-ins
1028983
1029- ** Timers** (measure total time):
1030- - ` timer_eval_op_plug_ns ` - Time spent in plugging operations
1031- - ` timer_eval_op_resolve_ns ` - Time resolving references
1032- - ` timer_eval_op_rule_index_ns ` - Time spent in rule indexing
1033- - ` timer_eval_op_builtin_call_ns ` - Time spent calling built-in functions
1034- - ` timer_partial_op_save_unify_ns ` - Time saving unification in partial eval
1035- - ` timer_partial_op_save_set_contains_ns ` - Time for set contains in partial eval
1036- - ` timer_partial_op_save_set_contains_rec_ns ` - Time for recursive set contains
1037- - ` timer_partial_op_copy_propagation_ns ` - Time for copy propagation optimization
984+ ` http.send ` metrics help identify I/O bottlenecks:
1038985
1039- ** Histograms** (track time distribution):
1040- - ` histogram_eval_op_plug ` - Distribution of plugging operation times
1041- - ` histogram_eval_op_resolve ` - Distribution of reference resolution times
1042- - ` histogram_eval_op_rule_index ` - Distribution of rule indexing times
1043- - ` histogram_eval_op_builtin_call ` - Distribution of built-in function call times
1044- - ` histogram_partial_op_save_unify ` - Distribution of unification save times
1045- - ` histogram_partial_op_save_set_contains ` - Distribution of set contains times
1046- - ` histogram_partial_op_save_set_contains_rec ` - Distribution of recursive set contains times
1047- - ` histogram_partial_op_copy_propagation ` - Distribution of copy propagation times
986+ - ` timer_rego_builtin_http_send_ns ` - Total time spent in http.send calls
987+ - ` counter_rego_builtin_http_send_interquery_cache_hits ` - Inter-query cache hits
988+ - ` counter_rego_builtin_http_send_network_requests ` - Actual network requests made
1048989
1049- Histograms show percentiles: 50%, 75%, 90%, 95%, 99%, 99.9%, 99.99% .
990+ High cache hit ratios indicate effective caching and reduced network overhead .
1050991
1051- ### Built-in Function Metrics
992+ #### Regex Built-ins
1052993
1053- #### HTTP Built-ins
994+ Regex operation metrics help optimize pattern matching:
1054995
1055- ` http.send ` metrics:
996+ - ` timer_rego_builtin_regex_interquery_ns ` - Time spent in regex operations
997+ - ` counter_rego_builtin_regex_interquery_cache_hits ` - Regex pattern cache hits
998+ - ` counter_rego_builtin_regex_interquery_value_cache_hits ` - Regex value cache hits
1056999
1057- - ` timer_rego_builtin_http_send_ns ` - Total time spent in http.send calls
1058- - ` counter_rego_builtin_http_send_interquery_cache_hits ` - Inter-query cache hits
1059- - ` counter_rego_builtin_http_send_network_requests ` - Actual network requests made
1000+ Effective regex caching improves performance when the same patterns are used repeatedly.
10601001
1061- High cache hit ratios indicate effective caching.
1002+ ### Core Query Metrics
10621003
1063- #### External Data Resolution
1004+ Basic query evaluation phases:
10641005
1065- External data resolution:
1006+ - ` timer_rego_query_parse_ns ` - Time parsing the query string
1007+ - ` timer_rego_query_compile_ns ` - Time compiling the query
1008+ - ` timer_rego_query_eval_ns ` - Time executing the compiled query
10661009
1067- - ` timer_rego_external_resolve_ns ` - Time resolving external data references
1010+ Compilation time often dominates in complex policies.
10681011
1069- ### SDK and Server Metrics
1012+ ### High-Level Metrics
10701013
1071- High -level evaluation :
1014+ Server -level metrics for overall performance :
10721015
10731016- ` timer_server_handler_ns ` - Total request handler execution time
1074- - ` timer_sdk_decision_eval_ns ` - SDK decision evaluation time
10751017- ` counter_server_query_cache_hit ` - Server-level query cache hits
10761018
1077- ### Using Metrics
1019+ ### Using Metrics for Optimization
10781020
1079- 1 . Compare parse, compile, and eval times to find slow phases
1080- 2 . High operation counts indicate complex queries
1081- 3 . Low cache hit rates suggest tuning opportunities
1082- 4 . High ` http.send ` counts indicate I/O bottlenecks
1083- 5 . Bundle activation times show deployment latency
1021+ 1 . ** Query phases** : Compare parse, compile, and eval times to identify bottlenecks
1022+ 2 . ** Cache effectiveness** : Low cache hit rates suggest tuning opportunities
1023+ 3 . ** I/O bottlenecks** : High ` http.send ` network request counts indicate caching issues
1024+ 4 . ** Pattern matching** : Monitor regex cache hits for frequently used patterns
10841025
10851026Access metrics via:
10861027- REST API: Add ` ?metrics=true ` to policy evaluation requests
0 commit comments