executing query monitor under killswitch (#5170)

This commit is contained in:
Giorgi Guliashvili 2018-09-03 18:02:40 +01:00 committed by GitHub
parent f7213ef9b4
commit c301e361ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 10 deletions

View File

@ -2,12 +2,11 @@
* Copyright (c) 2014-present, Facebook, Inc. * Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under both the Apache 2.0 license (found in the * This source code is licensed under both the Apache 2.0 license (found in
* LICENSE file in the root directory of this source tree) and the GPLv2 (found * the LICENSE file in the root directory of this source tree) and the GPLv2
* in the COPYING file in the root directory of this source tree). * (found in the COPYING file in the root directory of this source tree). You
* You may select, at your option, one of the above-listed licenses. * may select, at your option, one of the above-listed licenses.
*/ */
#pragma once #pragma once
#include <string> #include <string>
@ -32,6 +31,10 @@ class Killswitch : private boost::noncopyable {
public: public:
virtual ~Killswitch(); virtual ~Killswitch();
// Author: @guliashvili
// Creation Time: 3/09/2018
bool isExecutingQueryMonitorEnabled();
// Author: @guliashvili // Author: @guliashvili
// Creation Time: 24/08/2018 // Creation Time: 24/08/2018
bool isConfigBackupEnabled(); bool isConfigBackupEnabled();

View File

@ -16,6 +16,7 @@
#include <osquery/core.h> #include <osquery/core.h>
#include <osquery/database.h> #include <osquery/database.h>
#include <osquery/flags.h> #include <osquery/flags.h>
#include <osquery/killswitch.h>
#include <osquery/logger.h> #include <osquery/logger.h>
#include <osquery/numeric_monitoring.h> #include <osquery/numeric_monitoring.h>
#include <osquery/query.h> #include <osquery/query.h>
@ -178,11 +179,14 @@ inline void launchQueryWithProfiling(const std::string& name,
auto status = launchQuery(name, query); auto status = launchQuery(name, query);
auto query_duration = std::chrono::duration_cast<std::chrono::milliseconds>( auto query_duration = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now() - start_time_point); std::chrono::steady_clock::now() - start_time_point);
auto monitoring_path = boost::format("scheduler.executing_query.%s.%s") % if (Killswitch::get().isExecutingQueryMonitorEnabled()) {
name % (status.ok() ? "success" : "failure"); auto monitoring_path = boost::format("scheduler.executing_query.%s.%s") %
monitoring::record(monitoring_path.str(), name % (status.ok() ? "success" : "failure");
query_duration.count(),
monitoring::PreAggregationType::Min); monitoring::record(monitoring_path.str(),
query_duration.count(),
monitoring::PreAggregationType::Min);
}
} }
void SchedulerRunner::start() { void SchedulerRunner::start() {

View File

@ -32,6 +32,10 @@ FLAG(string,
Killswitch::Killswitch() {} Killswitch::Killswitch() {}
Killswitch::~Killswitch() = default; Killswitch::~Killswitch() = default;
bool Killswitch::isExecutingQueryMonitorEnabled() {
return isNewCodeEnabled("executingQueryMonitorSwitch");
}
bool Killswitch::isConfigBackupEnabled() { bool Killswitch::isConfigBackupEnabled() {
return isNewCodeEnabled("configBackupSwitch"); return isNewCodeEnabled("configBackupSwitch");
} }