add unit tests
This commit is contained in:
parent
00cb369d0b
commit
9c2453f0e4
8 changed files with 508 additions and 22 deletions
|
@ -2,24 +2,48 @@
|
|||
|
||||
namespace Superbalist\LaravelPrometheusExporter;
|
||||
|
||||
use Illuminate\Contracts\Routing\ResponseFactory;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Prometheus\RenderTextFormat;
|
||||
|
||||
class MetricsController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var ResponseFactory
|
||||
*/
|
||||
protected $responseFactory;
|
||||
|
||||
/**
|
||||
* @var $prometheusExporter
|
||||
*/
|
||||
protected $prometheusExporter;
|
||||
|
||||
/**
|
||||
* @param ResponseFactory $responseFactory
|
||||
* @param PrometheusExporter $prometheusExporter
|
||||
*/
|
||||
public function __construct(PrometheusExporter $prometheusExporter)
|
||||
public function __construct(ResponseFactory $responseFactory, PrometheusExporter $prometheusExporter)
|
||||
{
|
||||
$this->responseFactory = $responseFactory;
|
||||
$this->prometheusExporter = $prometheusExporter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ResponseFactory
|
||||
*/
|
||||
public function getResponseFactory()
|
||||
{
|
||||
return $this->responseFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PrometheusExporter
|
||||
*/
|
||||
public function getPrometheusExporter()
|
||||
{
|
||||
return $this->prometheusExporter;
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /metrics
|
||||
*
|
||||
|
@ -35,7 +59,6 @@ class MetricsController extends Controller
|
|||
$renderer = new RenderTextFormat();
|
||||
$result = $renderer->render($metrics);
|
||||
|
||||
return response($result)
|
||||
->header('Content-Type', RenderTextFormat::MIME_TYPE);
|
||||
return $this->responseFactory->make($result, 200, ['Content-Type' => RenderTextFormat::MIME_TYPE]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,7 +160,7 @@ class PrometheusExporter
|
|||
*/
|
||||
public function getGauge($name)
|
||||
{
|
||||
return $this->prometheus->getCounter($this->namespace, $name);
|
||||
return $this->prometheus->getGauge($this->namespace, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,8 +42,8 @@ class PrometheusServiceProvider extends ServiceProvider
|
|||
});
|
||||
$this->app->alias(PrometheusExporter::class, 'prometheus');
|
||||
|
||||
$this->app->bind('prometheus.storage_adapter_factory', function ($app) {
|
||||
return new StorageAdapterFactory($app);
|
||||
$this->app->bind('prometheus.storage_adapter_factory', function () {
|
||||
return new StorageAdapterFactory();
|
||||
});
|
||||
|
||||
$this->app->bind(Adapter::class, function ($app) {
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Superbalist\LaravelPrometheusExporter;
|
||||
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use InvalidArgumentException;
|
||||
use Prometheus\Storage\Adapter;
|
||||
use Prometheus\Storage\APC;
|
||||
|
@ -11,19 +10,6 @@ use Prometheus\Storage\Redis;
|
|||
|
||||
class StorageAdapterFactory
|
||||
{
|
||||
/**
|
||||
* @var Container
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @param Container $container
|
||||
*/
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory a storage adapter.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue