Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

Prevent exception from being thrown on 200 #122

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a3d66bd
Replace PHPUnit v with PHPUnit 7
Jul 19, 2019
b2614ee
Add json extension requirement
Jul 19, 2019
1a0cc23
Add docblocks
Jul 19, 2019
f553bb1
Fix full length expected exceptions in test suite
Jul 19, 2019
c7cf01c
Merge branch 'feature/upgrade_php_unit_to_7' into develop
Jul 19, 2019
f282d4c
Add typehints, return types and all-round php 7 goodness
Jul 22, 2019
01405bc
Add missing typehints and format exception message a little nicer
Jul 22, 2019
4d33aec
Use object property value declarations instead of using declarations …
Jul 22, 2019
6a644c3
Fix weird nesting issues
Jul 22, 2019
72ca2e7
Merged in feature/upgrade_to_php_7 (pull request #1)
Jul 22, 2019
417d335
Fix autoloading with PSR-4
Jul 22, 2019
119546d
Merge branch 'hotfix/PSR-4-autoloading-src-fix'
Jul 22, 2019
66bf579
Merge branch 'hotfix/PSR-4-autoloading-src-fix' into develop
Jul 22, 2019
9c40adc
Update README.md
Jul 22, 2019
8c7fa91
Removed unused namespaces
Jul 23, 2019
8caf681
Merged in develop (pull request #2)
Jul 23, 2019
7f8c5d4
Bump version in composer and add contribution information
NoelDavies Sep 11, 2019
306bdf0
merge branch 'develop'
NoelDavies Sep 11, 2019
d56d5c4
Add exponential bucket static helper for easy generation of histogram…
NoelDavies Oct 3, 2019
bc86c72
Added exponential bucket generation explaination for histograms into …
NoelDavies Oct 3, 2019
ae9284f
Clean up import statements in histogram
NoelDavies Oct 4, 2019
ae1e172
Merge branch 'feature/add_support_for_exponential_bucket_generation' …
NoelDavies Oct 4, 2019
765fc23
bump version to 1.0.1
NoelDavies Oct 4, 2019
ae61369
Merge branch 'release/v1.0.1'
NoelDavies Oct 4, 2019
648091b
Merge branch 'master' of bitbucket.org:endclothing/prometheus_client_php
NoelDavies Oct 4, 2019
25d0076
Update php required version
NoelDavies Oct 4, 2019
15b2c2c
Merge branch 'hotfix/php_version_bump_to_7.3'
NoelDavies Oct 4, 2019
b55c01b
Update README.md
DeyV Oct 23, 2019
fdd6a3d
Update .travis.yml
DeyV Oct 23, 2019
a89283b
Merge pull request #4 from DeyV/patch-2
NoelDavies Oct 23, 2019
d8ab1d9
Merge pull request #3 from DeyV/patch-1
NoelDavies Oct 23, 2019
de702c6
Add Installation instructions
simPod Nov 5, 2019
c0ea8a3
fix(composer): add replace rule
Gounlaf Nov 5, 2019
5930a03
Fix invalid json (typo)
martinssipenko Nov 7, 2019
63966cd
Introduce Continuous Integration (#20)
martinssipenko Nov 19, 2019
4668eeb
Add support for prometheus/pushgateway:>=0.10 (#17)
kswzr Nov 19, 2019
f4c614c
Add code style check into CI pipeline (#21)
martinssipenko Nov 29, 2019
ce813f7
Inject Redis via named constructor (#8)
martinssipenko Nov 29, 2019
44cccb4
Update phpunit to version 8 (#23)
martinssipenko Nov 29, 2019
65662f5
Run CI on PHP version 7.4 (#25)
martinssipenko Nov 29, 2019
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
103 changes: 103 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
unit-config: &unit-config
environment:
COMPOSER_PREFER_LOWEST: 0
steps:
- checkout

- run:
name: Install latest composer
command: |
php -r "copy('https://raw.githubusercontent.com/composer/getcomposer.org/master/web/installer', 'composer-setup.php');"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer

- run:
name: Write COMPOSER_PREFER_LOWEST to file
command: echo "$COMPOSER_PREFER_LOWEST" > ~/COMPOSER_PREFER_LOWEST.txt

# Download and cache dependencies
- restore_cache:
keys:
- v1-composer-cache-{{ checksum "~/COMPOSER_PREFER_LOWEST.txt" }}-{{ checksum "composer.json" }}
# Fall back to using the latest cache if no exact match is found.
- v1-composer-cache-{{ checksum "~/COMPOSER_PREFER_LOWEST.txt" }}

- run:
name: Validate composer files
command: composer validate --strict

- run:
name: Install PHP extensions
command: |
printf '\n' | sudo pecl install redis
sudo docker-php-ext-enable redis

- run:
name: Install composer packages
command: |
if [ $COMPOSER_PREFER_LOWEST -eq "1" ]; then
composer update --no-ansi --no-progress --optimize-autoloader --no-interaction --no-plugins --no-scripts --prefer-dist --prefer-stable --prefer-lowest
else
composer update --no-ansi --no-progress --optimize-autoloader --no-interaction --no-plugins --no-scripts --prefer-dist --prefer-stable
fi

- save_cache:
key: v1-composer-cache-{{ checksum "~/COMPOSER_PREFER_LOWEST.txt" }}-{{ checksum "composer.json" }}
paths:
- ./vendor

- run:
name: Wait for backing services to start
command: dockerize -wait tcp://127.0.0.1:6379 -timeout 30s

- run:
name: Run PHP Code Sniffer
command: ./vendor/bin/phpcs

- run:
name: Run tests
command: ./vendor/bin/phpunit

version: 2.1
jobs:
php74:
<<: *unit-config
docker:
- image: circleci/php:7.4-cli-node
- image: circleci/redis:5-alpine
environment:
COMPOSER_PREFER_LOWEST: 0

php74-lowest:
<<: *unit-config
docker:
- image: circleci/php:7.4-cli-node
- image: circleci/redis:5-alpine
environment:
COMPOSER_PREFER_LOWEST: 1

php73:
<<: *unit-config
docker:
- image: circleci/php:7.3-cli-node
- image: circleci/redis:5-alpine
environment:
COMPOSER_PREFER_LOWEST: 0

php73-lowest:
<<: *unit-config
docker:
- image: circleci/php:7.3-cli-node
- image: circleci/redis:5-alpine
environment:
COMPOSER_PREFER_LOWEST: 1

workflows:
version: 2
units:
jobs:
- php74
- php74-lowest
- php73
- php73-lowest
12 changes: 12 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
* text=auto
/.circleci/ export-ignore
/.github/ export-ignore
/examples/ export-ignore
/nginx/ export-ignore
/php-fpm/ export-ignore
/tests/ export-ignore
.gitattributes export-ignore
.gitignore export-ignore
docker-compose.yml export-ignore
phpcs.xml.dist export-ignore
phpunit.xml.dist export-ignore
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*.iml
/.idea/
composer.lock
composer.phar
composer.phar
.phpunit.result.cache
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# A prometheus client library written in PHP

[![Build Status](https://travis-ci.org/Jimdo/prometheus_client_php.svg?branch=master)](https://travis-ci.org/Jimdo/prometheus_client_php)
[![CircleCI](https://circleci.com/gh/endclothing/prometheus_client_php/tree/master.svg?style=shield)](https://circleci.com/gh/endclothing/prometheus_client_php/tree/master)

This library uses Redis or APCu to do the client side aggregation.
If using Redis, we recommend to run a local Redis instance next to your PHP workers.
Expand All @@ -12,6 +12,14 @@ You can pick from three adapters.
Redis, APC or an in memory adapter.
While the first needs a separate binary running, the second just needs the [APC](https://pecl.php.net/package/APCU) extension to be installed. If you don't need persistent metrics between requests (e.g. a long running cron job or script) the in memory adapter might be suitable to use.

## Installation

Add as [Composer](https://getcomposer.org/) dependency:

```sh
composer require endclothing/prometheus_client_php
```

## Usage

A simple counter:
Expand Down Expand Up @@ -83,13 +91,27 @@ $renderer = new RenderTextFormat();
$result = $renderer->render($registry->getMetricFamilySamples());
```

### Advanced Usage

#### Advanced Histogram Usage
On passing an empty array for the bucket parameter on instantiation, a set of default buckets will be used instead.
Whilst this is a good base for a typical web application, there is named constructor to assist in the generation of
exponential / geometric buckets.

Eg:
```
Histogram::exponentialBuckets(0.05, 1.5, 10);
```

This will start your buckets with a value of 1.5, grow them by a factor of 1.5 per bucket across a set of 10 buckets.

Also look at the [examples](examples).

## Development

### Dependencies

* PHP 5.6
* PHP ^7.3
* PHP Redis extension
* PHP APCu extension
* [Composer](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx)
Expand Down
38 changes: 25 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
{
"name": "jimdo/prometheus_client_php",
"name": "endclothing/prometheus_client_php",
"description": "Prometheus instrumentation library for PHP applications.",
"type": "library",
"license": "Apache-2.0",
"authors": [
{
"name": "Joscha",
"email": "[email protected]"
},
{
"name": "Jan Brauer",
"email": "[email protected]"
"name": "Daniel Noel-Davies",
"email": "[email protected]"
}
],
"replace": {
"jimdo/prometheus_client_php": "*"
},
"require": {
"php": ">=5.6.3",
"guzzlehttp/guzzle": "^6.2",
"php": "^7.3",
"ext-json": "*",
"guzzlehttp/guzzle": "^6.3",
"symfony/polyfill-apcu": "^1.6"
},
"require-dev": {
"phpunit/phpunit": "4.1.0"
"phpunit/phpunit": "^8.4",
"squizlabs/php_codesniffer": "^3.5"
},
"suggest": {
"ext-redis": "Required if using Redis.",
"ext-apc": "Required if using APCu."
},
"autoload": {
"psr-0": {
"Prometheus\\": "src/"
"psr-4": {
"Prometheus\\": "src/Prometheus/"
}
},
"autoload-dev": {
"psr-0": {
"Test\\Prometheus\\": "tests/"
}
},
"license": "Apache-2.0"
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"config": {
"sort-packages": true
},
"prefer-stable": true
}
6 changes: 3 additions & 3 deletions examples/flush_adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
$adapter = $_GET['adapter'];

if ($adapter === 'redis') {
define('REDIS_HOST', isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1');
define('REDIS_HOST', $_SERVER['REDIS_HOST'] ?? '127.0.0.1');

$redisAdapter = new Prometheus\Storage\Redis(array('host' => REDIS_HOST));
$redisAdapter = new Prometheus\Storage\Redis(['host' => REDIS_HOST]);
$redisAdapter->flushRedis();
} elseif ($adapter === 'apc') {
$apcAdapter = new Prometheus\Storage\APC();
$apcAdapter->flushAPC();
} elseif ($adapter === 'in-memory') {
$inMemoryAdapter = new Prometheus\Storage\InMemory();
$inMemoryAdapter->flushMemory();
}
}
2 changes: 1 addition & 1 deletion examples/metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
$adapter = $_GET['adapter'];

if ($adapter === 'redis') {
Redis::setDefaultOptions(array('host' => isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1'));
Redis::setDefaultOptions(['host' => $_SERVER['REDIS_HOST'] ?? '127.0.0.1']);
$adapter = new Prometheus\Storage\Redis();
} elseif ($adapter === 'apc') {
$adapter = new Prometheus\Storage\APC();
Expand Down
7 changes: 4 additions & 3 deletions examples/pushgateway.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?php
require __DIR__ . '/../vendor/autoload.php';

use Prometheus\PushGateway;
use Prometheus\Storage\Redis;
use Prometheus\CollectorRegistry;

$adapter = $_GET['adapter'];

if ($adapter === 'redis') {
Redis::setDefaultOptions(array('host' => isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1'));
Redis::setDefaultOptions(['host' => $_SERVER['REDIS_HOST'] ?? '127.0.0.1']);
$adapter = new Prometheus\Storage\Redis();
} elseif ($adapter === 'apc') {
$adapter = new Prometheus\Storage\APC();
Expand All @@ -20,5 +21,5 @@
$counter = $registry->registerCounter('test', 'some_counter', 'it increases', ['type']);
$counter->incBy(6, ['blue']);

$pushGateway = new \Prometheus\PushGateway('192.168.59.100:9091');
$pushGateway->push($registry, 'my_job', array('instance'=>'foo'));
$pushGateway = new PushGateway('192.168.59.100:9091');
$pushGateway->push($registry, 'my_job', ['instance' => 'foo']);
2 changes: 1 addition & 1 deletion examples/some_counter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
$adapter = $_GET['adapter'];

if ($adapter === 'redis') {
Redis::setDefaultOptions(array('host' => isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1'));
Redis::setDefaultOptions(['host' => $_SERVER['REDIS_HOST'] ?? '127.0.0.1']);
$adapter = new Prometheus\Storage\Redis();
} elseif ($adapter === 'apc') {
$adapter = new Prometheus\Storage\APC();
Expand Down
4 changes: 2 additions & 2 deletions examples/some_gauge.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
use Prometheus\Storage\Redis;


error_log('c='. $_GET['c']);
error_log('c=' . $_GET['c']);

$adapter = $_GET['adapter'];

if ($adapter === 'redis') {
Redis::setDefaultOptions(array('host' => isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1'));
Redis::setDefaultOptions(['host' => $_SERVER['REDIS_HOST'] ?? '127.0.0.1']);
$adapter = new Prometheus\Storage\Redis();
} elseif ($adapter === 'apc') {
$adapter = new Prometheus\Storage\APC();
Expand Down
4 changes: 2 additions & 2 deletions examples/some_histogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
use Prometheus\CollectorRegistry;
use Prometheus\Storage\Redis;

error_log('c='. $_GET['c']);
error_log('c=' . $_GET['c']);

$adapter = $_GET['adapter'];

if ($adapter === 'redis') {
Redis::setDefaultOptions(array('host' => isset($_SERVER['REDIS_HOST']) ? $_SERVER['REDIS_HOST'] : '127.0.0.1'));
Redis::setDefaultOptions(['host' => $_SERVER['REDIS_HOST'] ?? '127.0.0.1']);
$adapter = new Prometheus\Storage\Redis();
} elseif ($adapter === 'apc') {
$adapter = new Prometheus\Storage\APC();
Expand Down
12 changes: 12 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<ruleset name="PHP_CodeSniffer">
<file>src/</file>
<file>tests/</file>
<file>examples/</file>

<exclude-pattern type="relative">vendor/*</exclude-pattern>

<arg value="nps"/>

<rule ref="PSR12"/>
</ruleset>
7 changes: 0 additions & 7 deletions phpunit.xml

This file was deleted.

24 changes: 24 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false">

<testsuites>
<testsuite name="Unit">
<directory>./tests/Test/Prometheus</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/Prometheus</directory>
</whitelist>
</filter>
</phpunit>
Loading