Skip to content

fix: correct service parameters for elastic_search type handlers #501

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: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion DependencyInjection/MonologExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
Author

Choose a reason for hiding this comment

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

@stof Bump!

(Let me know if y'all don't like bumps.)

];

if (isset($handler['elasticsearch']['user'], $handler['elasticsearch']['password'])) {
Expand Down
Loading