Skip to content

Commit

Permalink
Redis connection fix (#7)
Browse files Browse the repository at this point in the history
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 <aleksander.nau@cadolabs.io>
  • Loading branch information
qem19 and umbr committed Aug 8, 2023
1 parent dbcfe6d commit b0a8c1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 10 additions & 1 deletion config/event_tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down
7 changes: 3 additions & 4 deletions src/Repositories/PrometheusRepository/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');

Expand Down

0 comments on commit b0a8c1a

Please sign in to comment.