Skip to content
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

fix: correct service parameters for elastic_search type handlers #501

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Kenneth-Sills
Copy link

Closes #500

@@ -292,7 +292,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
$factory = class_exists('Elastic\Elasticsearch\ClientBuilder') ? 'Elastic\Elasticsearch\ClientBuilder' : 'Elasticsearch\ClientBuilder';
$client->setFactory([$factory, 'fromConfig']);
$clientArguments = [
'host' => $handler['elasticsearch']['host'],
'hosts' => [$handler['elasticsearch']['host']],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not valid. The arguments need to be different for V7 or v8 (see just above where we already detect version 8+ for other differences)

Copy link
Author

@Kenneth-Sills Kenneth-Sills Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I said in the ticket, this applies to both v7 and v8. ClientBuilder::fromConfig works the same in both versions by proxying to the set* method and the only such method that exists is setHosts, not setHost.

In my demo project I just ran composer require elasticsearch/elasticsearch=^7 (using Elastica, so no v8), then set the monolog config like:

  monolog:
    handlers:
      main:
        type: fingers_crossed
        handler: elastic_search
        action_level: error
        excluded_http_codes: [404, 405]
        buffer_size: 50
      elastic_search:
        type: elastic_search
        elasticsearch:
          host: '%elastic_domain%'
          port: '%elastic_port%'
        index: '%elastic_index_monolog%'

Finally, I ran ./bin/console cache:clear (after rm -rf var/cache/* for good measure). And it also fails with:

In ClientBuilder.php line 217:

  Unknown parameters provided: host  

So far as I can tell this has always been the case in that client (though I only checked to v5). I think we just accidentally assumed the parameter was the same as Elastica at the time of implementation.

You are correct when it comes to Elastica, though, which I noted here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

elastic_search Handler Does Not Work (Invalid Factory Parameters)
2 participants