File tree Expand file tree Collapse file tree 7 files changed +36
-7
lines changed
tests/Test/Prometheus/Storage Expand file tree Collapse file tree 7 files changed +36
-7
lines changed Original file line number Diff line number Diff line change @@ -30,10 +30,16 @@ jobs:
3030 - 5432:5432
3131
3232 env :
33- # The hostname used to communicate with the Redis service container
33+ # The hostname used to communicate with the Redis/Sentinel service containers
3434 REDIS_HOST : redis
35+ # The hostname for redis sentinel
36+ REDIS_SENTINEL_HOST : redis-sentinel
3537 # The default Redis port
3638 REDIS_PORT : 6379
39+ # The default Redis Sentinel port
40+ REDIS_SENTINEL_PORT : 26379
41+ # The default Redis Sentinel primary
42+ REDIS_SENTINEL_SERVICE : myprimary
3743 # MySQL
3844 DB_DATABASE : test
3945 DB_USER : root
6975 with :
7076 redis-version : ${{ matrix.redis-version }}
7177
78+ - name : Generate Redis Sentinel conf compatible with redis 5 assuming 127.0.0.1 (no resolve hostname)
79+ run : |
80+ REDIS_SENTINEL_IP=127.0.0.1
81+ cat <<EOF > sentinel5.conf
82+ port ${{ env.REDIS_SENTINEL_PORT }}
83+ sentinel monitor ${{ env.REDIS_SENTINEL_SERVICE }} $REDIS_SENTINEL_IP ${{ env.REDIS_PORT }} 2
84+ sentinel down-after-milliseconds ${{ env.REDIS_SENTINEL_SERVICE }} 10000
85+ sentinel failover-timeout ${{ env.REDIS_SENTINEL_SERVICE }} 180000
86+ sentinel parallel-syncs ${{ env.REDIS_SENTINEL_SERVICE }} 2
87+ EOF
88+
89+ - name : Start Redis Sentinel
90+ run : docker run -d --name ${{env.REDIS_SENTINEL_HOST}} -p 26379:26379 --link redis:redis -v $PWD/sentinel5.conf:/data/sentinel.conf redis:${{ matrix.redis-version }} redis-server sentinel.conf --sentinel
91+
7292 - name : Execute tests (PDO with Sqlite)
7393 run : vendor/bin/phpunit
7494
Original file line number Diff line number Diff line change 11{
2- "github-actions.workflows.pinned.workflows" : []
2+ "github-actions.workflows.pinned.workflows" : [],
3+ "githubPullRequests.ignoredPullRequestBranches" : [
4+ " main"
5+ ]
36}
Original file line number Diff line number Diff line change 88
99if ($ adapterName === 'redis ' ) {
1010 define ('REDIS_HOST ' , $ _SERVER ['REDIS_HOST ' ] ?? '127.0.0.1 ' );
11+ define ('REDIS_SENTINEL_HOST ' , $ _SERVER ['REDIS_SENTINEL_HOST ' ] ?? '127.0.0.1 ' );
1112
12- $ adapter = new Prometheus \Storage \Redis (['host ' => REDIS_HOST ]);
13+ $ adapter = new Prometheus \Storage \Redis (['host ' => REDIS_HOST , ' sentinel ' => [ ' host ' => REDIS_SENTINEL_HOST ] ]);
1314} elseif ($ adapterName === 'apc ' ) {
1415 $ adapter = new Prometheus \Storage \APC ();
1516} elseif ($ adapterName === 'apcng ' ) {
Original file line number Diff line number Diff line change 11bind 0.0.0.0
2+ port 26379
23sentinel monitor myprimary redis 6379 2
34sentinel resolve-hostnames yes
45sentinel down-after-milliseconds myprimary 10000
Original file line number Diff line number Diff line change @@ -130,7 +130,7 @@ public function getRedisSentinel(): \RedisSentinel
130130 * @return self
131131 * @throws StorageException
132132 */
133- public static function fromExistingConnection (\Redis $ redis , \RedisSentinel $ redisSentinel = null ): self
133+ public static function fromExistingConnection (\Redis $ redis , ? \RedisSentinel $ redisSentinel = null ): self
134134 {
135135 if (isset ($ redisSentinel )) {
136136 RedisSentinel::fromExistingConnection ($ redisSentinel );
Original file line number Diff line number Diff line change 44
55use Prometheus \Exception \StorageException ;
66
7+ // Redis Sentinel connector based on https://github.com/Namoshek/laravel-redis-sentinel
78class RedisSentinel
89{
910 /**
Original file line number Diff line number Diff line change @@ -60,7 +60,10 @@ public function itShouldThrowExceptionWhenInjectedRedisIsNotConnected(): void
6060 {
6161 $ connection = new \Redis ();
6262 // @phpstan-ignore arguments.count
63- $ sentinel = new \RedisSentinel ();
63+
64+ $ sentinel = version_compare ((string )phpversion ('redis ' ), '6.0 ' , '>= ' ) ?
65+ new \RedisSentinel (['host ' => '/dev/null ' ]) :
66+ new \RedisSentinel ('/dev/null ' );
6467
6568 self ::expectException (StorageException::class);
6669 self ::expectExceptionMessageMatches ("/Can't connect to RedisSentinel server \\..*/ " );
@@ -86,8 +89,8 @@ public function itShouldThrowAnExceptionOnPrimaryFailure(): void
8689 * @test
8790 */
8891 public function itShouldGetMaster (): void
89- {
90- $ redis = new Redis (['host ' => ' /dev/null ' ,
92+ {
93+ $ redis = new Redis (['host ' => REDIS_HOST ,
9194 'sentinel ' => ['host ' => REDIS_SENTINEL_HOST , 'enable ' => true , 'service ' => 'myprimary ' ]
9295 ]);
9396
You can’t perform that action at this time.
0 commit comments