From c00f1a52209422ebc732a18ea1970bf0738566c7 Mon Sep 17 00:00:00 2001 From: Marcel Berteler Date: Tue, 19 Mar 2024 07:00:54 +0200 Subject: [PATCH 01/13] Added wipeKey to RedisNg --- src/Prometheus/Storage/RedisNg.php | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/Prometheus/Storage/RedisNg.php b/src/Prometheus/Storage/RedisNg.php index cb369ba7..307604b6 100644 --- a/src/Prometheus/Storage/RedisNg.php +++ b/src/Prometheus/Storage/RedisNg.php @@ -139,6 +139,43 @@ public function wipeStorage(): void ); } + /** + * @inheritDoc + */ + public function wipeKey(string $type, string $key) + { + $this->ensureOpenConnection(); + + $searchPattern = ""; + + $globalPrefix = $this->redis->getOption(\Redis::OPT_PREFIX); + // @phpstan-ignore-next-line false positive, phpstan thinks getOptions returns int + if (is_string($globalPrefix)) { + $searchPattern .= $globalPrefix; + } + + $searchPattern .= self::$prefix; + $searchPattern .= ":" . $type . ":" . $key; + + $this->redis->eval( + << Date: Tue, 19 Mar 2024 07:03:53 +0200 Subject: [PATCH 02/13] Added wipeKey to Redis --- src/Prometheus/Storage/Redis.php | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/Prometheus/Storage/Redis.php b/src/Prometheus/Storage/Redis.php index 122d11a3..bc7acbc0 100644 --- a/src/Prometheus/Storage/Redis.php +++ b/src/Prometheus/Storage/Redis.php @@ -139,6 +139,42 @@ public function wipeStorage(): void ); } + /** + * @inheritDoc + */ + public function wipeKey(string $type, string $key) + { + $this->ensureOpenConnection(); + + $searchPattern = ""; + + $globalPrefix = $this->redis->getOption(\Redis::OPT_PREFIX); + // @phpstan-ignore-next-line false positive, phpstan thinks getOptions returns int + if (is_string($globalPrefix)) { + $searchPattern .= $globalPrefix; + } + + $searchPattern .= self::$prefix; + $searchPattern .= ":" . $type . ":" . $key; + + $this->redis->eval( + << Date: Tue, 19 Mar 2024 07:06:31 +0200 Subject: [PATCH 03/13] Added wipeKey to storage adapter interface --- src/Prometheus/Storage/Adapter.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Prometheus/Storage/Adapter.php b/src/Prometheus/Storage/Adapter.php index fc39dd81..750f79e3 100644 --- a/src/Prometheus/Storage/Adapter.php +++ b/src/Prometheus/Storage/Adapter.php @@ -49,4 +49,14 @@ public function updateCounter(array $data): void; * @return void */ public function wipeStorage(): void; + + /** + * Removes a specific previously stored metric from underlying storage + * + * @param string $type + * @param string $key + * @throws StorageException + * @return void + */ + public function wipeKey(): void; } From ee1fa39895a901da29d69283318a52e4834db9ae Mon Sep 17 00:00:00 2001 From: Marcel Berteler Date: Tue, 19 Mar 2024 07:10:16 +0200 Subject: [PATCH 04/13] Added wipeKey placeholder to InMemory --- src/Prometheus/Storage/InMemory.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Prometheus/Storage/InMemory.php b/src/Prometheus/Storage/InMemory.php index a79714c7..ae43f8ff 100644 --- a/src/Prometheus/Storage/InMemory.php +++ b/src/Prometheus/Storage/InMemory.php @@ -61,6 +61,14 @@ public function wipeStorage(): void $this->summaries = []; } + /** + * @inheritDoc + */ + public function wipeKey(string $type, string $key): void + { + // not implemented yet + } + /** * @return MetricFamilySamples[] */ From a227b0ce3af1089199fc8d8d910e95f8daaac382 Mon Sep 17 00:00:00 2001 From: Marcel Berteler Date: Tue, 19 Mar 2024 07:11:38 +0200 Subject: [PATCH 05/13] Added wikeKep placeholder to APCng --- src/Prometheus/Storage/APCng.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Prometheus/Storage/APCng.php b/src/Prometheus/Storage/APCng.php index 5448fc95..6ba10369 100644 --- a/src/Prometheus/Storage/APCng.php +++ b/src/Prometheus/Storage/APCng.php @@ -303,6 +303,14 @@ public function wipeStorage(): void apcu_delete($this->metainfoCacheKey); } + /** + * @inheritDoc + */ + public function wipeKey(string $type, string $key): void + { + // not implemented yet + } + /** * Scans the APCu keyspace for all metainfo keys. A new metainfo cache array is built, * which references all metadata keys in APCu at that moment. This prevents a corner-case From 6413e88dbeca50f2473e0644f1dae98ac67ebe23 Mon Sep 17 00:00:00 2001 From: Marcel Berteler Date: Tue, 19 Mar 2024 07:12:20 +0200 Subject: [PATCH 06/13] Added wipeKey placeholder to APC --- src/Prometheus/Storage/APC.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Prometheus/Storage/APC.php b/src/Prometheus/Storage/APC.php index 5f747231..0cf02428 100644 --- a/src/Prometheus/Storage/APC.php +++ b/src/Prometheus/Storage/APC.php @@ -230,6 +230,14 @@ public function wipeStorage(): void } } + /** + * @inheritDoc + */ + public function wipeKey(string $type, string $key): void + { + // not implemented yet + } + /** * @param mixed[] $data * @return string From 624f15d0ca4503d45c1c11431b13a6ef9d1ae004 Mon Sep 17 00:00:00 2001 From: Marcel Berteler Date: Tue, 19 Mar 2024 07:15:29 +0200 Subject: [PATCH 07/13] Added wipeKey to CollectorRegistry --- src/Prometheus/CollectorRegistry.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Prometheus/CollectorRegistry.php b/src/Prometheus/CollectorRegistry.php index 8395c53e..4ab0d6cb 100644 --- a/src/Prometheus/CollectorRegistry.php +++ b/src/Prometheus/CollectorRegistry.php @@ -78,6 +78,18 @@ public function wipeStorage(): void $this->storageAdapter->wipeStorage(); } + /** + * Removes a specific previously stored metric from underlying storage adapter + * + * @param string $type + * @param string $name + * @return void + */ + public function wipeKey(string $type, string $name): void + { + $this->storageAdapter->wipeKey($type, $name); + } + /** * @return MetricFamilySamples[] */ From f13897b3122e002afad9f3c16a0d825da7d5857f Mon Sep 17 00:00:00 2001 From: Marcel Berteler Date: Tue, 19 Mar 2024 07:16:32 +0200 Subject: [PATCH 08/13] Added wikeKey to RegistryInterface --- src/Prometheus/RegistryInterface.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Prometheus/RegistryInterface.php b/src/Prometheus/RegistryInterface.php index a66ae5e6..5f94ac94 100644 --- a/src/Prometheus/RegistryInterface.php +++ b/src/Prometheus/RegistryInterface.php @@ -14,6 +14,15 @@ interface RegistryInterface */ public function wipeStorage(): void; + /** + * Removes a specific previously stored metric from underlying storage adapter + * + * @param string $type + * @param string $name + * @return void + */ + public function wipeKey(string $type, string $name): void; + /** * @return MetricFamilySamples[] */ From 1a7b1d433d0445373dd989c95d12257519088a89 Mon Sep 17 00:00:00 2001 From: Marcel Berteler Date: Tue, 19 Mar 2024 07:17:14 +0200 Subject: [PATCH 09/13] cleanup comments in RegistryInterface --- src/Prometheus/RegistryInterface.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Prometheus/RegistryInterface.php b/src/Prometheus/RegistryInterface.php index 5f94ac94..9bbf9ef6 100644 --- a/src/Prometheus/RegistryInterface.php +++ b/src/Prometheus/RegistryInterface.php @@ -19,6 +19,7 @@ public function wipeStorage(): void; * * @param string $type * @param string $name + * * @return void */ public function wipeKey(string $type, string $name): void; From 5a4a362440c2b0ee0b74ac83789e9459d5ea2dae Mon Sep 17 00:00:00 2001 From: Marcel Berteler Date: Tue, 19 Mar 2024 07:17:55 +0200 Subject: [PATCH 10/13] Cleanup comments in CollectorRegistry --- src/Prometheus/CollectorRegistry.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Prometheus/CollectorRegistry.php b/src/Prometheus/CollectorRegistry.php index 4ab0d6cb..37412a7e 100644 --- a/src/Prometheus/CollectorRegistry.php +++ b/src/Prometheus/CollectorRegistry.php @@ -83,6 +83,7 @@ public function wipeStorage(): void * * @param string $type * @param string $name + * * @return void */ public function wipeKey(string $type, string $name): void From a3fbda8283fb683e613edf019bbd2e91be6fea13 Mon Sep 17 00:00:00 2001 From: Marcel Berteler Date: Tue, 19 Mar 2024 07:19:05 +0200 Subject: [PATCH 11/13] Add return type to wipeKey in RedisNg --- src/Prometheus/Storage/RedisNg.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Prometheus/Storage/RedisNg.php b/src/Prometheus/Storage/RedisNg.php index 307604b6..a1c9336a 100644 --- a/src/Prometheus/Storage/RedisNg.php +++ b/src/Prometheus/Storage/RedisNg.php @@ -142,7 +142,7 @@ public function wipeStorage(): void /** * @inheritDoc */ - public function wipeKey(string $type, string $key) + public function wipeKey(string $type, string $key): void { $this->ensureOpenConnection(); From 8b9531c5690ad643abbca6da7d0ee31ab4f35d2d Mon Sep 17 00:00:00 2001 From: Marcel Berteler Date: Tue, 19 Mar 2024 07:19:33 +0200 Subject: [PATCH 12/13] Add return type to wipeKey in Redis --- src/Prometheus/Storage/Redis.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Prometheus/Storage/Redis.php b/src/Prometheus/Storage/Redis.php index bc7acbc0..686c170a 100644 --- a/src/Prometheus/Storage/Redis.php +++ b/src/Prometheus/Storage/Redis.php @@ -142,7 +142,7 @@ public function wipeStorage(): void /** * @inheritDoc */ - public function wipeKey(string $type, string $key) + public function wipeKey(string $type, string $key): void { $this->ensureOpenConnection(); From bbd79e1a2408f29d7d39f97295d02f792a1e2460 Mon Sep 17 00:00:00 2001 From: Marcel Berteler Date: Tue, 4 Jun 2024 12:50:49 +0200 Subject: [PATCH 13/13] Update Adapter.php Correct adapter --- src/Prometheus/Storage/Adapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Prometheus/Storage/Adapter.php b/src/Prometheus/Storage/Adapter.php index 750f79e3..bbc1c8d4 100644 --- a/src/Prometheus/Storage/Adapter.php +++ b/src/Prometheus/Storage/Adapter.php @@ -58,5 +58,5 @@ public function wipeStorage(): void; * @throws StorageException * @return void */ - public function wipeKey(): void; + public function wipeKey(string $type, string $key): void; }