Skip to content

Commit

Permalink
Fix missing Discovery.Azure IExtension (#2653)
Browse files Browse the repository at this point in the history
* Fix missing Discovery.Azure IExtension

* Cleanup code

---------

Co-authored-by: Aaron Stannard <[email protected]>
  • Loading branch information
Arkatufus and Aaronontheweb authored Jul 15, 2024
1 parent 1de7cb2 commit ff66309
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ public class AzureDiscoverySettingsSpecs
[Fact(DisplayName = "Default settings should contain default values")]
public void DefaultSettingsTest()
{
var settings = AzureDiscoverySettings.Create(AzureServiceDiscovery.DefaultConfig);
var settings = AzureDiscoverySettings.Create(AzureDiscovery.DefaultConfiguration());

var assemblyName = typeof(AzureServiceDiscovery).Assembly.FullName!.Split(',')[0].Trim();
var config = AzureServiceDiscovery.DefaultConfig.GetConfig("akka.discovery.azure");
var config = AzureDiscovery.DefaultConfiguration().GetConfig(AzureServiceDiscovery.DefaultConfigPath);
config.GetString("class").Should().Be($"{typeof(AzureServiceDiscovery).Namespace}.{nameof(AzureServiceDiscovery)}, {assemblyName}");

settings.ReadOnly.Should().BeFalse();
Expand All @@ -44,7 +44,7 @@ public void DefaultSettingsTest()
[Fact(DisplayName = "Empty settings variable and default settings should match")]
public void EmptySettingsTest()
{
var settings = AzureDiscoverySettings.Create(AzureServiceDiscovery.DefaultConfig);
var settings = AzureDiscoverySettings.Create(AzureDiscovery.DefaultConfiguration());
var empty = AzureDiscoverySettings.Empty;

empty.ReadOnly.Should().Be(settings.ReadOnly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void Apply(AkkaConfigurationBuilder builder, Setup? inputSetup = null)

builder.AddHocon(sb.ToString(), HoconAddMode.Prepend);

var fallback = AzureServiceDiscovery.DefaultConfig
var fallback = AzureDiscovery.DefaultConfiguration()
.GetConfig(AzureServiceDiscovery.FullPath(AzureServiceDiscovery.DefaultPath))
.MoveTo(AzureServiceDiscovery.FullPath(ConfigPath));
builder.AddHocon(fallback, HoconAddMode.Append);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,12 @@ public static AkkaConfigurationBuilder WithAzureDiscovery(
AkkaDiscoveryOptions options)
{
options.Apply(builder);

builder.AddHocon(AzureServiceDiscovery.DefaultConfig, HoconAddMode.Append);

// force start the module
builder.AddStartup((system, registry) =>
{
AzureDiscovery.Get(system);
});
return builder;
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/discovery/azure/Akka.Discovery.Azure/AzureDiscovery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Akka.Actor;
using Akka.Configuration;

namespace Akka.Discovery.Azure;

public class AzureDiscovery: IExtension
{
public static Configuration.Config DefaultConfiguration()
=> ConfigurationFactory.FromResource<AzureDiscovery>("Akka.Discovery.Azure.reference.conf");

public static AzureDiscovery Get(ActorSystem system)
=> system.WithExtension<AzureDiscovery, AzureDiscoveryProvider>();

public readonly AzureDiscoverySettings Settings;

public AzureDiscovery(ExtendedActorSystem system)
{
system.Settings.InjectTopLevelFallback(DefaultConfiguration());
Settings = AzureDiscoverySettings.Create(system);

var setup = system.Settings.Setup.Get<AzureDiscoverySetup>();
if (setup.HasValue)
Settings = setup.Value.Apply(Settings);
}
}

public class AzureDiscoveryProvider : ExtensionIdProvider<AzureDiscovery>
{
public override AzureDiscovery CreateExtension(ExtendedActorSystem system)
=> new AzureDiscovery(system);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public class AzureServiceDiscovery : ServiceDiscovery
internal const string DefaultPath = "azure";
internal const string DefaultConfigPath = "akka.discovery." + DefaultPath;
internal static string FullPath(string path) => $"akka.discovery.{path}";
public static readonly Configuration.Config DefaultConfig =
ConfigurationFactory.FromResource<AzureServiceDiscovery>("Akka.Discovery.Azure.reference.conf");

private readonly ILoggingAdapter _log;
private readonly ExtendedActorSystem _system;
Expand All @@ -42,7 +40,7 @@ public AzureServiceDiscovery(ExtendedActorSystem system, Configuration.Config co
_system = system;
_log = Logging.GetLogger(system, typeof(AzureServiceDiscovery));

var fullConfig = config.WithFallback(DefaultConfig.GetConfig(DefaultConfigPath));
var fullConfig = config.WithFallback(AzureDiscovery.DefaultConfiguration().GetConfig(DefaultConfigPath));
_settings = AzureDiscoverySettings.Create(system, fullConfig);

var setup = _system.Settings.Setup.Get<AzureDiscoverySetup>();
Expand Down

0 comments on commit ff66309

Please sign in to comment.