-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract Interfaces for User Interaction Classes
The registry and the rederer are classes that are usually injected by users into their own code, having interfaces for them allow users to mock based on the API and not on the concret implementation which avoids a common code smell. This also allows better custom implementations if users so desire.
- Loading branch information
Showing
4 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
namespace Prometheus; | ||
|
||
use Prometheus\Exception\MetricNotFoundException; | ||
use Prometheus\Exception\MetricsRegistrationException; | ||
|
||
interface RegistryInterface | ||
{ | ||
/** | ||
* @return MetricFamilySamples[] | ||
*/ | ||
public function getMetricFamilySamples(); | ||
|
||
/** | ||
* @param string $namespace e.g. cms | ||
* @param string $name e.g. duration_seconds | ||
* @param string $help e.g. The duration something took in seconds. | ||
* @param array $labels e.g. ['controller', 'action'] | ||
* | ||
* @return Gauge | ||
* @throws MetricsRegistrationException | ||
*/ | ||
public function registerGauge($namespace, $name, $help, $labels = []); | ||
|
||
/** | ||
* @param string $namespace | ||
* @param string $name | ||
* | ||
* @return Gauge | ||
* @throws MetricNotFoundException | ||
*/ | ||
public function getGauge($namespace, $name); | ||
|
||
/** | ||
* @param string $namespace e.g. cms | ||
* @param string $name e.g. duration_seconds | ||
* @param string $help e.g. The duration something took in seconds. | ||
* @param array $labels e.g. ['controller', 'action'] | ||
* | ||
* @return Gauge | ||
*/ | ||
public function getOrRegisterGauge($namespace, $name, $help, $labels = []); | ||
|
||
/** | ||
* @param string $namespace e.g. cms | ||
* @param string $name e.g. requests | ||
* @param string $help e.g. The number of requests made. | ||
* @param array $labels e.g. ['controller', 'action'] | ||
* | ||
* @return Counter | ||
* @throws MetricsRegistrationException | ||
*/ | ||
public function registerCounter($namespace, $name, $help, $labels = []); | ||
|
||
/** | ||
* @param string $namespace | ||
* @param string $name | ||
* | ||
* @return Counter | ||
* @throws MetricNotFoundException | ||
*/ | ||
public function getCounter($namespace, $name); | ||
|
||
/** | ||
* @param string $namespace e.g. cms | ||
* @param string $name e.g. requests | ||
* @param string $help e.g. The number of requests made. | ||
* @param array $labels e.g. ['controller', 'action'] | ||
* | ||
* @return Counter | ||
*/ | ||
public function getOrRegisterCounter($namespace, $name, $help, $labels = []); | ||
|
||
/** | ||
* @param string $namespace e.g. cms | ||
* @param string $name e.g. duration_seconds | ||
* @param string $help e.g. A histogram of the duration in seconds. | ||
* @param array $labels e.g. ['controller', 'action'] | ||
* @param array $buckets e.g. [100, 200, 300] | ||
* | ||
* @return Histogram | ||
* @throws MetricsRegistrationException | ||
*/ | ||
public function registerHistogram($namespace, $name, $help, $labels = [], $buckets = null); | ||
|
||
/** | ||
* @param string $namespace | ||
* @param string $name | ||
* | ||
* @return Histogram | ||
* @throws MetricNotFoundException | ||
*/ | ||
public function getHistogram($namespace, $name); | ||
|
||
/** | ||
* @param string $namespace e.g. cms | ||
* @param string $name e.g. duration_seconds | ||
* @param string $help e.g. A histogram of the duration in seconds. | ||
* @param array $labels e.g. ['controller', 'action'] | ||
* @param array $buckets e.g. [100, 200, 300] | ||
* | ||
* @return Histogram | ||
*/ | ||
public function getOrRegisterHistogram($namespace, $name, $help, $labels = [], $buckets = null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Prometheus; | ||
|
||
interface RendererInterface | ||
{ | ||
/** | ||
* @param MetricFamilySamples[] $metrics | ||
* | ||
* @return string | ||
*/ | ||
public function render(array $metrics); | ||
} |