Skip to content

Commit

Permalink
add crit event
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpeye committed Nov 8, 2024
1 parent d7f3d11 commit 4860771
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 43 deletions.
1 change: 1 addition & 0 deletions cloud/blockstore/libs/diagnostics/critical_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace NCloud::NBlockStore {
xxx(DiskRegistryAgentDevicePoolConfigMismatch) \
xxx(DiskRegistryPurgeHostError) \
xxx(DiskRegistryCleanupAgentConfigError) \
xxx(DiskRegistryOccupiedDeviceConfigurationHasChanged) \
// BLOCKSTORE_CRITICAL_EVENTS

#define BLOCKSTORE_IMPOSSIBLE_EVENTS(xxx) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,9 @@ auto TDiskRegistryState::RegisterAgent(

STORAGE_ERROR(message);

ReportDiskRegistryOccupiedDeviceConfigurationHasChanged(
message);

SetDeviceErrorState(d, timestamp, std::move(message));

continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11780,6 +11780,19 @@ Y_UNIT_TEST_SUITE(TDiskRegistryStateTest)
const TString oldSerialNumber = "OldSerialNumber";
const TString newSerialNumber = "NewSerialNumber";

auto monitoring = CreateMonitoringServiceStub();
auto rootGroup = monitoring->GetCounters()
->GetSubgroup("counters", "blockstore");

auto serverGroup = rootGroup->GetSubgroup("component", "server");
InitCriticalEventsCounter(serverGroup);

auto criticalEvents = serverGroup->FindCounter(
"AppCriticalEvents/"
"DiskRegistryOccupiedDeviceConfigurationHasChanged");

UNIT_ASSERT_VALUES_EQUAL(0, criticalEvents->Val());

TTestExecutor executor;
executor.WriteTx([&] (TDiskRegistryDatabase db) {
db.InitSchema();
Expand All @@ -11797,60 +11810,49 @@ Y_UNIT_TEST_SUITE(TDiskRegistryStateTest)
})
.Build();

executor.WriteTx([&] (TDiskRegistryDatabase db) {
TVector<TString> affectedDisks;
TVector<TString> disksToReallocate;
auto error = state.RegisterAgent(
db,
agentConfig,
Now(),
&affectedDisks,
&disksToReallocate);
executor.WriteTx(
[&](TDiskRegistryDatabase db)
{
auto [r, error] = state.RegisterAgent(db, agentConfig, Now());

UNIT_ASSERT_VALUES_EQUAL(S_OK, error.GetCode());
UNIT_ASSERT_VALUES_EQUAL(0, affectedDisks.size());
UNIT_ASSERT_VALUES_EQUAL(0, state.GetDirtyDevices().size());
});
UNIT_ASSERT_SUCCESS(error);
UNIT_ASSERT_VALUES_EQUAL(0, r.AffectedDisks.size());
UNIT_ASSERT_VALUES_EQUAL(0, state.GetDirtyDevices().size());
});

agentConfig.MutableDevices(0)->SetSerialNumber(oldSerialNumber);
agentConfig.MutableDevices(1)->SetSerialNumber(oldSerialNumber);

executor.WriteTx([&] (TDiskRegistryDatabase db) {
TVector<TString> affectedDisks;
TVector<TString> disksToReallocate;
auto error = state.RegisterAgent(
db,
agentConfig,
Now(),
&affectedDisks,
&disksToReallocate);
executor.WriteTx(
[&](TDiskRegistryDatabase db)
{
auto [r, error] = state.RegisterAgent(db, agentConfig, Now());

UNIT_ASSERT_VALUES_EQUAL(S_OK, error.GetCode());
UNIT_ASSERT_VALUES_EQUAL(0, affectedDisks.size());
UNIT_ASSERT_VALUES_EQUAL(0, state.GetDirtyDevices().size());
});
UNIT_ASSERT_SUCCESS(error);
UNIT_ASSERT_VALUES_EQUAL(0, r.AffectedDisks.size());
UNIT_ASSERT_VALUES_EQUAL(0, state.GetDirtyDevices().size());
});

agentConfig.MutableDevices(0)->SetSerialNumber(newSerialNumber);
agentConfig.MutableDevices(1)->SetSerialNumber(newSerialNumber);

executor.WriteTx([&] (TDiskRegistryDatabase db) {
TVector<TString> affectedDisks;
TVector<TString> disksToReallocate;
auto error = state.RegisterAgent(
db,
agentConfig,
Now(),
&affectedDisks,
&disksToReallocate);
executor.WriteTx(
[&](TDiskRegistryDatabase db)
{
auto [r, error] = state.RegisterAgent(db, agentConfig, Now());

UNIT_ASSERT_VALUES_EQUAL(S_OK, error.GetCode());
UNIT_ASSERT_VALUES_EQUAL(1, affectedDisks.size());
UNIT_ASSERT_VALUES_EQUAL("disk-1", affectedDisks[0]);
const auto& dd = state.GetDirtyDevices();
UNIT_ASSERT_VALUES_EQUAL(1, dd.size());
UNIT_ASSERT_VALUES_EQUAL("uuid-1.1", dd[0].GetDeviceUUID());
UNIT_ASSERT_VALUES_EQUAL(newSerialNumber, dd[0].GetSerialNumber());
});
UNIT_ASSERT_SUCCESS(error);
UNIT_ASSERT_VALUES_EQUAL(1, r.AffectedDisks.size());
UNIT_ASSERT_VALUES_EQUAL("disk-1", r.AffectedDisks[0]);
const auto& dd = state.GetDirtyDevices();
UNIT_ASSERT_VALUES_EQUAL(1, dd.size());
UNIT_ASSERT_VALUES_EQUAL("uuid-1.1", dd[0].GetDeviceUUID());
UNIT_ASSERT_VALUES_EQUAL(
newSerialNumber,
dd[0].GetSerialNumber());
});

UNIT_ASSERT_VALUES_EQUAL(1, criticalEvents->Val());
}
}

Expand Down

0 comments on commit 4860771

Please sign in to comment.