Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PostgreSQL support and fix some type hints and docBlock types errors #161

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/blackbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ jobs:
run: composer install --prefer-dist --no-interaction --no-suggest

- name: Compose Blackbox environment
run: docker-compose up -d
run: docker compose up -d
- name: Run Blackbox with APC
run: docker-compose run phpunit env ADAPTER=apc vendor/bin/phpunit tests/Test/
run: docker compose run phpunit env ADAPTER=apc vendor/bin/phpunit tests/Test/
- name: Run Blackbox with APCng
run: docker-compose run phpunit env ADAPTER=apcng vendor/bin/phpunit tests/Test/
run: docker compose run phpunit env ADAPTER=apcng vendor/bin/phpunit tests/Test/
- name: Run Blackbox with Redis
run: docker-compose run phpunit env ADAPTER=redis vendor/bin/phpunit tests/Test/
run: docker compose run phpunit env ADAPTER=redis vendor/bin/phpunit tests/Test/



21 changes: 20 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ jobs:
REDIS_HOST: redis
# The default Redis port
REDIS_PORT: 6379
# MySQL
DB_DATABASE: test
DB_USER: root
DB_PASSWORD: root

steps:
- name: Checkout code
uses: actions/checkout@v2
Expand All @@ -40,9 +45,23 @@ jobs:

- name: Install dependencies
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest

- name: Start Redis
uses: supercharge/[email protected]
with:
redis-version: ${{ matrix.redis-version }}
- name: Execute tests

- name: Execute tests (PDO with Sqlite)
run: vendor/bin/phpunit

- name: Start MySQL
run: |
sudo /etc/init.d/mysql start
mysql -e "CREATE DATABASE IF NOT EXISTS $DB_DATABASE;" -u$DB_USER -p$DB_PASSWORD

- name: Execute PDO tests with MySQL
env:
TEST_PDO_DSN: 'mysql:host=localhost;dbname=test'
TEST_PDO_USERNAME: 'root'
TEST_PDO_PASSWORD: 'root'
run: vendor/bin/phpunit tests/Test/Prometheus/PDO
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ $registry = new CollectorRegistry(new APC());
```
(see the `README.APCng.md` file for more details)

Using the PDO storage:
```php
$registry = new CollectorRegistry(new \PDO('mysql:host=localhost;dbname=prometheus', 'username', 'password'));
or
$registry = new CollectorRegistry(new \PDO('sqlite::memory:'));
```

### Advanced Usage

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"suggest": {
"ext-redis": "Required if using Redis.",
"ext-apc": "Required if using APCu.",
"ext-pdo": "Required if using PDO.",
"promphp/prometheus_push_gateway_php": "An easy client for using Prometheus PushGateway.",
"symfony/polyfill-apcu": "Required if you use APCu on PHP8.0+"
},
Expand Down
20 changes: 10 additions & 10 deletions src/Prometheus/CollectorRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function getMetricFamilySamples(bool $sortMetrics = true): array
* @return Gauge
* @throws MetricsRegistrationException
*/
public function registerGauge(string $namespace, string $name, string $help, $labels = []): Gauge
public function registerGauge(string $namespace, string $name, string $help, array $labels = []): Gauge
{
$metricIdentifier = self::metricIdentifier($namespace, $name);
if (isset($this->gauges[$metricIdentifier])) {
Expand Down Expand Up @@ -136,7 +136,7 @@ public function getGauge(string $namespace, string $name): Gauge
* @return Gauge
* @throws MetricsRegistrationException
*/
public function getOrRegisterGauge(string $namespace, string $name, string $help, $labels = []): Gauge
public function getOrRegisterGauge(string $namespace, string $name, string $help, array $labels = []): Gauge
{
try {
$gauge = $this->getGauge($namespace, $name);
Expand All @@ -155,7 +155,7 @@ public function getOrRegisterGauge(string $namespace, string $name, string $help
* @return Counter
* @throws MetricsRegistrationException
*/
public function registerCounter(string $namespace, string $name, string $help, $labels = []): Counter
public function registerCounter(string $namespace, string $name, string $help, array $labels = []): Counter
{
$metricIdentifier = self::metricIdentifier($namespace, $name);
if (isset($this->counters[$metricIdentifier])) {
Expand Down Expand Up @@ -196,7 +196,7 @@ public function getCounter(string $namespace, string $name): Counter
* @return Counter
* @throws MetricsRegistrationException
*/
public function getOrRegisterCounter(string $namespace, string $name, string $help, $labels = []): Counter
public function getOrRegisterCounter(string $namespace, string $name, string $help, array $labels = []): Counter
{
try {
$counter = $this->getCounter($namespace, $name);
Expand All @@ -211,7 +211,7 @@ public function getOrRegisterCounter(string $namespace, string $name, string $he
* @param string $name e.g. duration_seconds
* @param string $help e.g. A histogram of the duration in seconds.
* @param string[] $labels e.g. ['controller', 'action']
* @param mixed[]|null $buckets e.g. [100, 200, 300]
* @param float[]|null $buckets e.g. [100.0, 200.0, 300.0]
*
* @return Histogram
* @throws MetricsRegistrationException
Expand All @@ -221,7 +221,7 @@ public function registerHistogram(
string $name,
string $help,
array $labels = [],
array $buckets = null
?array $buckets = null
): Histogram {
$metricIdentifier = self::metricIdentifier($namespace, $name);
if (isset($this->histograms[$metricIdentifier])) {
Expand Down Expand Up @@ -259,7 +259,7 @@ public function getHistogram(string $namespace, string $name): Histogram
* @param string $name e.g. duration_seconds
* @param string $help e.g. A histogram of the duration in seconds.
* @param string[] $labels e.g. ['controller', 'action']
* @param float[]|null $buckets e.g. [100, 200, 300]
* @param float[]|null $buckets e.g. [100.0, 200.0, 300.0]
*
* @return Histogram
* @throws MetricsRegistrationException
Expand All @@ -269,7 +269,7 @@ public function getOrRegisterHistogram(
string $name,
string $help,
array $labels = [],
array $buckets = null
?array $buckets = null
): Histogram {
try {
$histogram = $this->getHistogram($namespace, $name);
Expand Down Expand Up @@ -297,7 +297,7 @@ public function registerSummary(
string $help,
array $labels = [],
int $maxAgeSeconds = 600,
array $quantiles = null
?array $quantiles = null
): Summary {
$metricIdentifier = self::metricIdentifier($namespace, $name);
if (isset($this->summaries[$metricIdentifier])) {
Expand Down Expand Up @@ -348,7 +348,7 @@ public function getOrRegisterSummary(
string $help,
array $labels = [],
int $maxAgeSeconds = 600,
array $quantiles = null
?array $quantiles = null
): Summary {
try {
$summary = $this->getSummary($namespace, $name);
Expand Down
2 changes: 1 addition & 1 deletion src/Prometheus/Counter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function inc(array $labels = []): void

/**
* @param int|float $count e.g. 2
* @param mixed[] $labels e.g. ['status', 'opcode']
* @param string[] $labels e.g. ['status', 'opcode']
*/
public function incBy($count, array $labels = []): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Prometheus/Gauge.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Gauge extends Collector
const TYPE = 'gauge';

/**
* @param double $value e.g. 123
* @param float $value e.g. 123.0
* @param string[] $labels e.g. ['status', 'opcode']
*/
public function set(float $value, array $labels = []): void
Expand Down
4 changes: 2 additions & 2 deletions src/Prometheus/Histogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(
string $name,
string $help,
array $labels = [],
array $buckets = null
?array $buckets = null
) {
parent::__construct($adapter, $namespace, $name, $help, $labels);

Expand Down Expand Up @@ -113,7 +113,7 @@ public static function exponentialBuckets(float $start, float $growthFactor, int
}

/**
* @param double $value e.g. 123
* @param float $value e.g. 123.0
* @param string[] $labels e.g. ['status', 'opcode']
*/
public function observe(float $value, array $labels = []): void
Expand Down
Loading