Skip to content

Conversation

@hpopuri2
Copy link

@hpopuri2 hpopuri2 commented Nov 26, 2025

Summary

This PR introduces a configurable option to enable/disable query history recording in Trino Gateway, addressing database performance bottlenecks and infrastructure cost concerns.

Problem

Currently, query history is always saved to the database, which creates several operational challenges:

  • Database becomes a bottleneck under high query loads, causing performance degradation
  • Forces operators to scale up database instances to handle the write load
  • Increases infrastructure costs significantly due to larger DB instance requirements
  • Query history may not be needed in all deployment scenarios (dev/test environments, alternative monitoring solutions)

Solution

Added a new configuration option queryHistoryEnabled in RoutingConfiguration that allows operators to:

  • Disable query history recording when not needed
  • Use lower-tier database instances, reducing operational costs
  • Improve overall gateway performance by eliminating unnecessary database writes
  • Maintain flexibility to enable/disable based on deployment requirements

Configuration

routing:
# Enable or disable query history recording to database (default: true)
queryHistoryEnabled: false # Set to false to disable query history recording

Default behavior: Query history is enabled by default (true) to maintain backward compatibility.

Benefits

  • ✅ Eliminated database bottleneck - No more query history writes under high load
  • ✅ Significant cost savings - Can use smaller, cheaper database instances
  • ✅ Improved gateway performance - Reduced database round trips
  • ✅ Operational flexibility - Enable/disable based on environment needs
  • ✅ Backward compatible - Existing deployments continue working unchanged

Implementation Details

Core Changes

  • RoutingConfiguration.java: Added queryHistoryEnabled boolean field with getter/setter (defaults to true)
  • ProxyRequestHandler.java: Added conditional check before queryHistoryManager.submitQueryDetail() to respect the configuration flag
  • config.yaml: Added configuration example with inline documentation

Test Coverage

Added comprehensive test suite covering all scenarios:

  • TestRoutingConfiguration: Unit tests for configuration parsing and defaults (3 tests)
  • TestProxyRequestHandlerQueryHistoryEnabled: Integration test validating queries ARE recorded when enabled
  • TestProxyRequestHandlerQueryHistoryDisabled: Integration test validating queries are NOT recorded when disabled
  • test-config-with-query-history-disabled.yml: Test configuration file for disabled scenario

All tests pass: 290 tests run, 0 failures, 0 errors

Backward Compatibility

✅ Fully backward compatible

  • Default value is true, maintaining existing behavior
  • Existing configurations without this setting will continue to record query history
  • No database schema changes required
  • No breaking changes to APIs or interfaces

Files Changed

Production Code (3 files)

  • gateway-ha/src/main/java/io/trino/gateway/ha/config/RoutingConfiguration.java
  • gateway-ha/src/main/java/io/trino/gateway/proxyserver/ProxyRequestHandler.java
  • gateway-ha/config.yaml

Test Code (5 files)

  • gateway-ha/src/test/java/io/trino/gateway/ha/config/TestRoutingConfiguration.java
  • gateway-ha/src/test/java/io/trino/gateway/proxyserver/TestProxyRequestHandlerQueryHistoryEnabled.java
  • gateway-ha/src/test/java/io/trino/gateway/proxyserver/TestProxyRequestHandlerQueryHistoryDisabled.java
  • gateway-ha/src/test/resources/test-config-template.yml
  • gateway-ha/src/test/resources/test-config-with-query-history-disabled.yml

Follow-up

After this PR is approved and merged, a follow-up PR will be submitted to the Trino Gateway Helm Charts repository to expose this configuration option in the Helm values, making it easier for Kubernetes deployments to configure this setting.

@cla-bot
Copy link

cla-bot bot commented Nov 26, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant