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

Flush only metric data from Redis instead of complete server #81

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"symfony/polyfill-apcu": "^1.6"
},
"require-dev": {
"phpunit/phpunit": "4.1.0"
"phpunit/phpunit": "~5.7"
},
"suggest": {
"ext-redis": "Required if using Redis.",
Expand Down
4 changes: 2 additions & 2 deletions src/Prometheus/PushGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public function delete($job, $groupingKey = null)
}

/**
* @param CollectorRegistry $collectorRegistry
* @param CollectorRegistry|null $collectorRegistry
* @param $job
* @param $groupingKey
* @param $method
*/
private function doRequest(CollectorRegistry $collectorRegistry, $job, $groupingKey, $method)
private function doRequest(CollectorRegistry $collectorRegistry = null, $job, $groupingKey, $method)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What argument errors does this prevent? When do they occur?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running the blackbox tests, I'm getting an argument error/notice since the CollectorRegistry is expected but null is given in PushGateway::delete() method.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #82.

There was 1 error:

1) Test\BlackBoxPushGatewayTest::pushGatewayShouldWork
Argument 1 passed to Prometheus\PushGateway::doRequest() must be an instance of Prometheus\CollectorRegistry, null given, called in /var/www/html/src/Prometheus/PushGateway.php on line 54 and defined

/var/www/html/src/Prometheus/PushGateway.php:63
/var/www/html/src/Prometheus/PushGateway.php:54
/var/www/html/tests/Test/BlackBoxPushGatewayTest.php:36

{
$url = "http://" . $this->address . "/metrics/job/" . $job;
if (!empty($groupingKey)) {
Expand Down
18 changes: 17 additions & 1 deletion src/Prometheus/Storage/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,23 @@ public static function setPrefix($prefix)
public function flushRedis()
{
$this->openConnection();
$this->redis->flushAll();
$this->redis->eval(<<<LUA
for keyIndex,key in ipairs(KEYS) do
local members = redis.call('smembers', key)
for memberIndex,member in ipairs(members) do
redis.call('del', member)
end
redis.call('del', key)
end
LUA
,
array(
self::$prefix . Counter::TYPE . self::PROMETHEUS_METRIC_KEYS_SUFFIX,
self::$prefix . Gauge::TYPE . self::PROMETHEUS_METRIC_KEYS_SUFFIX,
self::$prefix . Histogram::TYPE . self::PROMETHEUS_METRIC_KEYS_SUFFIX,
),
3
);
}

/**
Expand Down