From b0a8c1ab9da0b16d65b6b5ca604479838c61813a Mon Sep 17 00:00:00 2001 From: qem19 <49522198+qem19@users.noreply.github.com> Date: Tue, 8 Aug 2023 10:14:07 +0300 Subject: [PATCH] Redis connection fix (#7) Laravel doesnt have ability to use different redis-clients for different connections. It can be problem if you want to use sentinel-connection for app and phpredis for metrics. So, in the PR i changed redis config for Prometheus. Now, you can specify redis-client and all credentials right in event-tracker.php config --------- Co-authored-by: umbr --- config/event_tracker.php | 11 ++++++++++- src/Repositories/PrometheusRepository/Installer.php | 7 +++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/config/event_tracker.php b/config/event_tracker.php index 66406d7..58bd350 100644 --- a/config/event_tracker.php +++ b/config/event_tracker.php @@ -28,7 +28,16 @@ ], ], 'prometheus' => [ - 'redis' => 'default', + 'redis' => [ + 'client' => env('EVENT_TRACKER_REDIS_CLIENT', 'phpredis'), + 'credentials' => [ + 'host' => env('EVENT_TRACKER_REDIS_HOST', 'localhost'), + 'username' => env('EVENT_TRACKER_REDIS_USERNAME', 'redis'), + 'password' => env('EVENT_TRACKER_REDIS_PASSWORD'), + 'port' => env('EVENT_TRACKER_REDIS_PORT', '6379'), + 'database' => env('EVENT_TRACKER_REDIS_DATABASE', 0), + ], + ], 'labels' => [ 'namespace' => 'app_ns', ], diff --git a/src/Repositories/PrometheusRepository/Installer.php b/src/Repositories/PrometheusRepository/Installer.php index 3bce01b..7a325c4 100644 --- a/src/Repositories/PrometheusRepository/Installer.php +++ b/src/Repositories/PrometheusRepository/Installer.php @@ -22,10 +22,9 @@ public function install(array $config): void } $this->app->singleton(PrometheusRepositoryContract::class, function () use ($config) { - /** @var RedisManager $redisManager */ - $redisManager = $this->app->make(RedisManager::class); - $connection = $config['connections']['prometheus']['redis']; - $redis = $redisManager->connection($connection) + $redisConfig = $config['connections']['prometheus']['redis']; + $redisManager = new RedisManager($this->app, $redisConfig['client'], $redisConfig); + $redis = $redisManager->connection('credentials') ->client(); $redis->setOption(NativeRedis::OPT_PREFIX, '');