File tree 7 files changed +36
-7
lines changed
tests/Test/Prometheus/Storage
7 files changed +36
-7
lines changed Original file line number Diff line number Diff line change @@ -30,10 +30,16 @@ jobs:
30
30
- 5432:5432
31
31
32
32
env :
33
- # The hostname used to communicate with the Redis service container
33
+ # The hostname used to communicate with the Redis/Sentinel service containers
34
34
REDIS_HOST : redis
35
+ # The hostname for redis sentinel
36
+ REDIS_SENTINEL_HOST : redis-sentinel
35
37
# The default Redis port
36
38
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
37
43
# MySQL
38
44
DB_DATABASE : test
39
45
DB_USER : root
69
75
with :
70
76
redis-version : ${{ matrix.redis-version }}
71
77
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
+
72
92
- name : Execute tests (PDO with Sqlite)
73
93
run : vendor/bin/phpunit
74
94
Original file line number Diff line number Diff line change 1
1
{
2
- "github-actions.workflows.pinned.workflows" : []
2
+ "github-actions.workflows.pinned.workflows" : [],
3
+ "githubPullRequests.ignoredPullRequestBranches" : [
4
+ " main"
5
+ ]
3
6
}
Original file line number Diff line number Diff line change 8
8
9
9
if ($ adapterName === 'redis ' ) {
10
10
define ('REDIS_HOST ' , $ _SERVER ['REDIS_HOST ' ] ?? '127.0.0.1 ' );
11
+ define ('REDIS_SENTINEL_HOST ' , $ _SERVER ['REDIS_SENTINEL_HOST ' ] ?? '127.0.0.1 ' );
11
12
12
- $ adapter = new Prometheus \Storage \Redis (['host ' => REDIS_HOST ]);
13
+ $ adapter = new Prometheus \Storage \Redis (['host ' => REDIS_HOST , ' sentinel ' => [ ' host ' => REDIS_SENTINEL_HOST ] ]);
13
14
} elseif ($ adapterName === 'apc ' ) {
14
15
$ adapter = new Prometheus \Storage \APC ();
15
16
} elseif ($ adapterName === 'apcng ' ) {
Original file line number Diff line number Diff line change 1
1
bind 0.0.0.0
2
+ port 26379
2
3
sentinel monitor myprimary redis 6379 2
3
4
sentinel resolve-hostnames yes
4
5
sentinel down-after-milliseconds myprimary 10000
Original file line number Diff line number Diff line change @@ -130,7 +130,7 @@ public function getRedisSentinel(): \RedisSentinel
130
130
* @return self
131
131
* @throws StorageException
132
132
*/
133
- public static function fromExistingConnection (\Redis $ redis , \RedisSentinel $ redisSentinel = null ): self
133
+ public static function fromExistingConnection (\Redis $ redis , ? \RedisSentinel $ redisSentinel = null ): self
134
134
{
135
135
if (isset ($ redisSentinel )) {
136
136
RedisSentinel::fromExistingConnection ($ redisSentinel );
Original file line number Diff line number Diff line change 4
4
5
5
use Prometheus \Exception \StorageException ;
6
6
7
+ // Redis Sentinel connector based on https://github.com/Namoshek/laravel-redis-sentinel
7
8
class RedisSentinel
8
9
{
9
10
/**
Original file line number Diff line number Diff line change @@ -60,7 +60,10 @@ public function itShouldThrowExceptionWhenInjectedRedisIsNotConnected(): void
60
60
{
61
61
$ connection = new \Redis ();
62
62
// @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 ' );
64
67
65
68
self ::expectException (StorageException::class);
66
69
self ::expectExceptionMessageMatches ("/Can't connect to RedisSentinel server \\..*/ " );
@@ -86,8 +89,8 @@ public function itShouldThrowAnExceptionOnPrimaryFailure(): void
86
89
* @test
87
90
*/
88
91
public function itShouldGetMaster (): void
89
- {
90
- $ redis = new Redis (['host ' => ' /dev/null ' ,
92
+ {
93
+ $ redis = new Redis (['host ' => REDIS_HOST ,
91
94
'sentinel ' => ['host ' => REDIS_SENTINEL_HOST , 'enable ' => true , 'service ' => 'myprimary ' ]
92
95
]);
93
96
You can’t perform that action at this time.
0 commit comments