Active Context: Add one-click connection option

What does this MR do and why?

This MR adds support for automatic Elasticsearch configuration in AI ActiveContext connections to implement #525344 (closed).

Previously, the only option was to manually duplicate Elasticsearch configuration settings when creating ActiveContext connections. This created maintenance overhead and potential for configuration drift.

Now users can create a connection with use_advanced_search_config: true and it will automatically use GitLab's current Elasticsearch settings, staying synchronized without duplication:

Ai::ActiveContext::Connection.create!(
  name: "elastic",
  adapter_class: "ActiveContext::Databases::Elasticsearch::Adapter",
  options: { use_advanced_search_config: true }
)

The implementation directly returns ::Gitlab::CurrentSettings.elasticsearch_config since the ::Elasticsearch::Client can handle GitLab's URI hash format natively, requiring no transformation.

References

Closes #525344 (closed)

Screenshots or screen recordings

N/A - This is a backend API change with no UI components.

How to set up and validate locally

  1. Start the Rails console:

    bundle exec rails console
  2. Create a connection with automatic Elasticsearch configuration:

    connection = Ai::ActiveContext::Connection.create!(
      name: "elastic",
      adapter_class: "ActiveContext::Databases::Elasticsearch::Adapter",
      options: { use_advanced_search_config: true }
    )
  3. Verify the connection returns GitLab's Elasticsearch configuration:

    connection.options
    # Should return the same as:
    ::Gitlab::CurrentSettings.elasticsearch_config
  4. Verify the ActiveContext client can be instantiated successfully:

    ActiveContext::Databases::Elasticsearch::Client.new(connection.options)
    # Should create client without errors
  5. Test with custom options (should work as before):

    custom_connection = Ai::ActiveContext::Connection.create!(
      name: "custom",  
      adapter_class: "ActiveContext::Databases::Elasticsearch::Adapter",
      options: { url: "http://custom:9200" }
    )
    custom_connection.options
    # Should return the custom options

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

  • Performance: No performance impact - simply returns existing GitLab configuration
  • Security: No security changes - uses existing GitLab authentication and configuration
  • Reliability: Comprehensive test coverage with 26 passing tests including client compatibility verification
  • Code Quality: Simple, minimal implementation following GitLab patterns
  • Documentation: Inline code comments explain the purpose and behavior
Edited by Dmitry Gruzd

Merge request reports

Loading