Skip to content

Commit

Permalink
allow multiple endpoints as dsn to avoid downtime if single node fail…
Browse files Browse the repository at this point in the history
…s. (new config `hosts`)
  • Loading branch information
rliebi committed Mar 18, 2024
1 parent d3c07c3 commit 0dedaf4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public function getConfigTreeBuilder()
->children()
->arrayNode('client')
->children()
->arrayNode('connections')->info('An array of DSN to connect to the Elasticsearch cluster.')
->arrayPrototype()
->children()
->scalarNode('url')->end()
->end()
->end()
->end()
->scalarNode('dsn')->defaultValue('http://localhost:9200')->info('The DSN to connect to the Elasticsearch cluster.')->end()
->booleanNode('should_add_sentry_breadcrumbs')->defaultFalse()->info('If true, breadcrumbs are added to Sentry for every request made to Elasticsearch via Elastica.')->end()
->end()
Expand Down
14 changes: 13 additions & 1 deletion src/Repository/ConfigurationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Valantic\ElasticaBridgeBundle\Repository;

use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;

/**
Expand All @@ -15,8 +17,18 @@ public function __construct(
private readonly ContainerBagInterface $containerBag,
) {}

public function getClientDsn(): string
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*
* @return string|array<string>
*/
public function getClientDsn(): string|array
{
if ($this->containerBag->get('valantic_elastica_bridge')['client']['connections'] !== []) {
return ['connections' => $this->containerBag->get('valantic_elastica_bridge')['client']['connections']];
}

return $this->containerBag->get('valantic_elastica_bridge')['client']['dsn'];
}

Expand Down

0 comments on commit 0dedaf4

Please sign in to comment.