Skip to content

Commit 28b73a2

Browse files
committed
Add customizable tags parameter to health check methods
Implements issue #679: Allow users to customize tags for health checks via optional parameter. - Added optional `tags` parameter to AkkaPersistenceJournalBuilder.WithHealthCheck() - Added optional `tags` parameter to AkkaPersistenceSnapshotBuilder.WithHealthCheck() - When tags parameter is null, defaults to ["akka", "persistence", "journal"] or ["akka", "persistence", "snapshot-store"] - Consolidates previous overloads into single method with all optional parameters to avoid ambiguity - All 18 health check tests pass
1 parent 22f3949 commit 28b73a2

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/Akka.Persistence.Hosting/AkkaPersistenceHostingExtensions.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Text;
45
using Akka.Configuration;
56
using Akka.Hosting;
@@ -52,11 +53,13 @@ public AkkaPersistenceJournalBuilder(string journalId, AkkaConfigurationBuilder
5253
/// <param name="unHealthyStatus">Default status to return when the plugin reports <see cref="PersistenceHealthStatus.Unhealthy"/>
5354
/// or <see cref="PersistenceHealthStatus.Degraded"/>. Defaults to degraded.</param>
5455
/// <param name="name">Optional name to add to the health check.</param>
56+
/// <param name="tags">Optional custom tags for the health check. If null, defaults to ["akka", "persistence", "journal"].</param>
5557
/// <returns></returns>
5658
public AkkaPersistenceJournalBuilder WithHealthCheck(HealthStatus unHealthyStatus = HealthStatus.Degraded,
57-
string? name = null)
59+
string? name = null,
60+
IEnumerable<string>? tags = null)
5861
{
59-
var registration = AddHealthCheck(name, unHealthyStatus);
62+
var registration = AddHealthCheck(name, unHealthyStatus, tags);
6063
HealthCheckRegistration = registration;
6164
return this;
6265
}
@@ -96,14 +99,15 @@ private void AddAdapter<TAdapter>(string eventAdapterName, IEnumerable<Type> bou
9699
}
97100
}
98101

99-
private AkkaHealthCheckRegistration AddHealthCheck(string? name, HealthStatus unHealthyStatus)
102+
private AkkaHealthCheckRegistration AddHealthCheck(string? name, HealthStatus unHealthyStatus, IEnumerable<string>? tags = null)
100103
{
101104
var pluginId = $"akka.persistence.journal.{JournalId}";
105+
var healthCheckTags = tags?.ToList() ?? new List<string> { "akka", "persistence", "journal" };
102106
var registration = new AkkaHealthCheckRegistration(
103107
name ?? $"Akka.Persistence.Journal.{JournalId}",
104108
new JournalHealthCheck(pluginId),
105109
unHealthyStatus,
106-
["akka", "persistence", "journal"]);
110+
healthCheckTags);
107111
return registration;
108112
}
109113

src/Akka.Persistence.Hosting/SnapshotOptions.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// -----------------------------------------------------------------------
66

77
using System;
8+
using System.Collections.Generic;
9+
using System.Linq;
810
using System.Text;
911
using Akka.Configuration;
1012
using Akka.Hosting;
@@ -33,23 +35,26 @@ public AkkaPersistenceSnapshotBuilder(string snapshotStoreId, AkkaConfigurationB
3335
/// <param name="unHealthyStatus">Default status to return when the plugin reports <see cref="PersistenceHealthStatus.Unhealthy"/>
3436
/// or <see cref="PersistenceHealthStatus.Degraded"/>. Defaults to degraded.</param>
3537
/// <param name="name">Optional name to add to the health check.</param>
38+
/// <param name="tags">Optional custom tags for the health check. If null, defaults to ["akka", "persistence", "snapshot-store"].</param>
3639
/// <returns>The current builder instance for method chaining.</returns>
3740
public AkkaPersistenceSnapshotBuilder WithHealthCheck(HealthStatus unHealthyStatus = HealthStatus.Degraded,
38-
string? name = null)
41+
string? name = null,
42+
IEnumerable<string>? tags = null)
3943
{
40-
var registration = AddHealthCheck(name, unHealthyStatus);
44+
var registration = AddHealthCheck(name, unHealthyStatus, tags);
4145
HealthCheckRegistration = registration;
4246
return this;
4347
}
4448

45-
private AkkaHealthCheckRegistration AddHealthCheck(string? name, HealthStatus unHealthyStatus)
49+
private AkkaHealthCheckRegistration AddHealthCheck(string? name, HealthStatus unHealthyStatus, IEnumerable<string>? tags = null)
4650
{
4751
var pluginId = $"akka.persistence.snapshot-store.{SnapshotStoreId}";
52+
var healthCheckTags = tags?.ToList() ?? new List<string> { "akka", "persistence", "snapshot-store" };
4853
var registration = new AkkaHealthCheckRegistration(
4954
name ?? $"Akka.Persistence.SnapshotStore.{SnapshotStoreId}",
5055
new SnapshotStoreHealthCheck(pluginId),
5156
unHealthyStatus,
52-
["akka", "persistence", "snapshot-store"]);
57+
healthCheckTags);
5358
return registration;
5459
}
5560

0 commit comments

Comments
 (0)