Skip to content

Commit

Permalink
Akka.Cluster.Metrics extension implementation (#4126)
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorFedchenko authored and Aaronontheweb committed Jan 27, 2020
1 parent 6febe56 commit f068b09
Show file tree
Hide file tree
Showing 62 changed files with 7,546 additions and 14 deletions.
45 changes: 45 additions & 0 deletions src/Akka.sln
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Akka.Docs.Tests", "core\Akk
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Akka.Docs.Tutorials", "core\Akka.Docs.Tutorials\Akka.Docs.Tutorials.csproj", "{9AE636F2-988C-42E4-9B40-FF1F7177DF91}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Cluster.Metrics", "contrib\cluster\Akka.Cluster.Metrics\Akka.Cluster.Metrics.csproj", "{1E26E439-C9E1-4DBE-A783-D5FE31FCDD6F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Cluster.Metrics.Tests", "contrib\cluster\Akka.Cluster.Metrics.Tests\Akka.Cluster.Metrics.Tests.csproj", "{A2DEE719-E443-4C5D-B31C-35A0AF0628D4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Akka.Cluster.Metrics.Tests.MultiNode", "contrib\cluster\Akka.Cluster.Metrics.Tests.MultiNode\Akka.Cluster.Metrics.Tests.MultiNode.csproj", "{FC5216C2-3C98-4691-8E72-205EBF9594D0}"
EndProject
Global
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
Expand Down Expand Up @@ -909,6 +915,42 @@ Global
{9AE636F2-988C-42E4-9B40-FF1F7177DF91}.Release|x64.Build.0 = Release|Any CPU
{9AE636F2-988C-42E4-9B40-FF1F7177DF91}.Release|x86.ActiveCfg = Release|Any CPU
{9AE636F2-988C-42E4-9B40-FF1F7177DF91}.Release|x86.Build.0 = Release|Any CPU
{1E26E439-C9E1-4DBE-A783-D5FE31FCDD6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E26E439-C9E1-4DBE-A783-D5FE31FCDD6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E26E439-C9E1-4DBE-A783-D5FE31FCDD6F}.Debug|x64.ActiveCfg = Debug|Any CPU
{1E26E439-C9E1-4DBE-A783-D5FE31FCDD6F}.Debug|x64.Build.0 = Debug|Any CPU
{1E26E439-C9E1-4DBE-A783-D5FE31FCDD6F}.Debug|x86.ActiveCfg = Debug|Any CPU
{1E26E439-C9E1-4DBE-A783-D5FE31FCDD6F}.Debug|x86.Build.0 = Debug|Any CPU
{1E26E439-C9E1-4DBE-A783-D5FE31FCDD6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E26E439-C9E1-4DBE-A783-D5FE31FCDD6F}.Release|Any CPU.Build.0 = Release|Any CPU
{1E26E439-C9E1-4DBE-A783-D5FE31FCDD6F}.Release|x64.ActiveCfg = Release|Any CPU
{1E26E439-C9E1-4DBE-A783-D5FE31FCDD6F}.Release|x64.Build.0 = Release|Any CPU
{1E26E439-C9E1-4DBE-A783-D5FE31FCDD6F}.Release|x86.ActiveCfg = Release|Any CPU
{1E26E439-C9E1-4DBE-A783-D5FE31FCDD6F}.Release|x86.Build.0 = Release|Any CPU
{A2DEE719-E443-4C5D-B31C-35A0AF0628D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A2DEE719-E443-4C5D-B31C-35A0AF0628D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A2DEE719-E443-4C5D-B31C-35A0AF0628D4}.Debug|x64.ActiveCfg = Debug|Any CPU
{A2DEE719-E443-4C5D-B31C-35A0AF0628D4}.Debug|x64.Build.0 = Debug|Any CPU
{A2DEE719-E443-4C5D-B31C-35A0AF0628D4}.Debug|x86.ActiveCfg = Debug|Any CPU
{A2DEE719-E443-4C5D-B31C-35A0AF0628D4}.Debug|x86.Build.0 = Debug|Any CPU
{A2DEE719-E443-4C5D-B31C-35A0AF0628D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A2DEE719-E443-4C5D-B31C-35A0AF0628D4}.Release|Any CPU.Build.0 = Release|Any CPU
{A2DEE719-E443-4C5D-B31C-35A0AF0628D4}.Release|x64.ActiveCfg = Release|Any CPU
{A2DEE719-E443-4C5D-B31C-35A0AF0628D4}.Release|x64.Build.0 = Release|Any CPU
{A2DEE719-E443-4C5D-B31C-35A0AF0628D4}.Release|x86.ActiveCfg = Release|Any CPU
{A2DEE719-E443-4C5D-B31C-35A0AF0628D4}.Release|x86.Build.0 = Release|Any CPU
{FC5216C2-3C98-4691-8E72-205EBF9594D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FC5216C2-3C98-4691-8E72-205EBF9594D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC5216C2-3C98-4691-8E72-205EBF9594D0}.Debug|x64.ActiveCfg = Debug|Any CPU
{FC5216C2-3C98-4691-8E72-205EBF9594D0}.Debug|x64.Build.0 = Debug|Any CPU
{FC5216C2-3C98-4691-8E72-205EBF9594D0}.Debug|x86.ActiveCfg = Debug|Any CPU
{FC5216C2-3C98-4691-8E72-205EBF9594D0}.Debug|x86.Build.0 = Debug|Any CPU
{FC5216C2-3C98-4691-8E72-205EBF9594D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC5216C2-3C98-4691-8E72-205EBF9594D0}.Release|Any CPU.Build.0 = Release|Any CPU
{FC5216C2-3C98-4691-8E72-205EBF9594D0}.Release|x64.ActiveCfg = Release|Any CPU
{FC5216C2-3C98-4691-8E72-205EBF9594D0}.Release|x64.Build.0 = Release|Any CPU
{FC5216C2-3C98-4691-8E72-205EBF9594D0}.Release|x86.ActiveCfg = Release|Any CPU
{FC5216C2-3C98-4691-8E72-205EBF9594D0}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -998,6 +1040,9 @@ Global
{6F8FECD6-6E39-473E-9B9A-9EE22CBF479F} = {01167D3C-49C4-4CDE-9787-C176D139ACDD}
{159F6312-3F12-4A84-9E7C-0A4B4FD72D1E} = {01167D3C-49C4-4CDE-9787-C176D139ACDD}
{9AE636F2-988C-42E4-9B40-FF1F7177DF91} = {01167D3C-49C4-4CDE-9787-C176D139ACDD}
{1E26E439-C9E1-4DBE-A783-D5FE31FCDD6F} = {76F58DC4-19F1-43EF-A6E2-EC1CC8395AC5}
{A2DEE719-E443-4C5D-B31C-35A0AF0628D4} = {76F58DC4-19F1-43EF-A6E2-EC1CC8395AC5}
{FC5216C2-3C98-4691-8E72-205EBF9594D0} = {76F58DC4-19F1-43EF-A6E2-EC1CC8395AC5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {03AD8E21-7507-4E68-A4E9-F4A7E7273164}
Expand Down
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>
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");
}
}
}
Loading

0 comments on commit f068b09

Please sign in to comment.