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

Update signatures for compatibility with php8. Update composer.json p… #11

Merged
merged 3 commits into from
Jan 30, 2024
Merged
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
15 changes: 15 additions & 0 deletions .docker/php/8.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM php:8.0-cli-alpine
ENV XDEBUG_VERSION 3.2.1

# Update system
RUN apk update && apk add --update linux-headers && apk add --no-cache git $PHPIZE_DEPS procps python3 \
&& pecl install xdebug-${XDEBUG_VERSION} \
&& docker-php-ext-enable xdebug

RUN python3 -m ensurepip \
&& rm -r /usr/lib/python*/ensurepip \
&& pip3 install --upgrade pip setuptools \
&& pip3 install --upgrade prometheus_client path \
&& ln -s /usr/bin/python3 /usr/bin/python
# Cleanup
RUN apk del $PHPIZE_DEPS && rm -rf /var/cache/apk/*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This implementation supports the following metric types:

* Counter
* Gauge
* Historgram (calculated from a collection of gauges)
* Histogram (calculated from a collection of gauges)
* Summary (calculated from a collection of gauges)

The library ships with a [PSR-7](https://www.php-fig.org/psr/psr-7/) compatible
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
],
"require": {
"php": ">=7.1",
"php": "^7.1 || ^8.0",
"psr/http-message": "^1.0"
},
"autoload": {
Expand Down
16 changes: 14 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ services:
- ./:/repo
working_dir: /repo

php80:
build:
dockerfile: Dockerfile
context: .docker/php/8.0
container_name: om_et_php8.0
restart: "no"
networks:
- om_et
volumes:
- ./:/repo
working_dir: /repo

composer:
build:
dockerfile: Dockerfile
Expand All @@ -63,7 +75,7 @@ services:

networks:
default:
external:
name: "gateway"
name: "gateway"
external: true
om_et:
internal: true
4 changes: 2 additions & 2 deletions src/Collections/CounterCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace OpenMetricsPhp\Exposition\Text\Collections;

use Iterator;
use OpenMetricsPhp\Exposition\Text\Interfaces\NamesMetric;
use OpenMetricsPhp\Exposition\Text\Metrics\Counter;
use Traversable;
use function count;

final class CounterCollection extends AbstractMetricCollection
Expand Down Expand Up @@ -39,7 +39,7 @@ public function count() : int
return count( $this->counters );
}

public function getMetricLines() : Iterator
public function getMetricLines() : Traversable
{
if ( 0 === $this->count() )
{
Expand Down
4 changes: 2 additions & 2 deletions src/Collections/GaugeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace OpenMetricsPhp\Exposition\Text\Collections;

use Iterator;
use OpenMetricsPhp\Exposition\Text\Interfaces\NamesMetric;
use OpenMetricsPhp\Exposition\Text\Metrics\Gauge;
use Traversable;
use function count;
use function implode;
use function iterator_to_array;
Expand Down Expand Up @@ -48,7 +48,7 @@ public function count() : int
return count( $this->gauges );
}

public function getMetricLines() : Iterator
public function getMetricLines() : Traversable
{
if ( 0 === $this->count() )
{
Expand Down
3 changes: 2 additions & 1 deletion src/Collections/LabelCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OpenMetricsPhp\Exposition\Text\Exceptions\InvalidArgumentException;
use OpenMetricsPhp\Exposition\Text\Interfaces\ProvidesNamedValue;
use OpenMetricsPhp\Exposition\Text\Types\Label;
use Traversable;
use function array_map;
use function count;
use function implode;
Expand Down Expand Up @@ -62,7 +63,7 @@ public function add( ProvidesNamedValue $label, ProvidesNamedValue ...$labels )
}
}

public function getIterator() : iterable
public function getIterator() : Traversable
{
yield from $this->labels;
}
Expand Down
4 changes: 2 additions & 2 deletions src/HttpResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace OpenMetricsPhp\Exposition\Text;

use Iterator;
use OpenMetricsPhp\Exposition\Text\HttpResponse\OutputStream;
use OpenMetricsPhp\Exposition\Text\Interfaces\ProvidesMetricLines;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use Traversable;
use function is_array;

final class HttpResponse implements ResponseInterface
Expand Down Expand Up @@ -61,7 +61,7 @@ public static function fromMetricCollections(
private static function getAllMetricLines(
ProvidesMetricLines $collection,
ProvidesMetricLines ...$collections
) : Iterator
) : Traversable
{
yield from $collection->getMetricLines();
foreach ( $collections as $loopCollection )
Expand Down
4 changes: 2 additions & 2 deletions src/Interfaces/ProvidesMetricLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace OpenMetricsPhp\Exposition\Text\Interfaces;

use Iterator;
use Traversable;

interface ProvidesMetricLines
{
public function getMetricLines() : Iterator;
public function getMetricLines() : Traversable;

public function getMetricsString() : string;
}
4 changes: 2 additions & 2 deletions src/Metrics/Histogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace OpenMetricsPhp\Exposition\Text\Metrics;

use Iterator;
use OpenMetricsPhp\Exposition\Text\Collections\GaugeCollection;
use OpenMetricsPhp\Exposition\Text\Exceptions\InvalidArgumentException;
use OpenMetricsPhp\Exposition\Text\Interfaces\NamesMetric;
Expand All @@ -12,6 +11,7 @@
use OpenMetricsPhp\Exposition\Text\Metrics\Aggregations\Sum;
use OpenMetricsPhp\Exposition\Text\Metrics\Histogram\Bucket;
use OpenMetricsPhp\Exposition\Text\Metrics\Histogram\InfiniteBucket;
use Traversable;
use function iterator_to_array;
use function sort;
use const SORT_ASC;
Expand Down Expand Up @@ -112,7 +112,7 @@ private function getHelpString() : string
return sprintf( '# HELP %s %s', $this->metricName->toString(), $this->help );
}

public function getMetricLines() : Iterator
public function getMetricLines() : Traversable
{
yield $this->getTypeString();

Expand Down
4 changes: 2 additions & 2 deletions src/Metrics/Summary.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace OpenMetricsPhp\Exposition\Text\Metrics;

use Iterator;
use OpenMetricsPhp\Exposition\Text\Collections\GaugeCollection;
use OpenMetricsPhp\Exposition\Text\Exceptions\InvalidArgumentException;
use OpenMetricsPhp\Exposition\Text\Interfaces\NamesMetric;
use OpenMetricsPhp\Exposition\Text\Interfaces\ProvidesMetricLines;
use OpenMetricsPhp\Exposition\Text\Metrics\Aggregations\Count;
use OpenMetricsPhp\Exposition\Text\Metrics\Aggregations\Sum;
use OpenMetricsPhp\Exposition\Text\Metrics\Summary\Quantile;
use Traversable;
use const SORT_ASC;
use const SORT_NUMERIC;

Expand Down Expand Up @@ -106,7 +106,7 @@ private function getHelpString() : string
return sprintf( '# HELP %s %s', $this->metricName->toString(), $this->help );
}

public function getMetricLines() : Iterator
public function getMetricLines() : Traversable
{
yield $this->getTypeString();

Expand Down
8 changes: 6 additions & 2 deletions tests/Integration/OpenMetrics/parseFile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from prometheus_client.openmetrics.parser import text_string_to_metric_families
from path import path
import sys

metrics = path(sys.argv[1]).bytes()
if sys.version_info[0] == 3:
from path import Path
metrics = Path(sys.argv[1]).bytes().decode("utf-8")
else:
from path import path
metrics = path(sys.argv[1]).bytes()

for family in text_string_to_metric_families(metrics):
for sample in family.samples:
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Types/LabelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use OpenMetricsPhp\Exposition\Text\Tests\Traits\EmptyStringProviding;
use OpenMetricsPhp\Exposition\Text\Types\Label;
use PHPUnit\Framework\TestCase;
use Traversable;

final class LabelTest extends TestCase
{
Expand Down Expand Up @@ -49,7 +50,7 @@ public function testThrowsExceptionForInvalidLabelName( string $name ) : void
$this->fail( 'Expected an InvalidArgumentException to be thrown for invalid label name.' );
}

public function invalidLabelNameProvider() : iterable
public function invalidLabelNameProvider() : Traversable
{
yield from $this->emptyStringProvider();

Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Types/MetricNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use OpenMetricsPhp\Exposition\Text\Tests\Traits\EmptyStringProviding;
use OpenMetricsPhp\Exposition\Text\Types\MetricName;
use PHPUnit\Framework\TestCase;
use Traversable;

final class MetricNameTest extends TestCase
{
Expand All @@ -30,7 +31,7 @@ public function testThrowsExceptionForInvalidMetricName( string $metricName ) :
$this->fail( 'Expected an InvalidArgumentException to be thrown for invalid metric name.' );
}

public function invalidMetricNameProvider() : iterable
public function invalidMetricNameProvider() : Traversable
{
yield from $this->emptyStringProvider();

Expand Down