contributte / elastica

:mag: Tiny Elastica integration into Nette Framework (@nette)
MIT License
6 stars 7 forks source link

Client configuration #4

Closed tg666 closed 2 years ago

tg666 commented 3 years ago

Hi, when integrating the extension into our project, I found out that the Client configuration has an invalid structure and also that default (null) values are getting into the Client.

Current configuration example:

contributte.elastica:
    debug: %debugMode%
    hosts:
        es01:
            host: elasticsearch
            port: 9200
<?php
​
public function createServiceContributte__elastica__client(): Contributte\Elastica\Client
{
    $service = new Contributte\Elastica\Client(
        [
            'es01' => [
                'host' => 'elasticsearch',
                'port' => 9200,
                'path' => null,
                'url' => null,
                'proxy' => null,
                'transport' => null,
                'persistent' => null,
                'timeout' => null,
                'connections' => [],
                'roundRobin' => null,
                'compression' => null,
                'log' => null,
                'retryOnConflict' => null,
                'bigintConversion' => null,
                'username' => null,
                'password' => null,
            ],
        ],
        null,
        $this->getService('contributte.monolog.logger.default')
    );
    $this->getService('contributte.elastica.panel')->register($service);
    return $service;
}

But options for the default Client should be in the configuration root. In the case of multiple nodes, they are defined under the key connections.

New configuration example:

contributte.elastica:
    debug: %debugMode%
    config:
        host: elasticsearch
        port: 9200
public function createServiceContributte__elastica__client(): Contributte\Elastica\Client
{
    $service = new Contributte\Elastica\Client(
        ['host' => 'elasticsearch`, 'port' => 9200],
        null,
        $this->getService('contributte.monolog.logger.default')
    );
    $this->getService('contributte.elastica.panel')->register($service);
    return $service;
}

I also marked options host, port, username, password and auth_type as dynamic - parameters, env variables etc. are allowed.

Package nette/schema is required because of usage of the method ::skipDefaults() that has been added in the version ^1.2.

f3l1x commented 3 years ago

Hi. Does it means there is not support for multiple configuration?

tg666 commented 3 years ago

Ruflin/Elastica supports multiple connections. They can be defined under key connections: https://github.com/ruflin/Elastica/blob/master/src/Client.php#L619

For example:

contributte.elastica:
    debug: %debugMode%
    config:
        connections:
            -
                host: host1
                port: 1234
                # ...
            -
                host: host2
                port: 5678
                # ...
f3l1x commented 3 years ago

Oh, I see it now. Thanks. I've added some comments.

f3l1x commented 2 years ago

Ping @tg666

jiripudil commented 2 years ago

Hi, is there anything I can help with to get this merged? Correct me if I'm wrong (please do!) but I think the package is now unusable e.g. with docker-compose where ES is usually accessible via a different hostname than the default localhost 🤔

f3l1x commented 2 years ago

It's OK, thanks for pinging me. @jiripudil