Skip to content

Commit

Permalink
Fix wrong log lag in cluster-zone check
Browse files Browse the repository at this point in the history
Refactor the calculation into a generic function
which is also used inside the 2.4 status API.

fixes #8805
  • Loading branch information
Michael Friedrich committed Sep 25, 2015
1 parent 5ef4204 commit 717118f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
16 changes: 8 additions & 8 deletions lib/methods/clusterzonechecktask.cpp
Expand Up @@ -81,28 +81,28 @@ void ClusterZoneCheckTask::ScriptFunc(const Checkable::Ptr& checkable, const Che
}

bool connected = false;
double lag = 0;
double zoneLag = 0;

BOOST_FOREACH(const Endpoint::Ptr& endpoint, zone->GetEndpoints()) {
double eplag = Utility::GetTime() - endpoint->GetRemoteLogPosition();

if (endpoint->IsConnected())
connected = true;

if ((endpoint->GetSyncing() || !endpoint->IsConnected()) && eplag > lag)
lag = eplag;
double eplag = ApiListener::CalculateZoneLag(endpoint);

if (eplag > 0 && eplag > zoneLag)
zoneLag = eplag;
}

if (!connected) {
cr->SetState(ServiceCritical);
cr->SetOutput("Zone '" + zoneName + "' is not connected. Log lag: " + Utility::FormatDuration(lag));
cr->SetOutput("Zone '" + zoneName + "' is not connected. Log lag: " + Utility::FormatDuration(zoneLag));
} else {
cr->SetState(ServiceOK);
cr->SetOutput("Zone '" + zoneName + "' is connected. Log lag: " + Utility::FormatDuration(lag));
cr->SetOutput("Zone '" + zoneName + "' is connected. Log lag: " + Utility::FormatDuration(zoneLag));
}

Array::Ptr perfdata = new Array();
perfdata->Add(new PerfdataValue("slave_lag", lag));
perfdata->Add(new PerfdataValue("slave_lag", zoneLag));
cr->SetPerformanceData(perfdata);

checkable->ProcessCheckResult(cr);
Expand Down
15 changes: 13 additions & 2 deletions lib/remote/apilistener.cpp
Expand Up @@ -895,9 +895,9 @@ std::pair<Dictionary::Ptr, Dictionary::Ptr> ApiListener::GetStatus(void)
if (endpoint->GetName() == GetIdentity())
continue;

double eplag = Utility::GetTime() - endpoint->GetRemoteLogPosition();
double eplag = CalculateZoneLag(endpoint);

if ((endpoint->GetSyncing() || !endpoint->IsConnected()) && eplag > zoneLag)
if (eplag > 0 && eplag > zoneLag)
zoneLag = eplag;

allEndpoints++;
Expand Down Expand Up @@ -945,6 +945,17 @@ std::pair<Dictionary::Ptr, Dictionary::Ptr> ApiListener::GetStatus(void)
return std::make_pair(status, perfdata);
}

double ApiListener::CalculateZoneLag(const Endpoint::Ptr& endpoint)
{
double remoteLogPosition = endpoint->GetRemoteLogPosition();
double eplag = Utility::GetTime() - remoteLogPosition;

if ((endpoint->GetSyncing() || !endpoint->IsConnected()) && remoteLogPosition != 0)
return eplag;

return 0;
}

void ApiListener::AddAnonymousClient(const JsonRpcConnection::Ptr& aclient)
{
ObjectLock olock(this);
Expand Down
2 changes: 2 additions & 0 deletions lib/remote/apilistener.hpp
Expand Up @@ -75,6 +75,8 @@ class I2_REMOTE_API ApiListener : public ObjectImpl<ApiListener>
void RemoveHttpClient(const HttpServerConnection::Ptr& aclient);
std::set<HttpServerConnection::Ptr> GetHttpClients(void) const;

static double CalculateZoneLag(const Endpoint::Ptr& endpoint);

/* filesync */
static Value ConfigUpdateHandler(const MessageOrigin::Ptr& origin, const Dictionary::Ptr& params);

Expand Down

0 comments on commit 717118f

Please sign in to comment.