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

allow multiple endpoints as dsn to avoid downtime #68

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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()
Copy link
Member

Choose a reason for hiding this comment

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

Remove this config node

->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
Loading