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

View File

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

View File

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