-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Akka.Cluster.Metrics extension implementation (#4126)
- Loading branch information
1 parent
6febe56
commit f068b09
Showing
62 changed files
with
7,546 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
.../cluster/Akka.Cluster.Metrics.Tests.MultiNode/Akka.Cluster.Metrics.Tests.MultiNode.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="..\..\..\common.props" /> | ||
|
||
<PropertyGroup> | ||
<AssemblyTitle>Akka.Cluster.Metrics</AssemblyTitle> | ||
<TargetFrameworks>$(NetFrameworkTestVersion);$(NetCoreTestVersion)</TargetFrameworks> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Akka.Cluster.Metrics.Tests\Akka.Cluster.Metrics.Tests.csproj" /> | ||
<ProjectReference Include="..\Akka.Cluster.Metrics\Akka.Cluster.Metrics.csproj" /> | ||
<ProjectReference Include="..\..\..\core\Akka.Cluster.TestKit\Akka.Cluster.TestKit.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" /> | ||
<PackageReference Include="xunit" Version="$(XunitVersion)" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" /> | ||
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants> | ||
</PropertyGroup> | ||
</Project> |
162 changes: 162 additions & 0 deletions
162
src/contrib/cluster/Akka.Cluster.Metrics.Tests.MultiNode/ClusterMetricsExtensionSpec.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
// //----------------------------------------------------------------------- | ||
// // <copyright file="ClusterMetricsExtensionSpec.cs" company="Akka.NET Project"> | ||
// // Copyright (C) 2009-2020 Lightbend Inc. <http://www.lightbend.com> | ||
// // Copyright (C) 2013-2020 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// // </copyright> | ||
// //----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Immutable; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Akka.Cluster.Metrics.Tests.Helpers; | ||
using Akka.Cluster.TestKit; | ||
using Akka.Configuration; | ||
using Akka.Remote.TestKit; | ||
using FluentAssertions; | ||
|
||
namespace Akka.Cluster.Metrics.Tests.MultiNode | ||
{ | ||
public class ClusterMetricsCommonConfig : MultiNodeConfig | ||
{ | ||
public readonly RoleName Node1; | ||
public readonly RoleName Node2; | ||
public readonly RoleName Node3; | ||
public readonly RoleName Node4; | ||
public readonly RoleName Node5; | ||
|
||
public Config EnableMetricsExtension => ConfigurationFactory.ParseString(@" | ||
akka.extensions=[""Akka.Cluster.Metrics.ClusterMetricsExtensionProvider, Akka.Cluster.Metrics""] | ||
akka.cluster.metrics.collector.enabled = on | ||
"); | ||
|
||
public Config DisableMetricsExtension => ConfigurationFactory.ParseString(@" | ||
akka.extensions=[""Akka.Cluster.Metrics.ClusterMetricsExtensionProvider, Akka.Cluster.Metrics""] | ||
akka.cluster.metrics.collector.enabled = off | ||
"); | ||
|
||
public ClusterMetricsCommonConfig() | ||
{ | ||
Node1 = Role("node-1"); | ||
Node2 = Role("node-2"); | ||
Node3 = Role("node-3"); | ||
Node4 = Role("node-4"); | ||
Node5 = Role("node-5"); | ||
} | ||
} | ||
|
||
public class ClusterMetricsDisabledConfig : ClusterMetricsCommonConfig | ||
{ | ||
public ClusterMetricsDisabledConfig() | ||
{ | ||
CommonConfig = DisableMetricsExtension | ||
.WithFallback(DebugConfig(on: false)) | ||
.WithFallback(MultiNodeClusterSpec.ClusterConfigWithFailureDetectorPuppet()); | ||
} | ||
} | ||
|
||
public class ClusterMetricsEnabledConfig : ClusterMetricsCommonConfig | ||
{ | ||
public ClusterMetricsEnabledConfig() | ||
{ | ||
CommonConfig = EnableMetricsExtension | ||
.WithFallback(DebugConfig(on: false)) | ||
.WithFallback(MultiNodeClusterSpec.ClusterConfigWithFailureDetectorPuppet()); | ||
} | ||
} | ||
|
||
public class ClusterMetricsEnabledSpec : MultiNodeClusterSpec | ||
{ | ||
private readonly ClusterMetricsCommonConfig _config; | ||
public ClusterMetricsView MetricsView { get; } | ||
|
||
private ClusterMetricsEnabledSpec(ClusterMetricsCommonConfig config) : base(config, typeof(ClusterMetricsEnabledSpec)) | ||
{ | ||
_config = config; | ||
MetricsView = new ClusterMetricsView(Cluster.System); | ||
} | ||
|
||
public ClusterMetricsEnabledSpec() : this(new ClusterMetricsEnabledConfig()) | ||
{ | ||
} | ||
|
||
[MultiNodeFact] | ||
public async Task ClusterMetrics_Should_work_when_enabled() | ||
{ | ||
await Should_collect_and_publish_metrics_and_gossip_them_around_the_node_ring(); | ||
await Should_reflect_the_correct_number_or_node_metrics_in_cluster_view(); | ||
} | ||
|
||
private async Task Should_collect_and_publish_metrics_and_gossip_them_around_the_node_ring() | ||
{ | ||
await AwaitAssertAsync(() => | ||
{ | ||
AwaitClusterUp(Roles.ToArray()); | ||
}, TimeSpan.FromSeconds(30)); | ||
|
||
EnterBarrier("cluster_started"); | ||
await AwaitAssertAsync(() => | ||
{ | ||
Cluster.State.Members.Count(m => m.Status == MemberStatus.Up).Should().Be(Roles.Count); | ||
}, TimeSpan.FromSeconds(30)); | ||
|
||
await AwaitAssertAsync(() => | ||
{ | ||
MetricsView.ClusterMetrics.Count.Should().Be(Roles.Count); | ||
}, TimeSpan.FromSeconds(30)); | ||
|
||
await WithinAsync(10.Seconds(), async () => | ||
{ | ||
var collector = new MetricsCollectorBuilder().Build(Cluster.System); | ||
collector.Sample().Metrics.Count.Should().BeGreaterThan(3); | ||
EnterBarrier("after"); | ||
}); | ||
} | ||
|
||
private async Task Should_reflect_the_correct_number_or_node_metrics_in_cluster_view() | ||
{ | ||
await WithinAsync(30.Seconds(), async () => | ||
{ | ||
RunOn(() => | ||
{ | ||
Cluster.Leave(Node(_config.Node1).Address); | ||
}, _config.Node2); | ||
EnterBarrier("first-left"); | ||
await RunOnAsync(async () => | ||
{ | ||
MarkNodeAsUnavailable(Node(_config.Node1).Address); | ||
await AwaitAssertAsync(() => MetricsView.ClusterMetrics.Count.Should().Be(Roles.Count - 1)); | ||
}, _config.Node2, _config.Node3, _config.Node4, _config.Node5); | ||
EnterBarrier("finished"); | ||
}); | ||
} | ||
} | ||
|
||
public class ClusterMetricsDisabledSpec : MultiNodeClusterSpec | ||
{ | ||
public ClusterMetricsView MetricsView { get; } | ||
|
||
private ClusterMetricsDisabledSpec(ClusterMetricsDisabledConfig config) : base(config, typeof(ClusterMetricsDisabledSpec)) | ||
{ | ||
MetricsView = new ClusterMetricsView(Cluster.System); | ||
} | ||
|
||
public ClusterMetricsDisabledSpec() : this(new ClusterMetricsDisabledConfig()) | ||
{ | ||
} | ||
|
||
[MultiNodeFact] | ||
public void ClusterMetrics_Should_not_collect_publish_and_gossip_metrics_when_disabled() | ||
{ | ||
AwaitClusterUp(Roles.ToArray()); | ||
MetricsView.ClusterMetrics.Count.Should().Be(0); | ||
ClusterMetrics.Get(Sys).Subscribe(TestActor); | ||
ExpectNoMsg(); | ||
MetricsView.ClusterMetrics.Count.Should().Be(0); | ||
EnterBarrier("after"); | ||
} | ||
} | ||
} |
Oops, something went wrong.