mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Removed the deprecated code for metric. (#5847)
This commit is contained in:
parent
67236750b2
commit
f82bc145b5
@ -35,7 +35,9 @@
|
||||
- [x] Remove deprecated codes.
|
||||
- [#5813](https://github.com/hyperf/hyperf/pull/5813) Removed support for swoole 4.x
|
||||
|
||||
## Deprecated
|
||||
## Changed
|
||||
|
||||
- [#5847](https://github.com/hyperf/hyperf/pull/5847) Changed the default redis key for metric.
|
||||
|
||||
## Fixed
|
||||
|
||||
|
@ -339,12 +339,7 @@ LUA
|
||||
|
||||
protected function toMetricKey(array $data): string
|
||||
{
|
||||
// TODO: This is a hack, we should remove it since v3.1.
|
||||
if (! str_ends_with(self::$prefix, ':')) {
|
||||
$prefix = self::$prefix . ':';
|
||||
}
|
||||
|
||||
return ($prefix ?? self::$prefix) . implode(':', [$data['type'] ?? '', $data['name'] ?? '']) . $this->getRedisTag($data['type'] ?? '');
|
||||
return self::$prefix . implode(':', [$data['type'] ?? '', $data['name'] ?? '']) . $this->getRedisTag($data['type'] ?? '');
|
||||
}
|
||||
|
||||
protected function getMetricGatherKey(string $metricType): string
|
||||
|
@ -29,8 +29,7 @@ class RedisStorageFactory
|
||||
$redisFactory = $container->get(RedisFactory::class);
|
||||
|
||||
Redis::setPrefix($config->get('metric.metric.prometheus.redis_prefix', $config->get('app_name', 'skeleton')));
|
||||
// TODO: since 3.1, default value will be changed to ':metric_keys'
|
||||
Redis::setMetricGatherKeySuffix($config->get('metric.metric.prometheus.redis_gather_key_suffix', '_METRIC_KEYS'));
|
||||
Redis::setMetricGatherKeySuffix($config->get('metric.metric.prometheus.redis_gather_key_suffix', ':metric_keys'));
|
||||
|
||||
return new Redis($redisFactory->get($config->get('metric.metric.prometheus.redis_config', 'default')));
|
||||
}
|
||||
|
@ -28,10 +28,6 @@ use ReflectionProperty;
|
||||
* @coversNothing
|
||||
*/
|
||||
#[CoversNothing]
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class RedisStorageFactoryTest extends TestCase
|
||||
{
|
||||
protected string $prePrefix;
|
||||
@ -43,7 +39,6 @@ class RedisStorageFactoryTest extends TestCase
|
||||
parent::setUp();
|
||||
|
||||
$prefixProperty = new ReflectionProperty(Redis::class, 'prefix');
|
||||
|
||||
$metricGatherKeySuffix = new ReflectionProperty(Redis::class, 'metricGatherKeySuffix');
|
||||
|
||||
$this->prePrefix = $prefixProperty->getDefaultValue();
|
||||
@ -78,7 +73,7 @@ class RedisStorageFactoryTest extends TestCase
|
||||
|
||||
self::assertInstanceOf(Redis::class, $redis);
|
||||
self::assertEquals('skeleton', $prefixProperty->getValue($redis));
|
||||
self::assertEquals('_METRIC_KEYS', $metricGatherKeySuffixProperty->getValue($redis));
|
||||
self::assertEquals(':metric_keys', $metricGatherKeySuffixProperty->getValue($redis));
|
||||
}
|
||||
|
||||
public function testNewConfig()
|
||||
@ -111,4 +106,35 @@ class RedisStorageFactoryTest extends TestCase
|
||||
self::assertEquals('prometheus:', $prefixProperty->getValue($redis));
|
||||
self::assertEquals(':metric_keys', $metricGatherKeySuffixProperty->getValue($redis));
|
||||
}
|
||||
|
||||
public function testCustomConfig()
|
||||
{
|
||||
$redisFactory = Mockery::mock(RedisFactory::class);
|
||||
$redisFactory->shouldReceive('get')->with('custom')->andReturn(Mockery::mock(RedisProxy::class));
|
||||
|
||||
$container = Mockery::mock(ContainerInterface::class);
|
||||
$container->shouldReceive('get')->with(ConfigInterface::class)->andReturn(new Config([
|
||||
'metric' => [
|
||||
'metric' => [
|
||||
'prometheus' => [
|
||||
'redis_config' => 'custom',
|
||||
'redis_prefix' => 'custom:',
|
||||
'redis_gather_key_suffix' => ':custom',
|
||||
],
|
||||
],
|
||||
],
|
||||
]));
|
||||
$container->shouldReceive('get')->with(RedisFactory::class)->andReturn($redisFactory);
|
||||
|
||||
$factory = new RedisStorageFactory();
|
||||
$redis = $factory($container);
|
||||
|
||||
$prefixProperty = new ReflectionProperty(Redis::class, 'prefix');
|
||||
|
||||
$metricGatherKeySuffixProperty = new ReflectionProperty(Redis::class, 'metricGatherKeySuffix');
|
||||
|
||||
self::assertInstanceOf(Redis::class, $redis);
|
||||
self::assertEquals('custom:', $prefixProperty->getValue($redis));
|
||||
self::assertEquals(':custom', $metricGatherKeySuffixProperty->getValue($redis));
|
||||
}
|
||||
}
|
||||
|
@ -25,10 +25,6 @@ use ReflectionProperty;
|
||||
* @coversNothing
|
||||
*/
|
||||
#[CoversNothing]
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
class RedisTest extends TestCase
|
||||
{
|
||||
protected string $prePrefix;
|
||||
@ -40,7 +36,6 @@ class RedisTest extends TestCase
|
||||
parent::setUp();
|
||||
|
||||
$prefixProperty = new ReflectionProperty(Redis::class, 'prefix');
|
||||
|
||||
$metricGatherKeySuffix = new ReflectionProperty(Redis::class, 'metricGatherKeySuffix');
|
||||
|
||||
$this->prePrefix = $prefixProperty->getDefaultValue();
|
||||
|
Loading…
Reference in New Issue
Block a user