This repository was archived by the owner on Oct 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 210
Expand file tree
/
Copy pathBlackBoxPushGatewayTest.php
More file actions
48 lines (40 loc) · 1.48 KB
/
BlackBoxPushGatewayTest.php
File metadata and controls
48 lines (40 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace Test;
use GuzzleHttp\Client;
use PHPUnit_Framework_TestCase;
use Prometheus\CollectorRegistry;
use Prometheus\PushGateway;
use Prometheus\Storage\APC;
class BlackBoxPushGatewayTest extends PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function pushGatewayShouldWork()
{
$adapter = new APC();
$registry = new CollectorRegistry($adapter);
$counter = $registry->registerCounter('test', 'some_counter', 'it increases', ['type']);
$counter->incBy(6, ['blue']);
$client = new Client(['base_uri' => 'http://pushgateway:9091/metrics/job/']);
$pushGateway = new PushGateway($client);
$pushGateway->push($registry, 'my_job', array('instance' => 'foo'));
$httpClient = new Client();
$metrics = $httpClient->get("http://pushgateway:9091/metrics")->getBody()->getContents();
$this->assertContains(
'# HELP test_some_counter it increases
# TYPE test_some_counter counter
test_some_counter{instance="foo",job="my_job",type="blue"} 6',
$metrics
);
$pushGateway->delete('my_job', array('instance' => 'foo'));
$httpClient = new Client();
$metrics = $httpClient->get("http://pushgateway:9091/metrics")->getBody()->getContents();
$this->assertNotContains(
'# HELP test_some_counter it increases
# TYPE test_some_counter counter
test_some_counter{instance="foo",job="my_job",type="blue"} 6',
$metrics
);
}
}