Skip to content

Commit

Permalink
RavenDB-21412 missing handling of total Queue Sink tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
arekpalinski committed Jun 14, 2024
1 parent b2b1de1 commit ae74d22
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@ protected internal static int GetNumberOfSubscriptions(TransactionOperationConte

return count;
}

protected internal static int GetNumberOfQueueSinks(RawDatabaseRecord database) => database.QueueSinks?.Count(x => x.Disabled == false) ?? 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ protected override int GetCount(TransactionOperationContext context, RawDatabase
count += GetNumberOfSinkPullReplications(database);
count += GetNumberOfSqlEtls(database);
count += GetNumberOfSubscriptions(context, database);
count += GetNumberOfQueueSinks(database);

return count;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Raven.Server.ServerWide;
using Raven.Server.ServerWide.Context;

namespace Raven.Server.Monitoring.Snmp.Objects.Database;

public class TotalNumberOfQueueSinkTasks : OngoingTasksBase
{
public TotalNumberOfQueueSinkTasks(ServerStore serverStore)
: base(serverStore, SnmpOids.Databases.General.TotalNumberOfQueueSinkTasks)
{
}

protected override int GetCount(TransactionOperationContext context, RawDatabaseRecord database)
{
return GetNumberOfQueueSinks(database);
}
}
5 changes: 4 additions & 1 deletion src/Raven.Server/Monitoring/Snmp/SnmpOids.cs
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,11 @@ private General()
[Description("Number of active Pull Replication As Sink tasks for all databases")]
public const string TotalNumberOfActivePullReplicationAsSinkTasks = "5.1.11.20";

[Description("Number of enabled Queue Sink tasks for all databases")]
public const string TotalNumberOfQueueSinkTasks = "5.1.11.21";

[Description("Number of active Queue Sink tasks for all databases")]
public const string TotalNumberOfActiveQueueSinkTasks = "5.1.11.21";
public const string TotalNumberOfActiveQueueSinkTasks = "5.1.11.22";

public static DynamicJsonArray ToJson()
{
Expand Down
17 changes: 11 additions & 6 deletions test/FastTests/Issues/RavenDB_21412.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Tests.Infrastructure;
using Xunit;
using Xunit.Abstractions;
using static Raven.Server.Utils.MetricCacher.Keys;

namespace FastTests.Issues;

Expand Down Expand Up @@ -58,15 +59,15 @@ public async Task Verify_OngoingTasks_In_Snmp_Return_Proper_Counts()
var total = new TotalNumberOfOngoingTasks(Server.ServerStore);
var test = new TestOngoingTasks(Server.ServerStore, "1");

AssertCounts(test, total, expectedOlapCount: 0, expectedElasticCount: 0, expectedExternalCount: 0, expectedBackupCount: 0, expectedQueueCount: 0, expectedRavenCount: 0, expectedSinkCount: 0, expectedSqlCount: 0, expectedSubscriptionCount: 0);
AssertCounts(test, total, expectedOlapCount: 0, expectedElasticCount: 0, expectedExternalCount: 0, expectedBackupCount: 0, expectedQueueCount: 0, expectedRavenCount: 0, expectedSinkCount: 0, expectedSqlCount: 0, expectedSubscriptionCount: 0, expectedQueueSinkCount: 0);

var sub = await store.Subscriptions.CreateAsync<Company>();
AssertCounts(test, total, expectedOlapCount: 0, expectedElasticCount: 0, expectedExternalCount: 0, expectedBackupCount: 0, expectedQueueCount: 0, expectedRavenCount: 0, expectedSinkCount: 0, expectedSqlCount: 0, expectedSubscriptionCount: 1);
AssertCounts(test, total, expectedOlapCount: 0, expectedElasticCount: 0, expectedExternalCount: 0, expectedBackupCount: 0, expectedQueueCount: 0, expectedRavenCount: 0, expectedSinkCount: 0, expectedSqlCount: 0, expectedSubscriptionCount: 1, expectedQueueSinkCount: 0);
await store.Subscriptions.DisableAsync(sub);
AssertCounts(test, total, expectedOlapCount: 0, expectedElasticCount: 0, expectedExternalCount: 0, expectedBackupCount: 0, expectedQueueCount: 0, expectedRavenCount: 0, expectedSinkCount: 0, expectedSqlCount: 0, expectedSubscriptionCount: 0);
AssertCounts(test, total, expectedOlapCount: 0, expectedElasticCount: 0, expectedExternalCount: 0, expectedBackupCount: 0, expectedQueueCount: 0, expectedRavenCount: 0, expectedSinkCount: 0, expectedSqlCount: 0, expectedSubscriptionCount: 0, expectedQueueSinkCount: 0);

await store.Maintenance.SendAsync(new UpdatePeriodicBackupOperation(new PeriodicBackupConfiguration { FullBackupFrequency = "* * * * *", LocalSettings = new LocalSettings { FolderPath = NewDataPath() } }));
AssertCounts(test, total, expectedOlapCount: 0, expectedElasticCount: 0, expectedExternalCount: 0, expectedBackupCount: 1, expectedQueueCount: 0, expectedRavenCount: 0, expectedSinkCount: 0, expectedSqlCount: 0, expectedSubscriptionCount: 0);
AssertCounts(test, total, expectedOlapCount: 0, expectedElasticCount: 0, expectedExternalCount: 0, expectedBackupCount: 1, expectedQueueCount: 0, expectedRavenCount: 0, expectedSinkCount: 0, expectedSqlCount: 0, expectedSubscriptionCount: 0, expectedQueueSinkCount: 0);
}
}

Expand All @@ -81,7 +82,8 @@ private static void AssertCounts(
int expectedRavenCount,
int expectedSinkCount,
int expectedSqlCount,
int expectedSubscriptionCount)
int expectedSubscriptionCount,
int expectedQueueSinkCount)
{
test.GetCountFunc = (_, database) => OngoingTasksBase.GetNumberOfOlapEtls(database);
Assert.Equal(expectedOlapCount, ((Integer32)test.Data).ToInt32());
Expand Down Expand Up @@ -110,7 +112,10 @@ private static void AssertCounts(
test.GetCountFunc = OngoingTasksBase.GetNumberOfSubscriptions;
Assert.Equal(expectedSubscriptionCount, ((Integer32)test.Data).ToInt32());

Assert.Equal(expectedOlapCount + expectedElasticCount + expectedExternalCount + expectedBackupCount + expectedQueueCount + expectedRavenCount + expectedSinkCount + expectedSqlCount + expectedSubscriptionCount, ((Integer32)total.Data).ToInt32());
test.GetCountFunc = (_, database) => OngoingTasksBase.GetNumberOfQueueSinks(database);
Assert.Equal(expectedQueueSinkCount, ((Integer32)test.Data).ToInt32());

Assert.Equal(expectedOlapCount + expectedElasticCount + expectedExternalCount + expectedBackupCount + expectedQueueCount + expectedRavenCount + expectedSinkCount + expectedSqlCount + expectedSubscriptionCount + expectedQueueSinkCount, ((Integer32)total.Data).ToInt32());
}

private class TestOngoingTasks : OngoingTasksBase
Expand Down

0 comments on commit ae74d22

Please sign in to comment.