Skip to content

Commit 075e16a

Browse files
committed
Use Dsn object instead of connection parameters per each service check
1 parent 745ab04 commit 075e16a

58 files changed

Lines changed: 788 additions & 969 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
CHANGELOG
22
=========
33

4+
Next release
5+
------------
6+
7+
* Remove connection parameters data transfer objects, use `Dsn` instead of. Affected checks:
8+
* Redis
9+
* ElasticSearch/OpenSearch
10+
* RabbitMQ
11+
* MongoDB
12+
413
v2.1.2
514
------
615

docker-compose.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ services:
9595
networks:
9696
- diagnostic
9797

98+
clickhouse-server:
99+
image: clickhouse:25.9
100+
container_name: diagnostic-clickhouse-server
101+
ulimits:
102+
nofile:
103+
soft: 262144
104+
hard: 262144
105+
environment:
106+
CLICKHOUSE_DB: diagnostic
107+
CLICKHOUSE_USER: diagnostic
108+
CLICKHOUSE_PASSWORD: Q1w2e3r4
109+
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
110+
networks:
111+
- diagnostic
112+
98113
networks:
99114
diagnostic:
100115
driver: bridge

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
colors="true"
55
bootstrap="./vendor/autoload.php"
66
displayDetailsOnTestsThatTriggerDeprecations="true"
7+
displayDetailsOnTestsThatTriggerWarnings="true"
78
>
89
<testsuites>
910
<testsuite name="Diagnostic tests">

src/Check/Doctrine/ReadAccessToTablesFromEntityManagerCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php /** @noinspection ALL */
1+
<?php
22

33
/*
44
* This file is part of the FiveLab Diagnostic package.

src/Check/Elasticsearch/ElasticsearchClusterStateCheck.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use FiveLab\Component\Diagnostic\Result\Result;
1919
use FiveLab\Component\Diagnostic\Result\Success;
2020
use FiveLab\Component\Diagnostic\Result\Warning;
21+
use FiveLab\Component\Diagnostic\Util\Dsn;
2122
use FiveLab\Component\Diagnostic\Util\Http\HttpAdapter;
2223
use FiveLab\Component\Diagnostic\Util\Http\HttpAdapterInterface;
2324

@@ -27,14 +28,14 @@
2728

2829
private HttpAdapterInterface $http;
2930

30-
public function __construct(private ElasticsearchConnectionParameters $connectionParameters, ?HttpAdapterInterface $http = null)
31+
public function __construct(private Dsn $dsn, ?HttpAdapterInterface $http = null)
3132
{
3233
$this->http = $http ?? new HttpAdapter();
3334
}
3435

3536
public function check(): Result
3637
{
37-
$result = $this->sendRequest($this->http, $this->connectionParameters, '_cat/health');
38+
$result = $this->sendRequest($this->http, $this->dsn, '_cat/health');
3839

3940
if ($result instanceof Result) {
4041
return $result;
@@ -57,7 +58,7 @@ public function check(): Result
5758
public function getExtraParameters(): array
5859
{
5960
return [
60-
'dsn' => $this->connectionParameters->getDsn(true),
61+
'dsn' => $this->dsn->getDsn(maskedPassword: true),
6162
];
6263
}
6364
}

src/Check/Elasticsearch/ElasticsearchConnectionCheck.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use FiveLab\Component\Diagnostic\Result\Failure;
1818
use FiveLab\Component\Diagnostic\Result\Result;
1919
use FiveLab\Component\Diagnostic\Result\Success;
20+
use FiveLab\Component\Diagnostic\Util\Dsn;
2021
use FiveLab\Component\Diagnostic\Util\Http\HttpAdapter;
2122
use FiveLab\Component\Diagnostic\Util\Http\HttpAdapterInterface;
2223

@@ -26,14 +27,14 @@
2627

2728
private HttpAdapterInterface $http;
2829

29-
public function __construct(private ElasticsearchConnectionParameters $connectionParameters, ?HttpAdapterInterface $http = null)
30+
public function __construct(private Dsn $dsn, ?HttpAdapterInterface $http = null)
3031
{
3132
$this->http = $http ?? new HttpAdapter();
3233
}
3334

3435
public function check(): Result
3536
{
36-
$result = $this->sendRequest($this->http, $this->connectionParameters, '_cat/health');
37+
$result = $this->sendRequest($this->http, $this->dsn, '_cat/health');
3738

3839
if ($result instanceof Result) {
3940
return $result;
@@ -51,7 +52,7 @@ public function check(): Result
5152
public function getExtraParameters(): array
5253
{
5354
return [
54-
'dsn' => $this->connectionParameters->getDsn(true),
55+
'dsn' => $this->dsn->getDsn(maskedPassword: true),
5556
];
5657
}
5758
}

src/Check/Elasticsearch/ElasticsearchConnectionParameters.php

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/Check/Elasticsearch/ElasticsearchHelperTrait.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,23 @@
1515

1616
use FiveLab\Component\Diagnostic\Result\Failure;
1717
use FiveLab\Component\Diagnostic\Result\Result;
18+
use FiveLab\Component\Diagnostic\Util\Dsn;
1819
use FiveLab\Component\Diagnostic\Util\Http\HttpAdapterInterface;
1920

2021
trait ElasticsearchHelperTrait
2122
{
2223
/**
2324
* Send request to elasticsearch API.
2425
*
25-
* @param HttpAdapterInterface $http
26-
* @param ElasticsearchConnectionParameters $connectionParameters
27-
* @param string $uri
26+
* @param HttpAdapterInterface $http
27+
* @param Dsn $dsn
28+
* @param string $uri
2829
*
2930
* @return Result|array<string|int, mixed>
3031
*/
31-
protected function sendRequest(HttpAdapterInterface $http, ElasticsearchConnectionParameters $connectionParameters, string $uri): Result|array
32+
protected function sendRequest(HttpAdapterInterface $http, Dsn $dsn, string $uri): Result|array
3233
{
33-
$uri = \sprintf('%s/%s', \rtrim($connectionParameters->getDsn(), \ltrim($uri, '/')), $uri);
34+
$uri = \sprintf('%s/%s', \rtrim($dsn->getDsn(), \ltrim($uri, '/')), $uri);
3435

3536
$request = $http->createRequest('GET', $uri, [
3637
'accept' => 'application/json',
@@ -43,7 +44,7 @@ protected function sendRequest(HttpAdapterInterface $http, ElasticsearchConnecti
4344
} catch (\Throwable $error) {
4445
return new Failure(\sprintf(
4546
'Fail connect to %s with error: %s.',
46-
$connectionParameters->getDsn(),
47+
$dsn->getDsn(),
4748
\rtrim($error->getMessage(), '.')
4849
));
4950
}

src/Check/Elasticsearch/ElasticsearchIndexCheck.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use FiveLab\Component\Diagnostic\Result\Result;
1919
use FiveLab\Component\Diagnostic\Result\Success;
2020
use FiveLab\Component\Diagnostic\Util\ArrayUtils;
21+
use FiveLab\Component\Diagnostic\Util\Dsn;
2122
use FiveLab\Component\Diagnostic\Util\Http\HttpAdapter;
2223
use FiveLab\Component\Diagnostic\Util\Http\HttpAdapterInterface;
2324

@@ -35,23 +36,23 @@ class ElasticsearchIndexCheck implements CheckInterface
3536
/**
3637
* Constructor.
3738
*
38-
* @param ElasticsearchConnectionParameters $connectionParameters
39-
* @param string $index
40-
* @param array<string, mixed> $expectedSettings
41-
* @param HttpAdapterInterface|null $http
39+
* @param Dsn $dsn
40+
* @param string $index
41+
* @param array<string, mixed> $expectedSettings
42+
* @param HttpAdapterInterface|null $http
4243
*/
4344
public function __construct(
44-
private readonly ElasticsearchConnectionParameters $connectionParameters,
45-
private readonly string $index,
46-
private readonly array $expectedSettings = [],
47-
?HttpAdapterInterface $http = null
45+
private readonly Dsn $dsn,
46+
private readonly string $index,
47+
private readonly array $expectedSettings = [],
48+
?HttpAdapterInterface $http = null
4849
) {
4950
$this->http = $http ?? new HttpAdapter();
5051
}
5152

5253
public function check(): Result
5354
{
54-
$result = $this->sendRequest($this->http, $this->connectionParameters, $this->index.'/_settings');
55+
$result = $this->sendRequest($this->http, $this->dsn, $this->index.'/_settings');
5556

5657
if ($result instanceof Result) {
5758
return $result;
@@ -84,7 +85,7 @@ public function check(): Result
8485
public function getExtraParameters(): array
8586
{
8687
$parameters = [
87-
'dsn' => $this->connectionParameters->getDsn(true),
88+
'dsn' => $this->dsn->getDsn(maskedPassword: true),
8889
];
8990

9091
$actualSettings = $this->actualSettings;

src/Check/Elasticsearch/ElasticsearchTemplateCheck.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use FiveLab\Component\Diagnostic\Result\Result;
1919
use FiveLab\Component\Diagnostic\Result\Success;
2020
use FiveLab\Component\Diagnostic\Util\ArrayUtils;
21+
use FiveLab\Component\Diagnostic\Util\Dsn;
2122
use FiveLab\Component\Diagnostic\Util\Http\HttpAdapter;
2223
use FiveLab\Component\Diagnostic\Util\Http\HttpAdapterInterface;
2324

@@ -40,25 +41,25 @@ class ElasticsearchTemplateCheck implements CheckInterface
4041
/**
4142
* Constructor.
4243
*
43-
* @param ElasticsearchConnectionParameters $connectionParameters
44-
* @param string $name
45-
* @param array<string> $expectedPatterns
46-
* @param array<string, mixed> $expectedSettings
47-
* @param HttpAdapterInterface|null $http
44+
* @param Dsn $dsn
45+
* @param string $name
46+
* @param array<string> $expectedPatterns
47+
* @param array<string, mixed> $expectedSettings
48+
* @param HttpAdapterInterface|null $http
4849
*/
4950
public function __construct(
50-
private readonly ElasticsearchConnectionParameters $connectionParameters,
51-
private readonly string $name,
52-
private array $expectedPatterns = [],
53-
private readonly array $expectedSettings = [],
54-
?HttpAdapterInterface $http = null
51+
private readonly Dsn $dsn,
52+
private readonly string $name,
53+
private array $expectedPatterns = [],
54+
private readonly array $expectedSettings = [],
55+
?HttpAdapterInterface $http = null
5556
) {
5657
$this->http = $http ?? new HttpAdapter();
5758
}
5859

5960
public function check(): Result
6061
{
61-
$result = $this->sendRequest($this->http, $this->connectionParameters, '_template/'.$this->name);
62+
$result = $this->sendRequest($this->http, $this->dsn, '_template/'.$this->name);
6263

6364
if ($result instanceof Result) {
6465
return $result;
@@ -105,7 +106,7 @@ public function check(): Result
105106
public function getExtraParameters(): array
106107
{
107108
$parameters = [
108-
'dsn' => $this->connectionParameters->getDsn(true),
109+
'dsn' => $this->dsn->getDsn(maskedPassword: true),
109110
];
110111

111112
return \array_merge($parameters, [

0 commit comments

Comments
 (0)