Skip to content

Commit 35d5a68

Browse files
Add PDO storage adapter. (#157)
* PDO storage adapter - counter. Signed-off-by: Janez Urevc <janez@tag1.com> Co-authored-by: Lukas Kämmerling <github@lukas-kaemmerling.de>
1 parent ad662ee commit 35d5a68

File tree

10 files changed

+807
-1
lines changed

10 files changed

+807
-1
lines changed

.github/workflows/tests.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ jobs:
2020
REDIS_HOST: redis
2121
# The default Redis port
2222
REDIS_PORT: 6379
23+
# MySQL
24+
DB_DATABASE: test
25+
DB_USER: root
26+
DB_PASSWORD: root
27+
2328
steps:
2429
- name: Checkout code
2530
uses: actions/checkout@v2
@@ -40,9 +45,23 @@ jobs:
4045

4146
- name: Install dependencies
4247
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
48+
4349
- name: Start Redis
4450
uses: supercharge/redis-github-action@1.1.0
4551
with:
4652
redis-version: ${{ matrix.redis-version }}
47-
- name: Execute tests
53+
54+
- name: Execute tests (PDO with Sqlite)
4855
run: vendor/bin/phpunit
56+
57+
- name: Start MySQL
58+
run: |
59+
sudo /etc/init.d/mysql start
60+
mysql -e "CREATE DATABASE IF NOT EXISTS $DB_DATABASE;" -u$DB_USER -p$DB_PASSWORD
61+
62+
- name: Execute PDO tests with MySQL
63+
env:
64+
TEST_PDO_DSN: 'mysql:host=localhost;dbname=test'
65+
TEST_PDO_USERNAME: 'root'
66+
TEST_PDO_PASSWORD: 'root'
67+
run: vendor/bin/phpunit tests/Test/Prometheus/PDO

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ $registry = new CollectorRegistry(new APC());
102102
```
103103
(see the `README.APCng.md` file for more details)
104104

105+
Using the PDO storage:
106+
```php
107+
$registry = new CollectorRegistry(new \PDO('mysql:host=localhost;dbname=prometheus', 'username', 'password'));
108+
or
109+
$registry = new CollectorRegistry(new \PDO('sqlite::memory:'));
110+
```
105111

106112
### Advanced Usage
107113

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"suggest": {
3232
"ext-redis": "Required if using Redis.",
3333
"ext-apc": "Required if using APCu.",
34+
"ext-pdo": "Required if using PDO.",
3435
"promphp/prometheus_push_gateway_php": "An easy client for using Prometheus PushGateway.",
3536
"symfony/polyfill-apcu": "Required if you use APCu on PHP8.0+"
3637
},

0 commit comments

Comments
 (0)