Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Logging metrics sampling (#1516)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbutrovich authored Mar 12, 2021
1 parent 68c0069 commit 86d87d1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/include/main/db_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ class DBMain {
uint8_t pipeline_metrics_sample_rate_ = 10;
bool transaction_metrics_ = false;
bool logging_metrics_ = false;
uint8_t logging_metrics_sample_rate_ = 100;
bool gc_metrics_ = false;
bool bind_command_metrics_ = false;
bool execute_command_metrics_ = false;
Expand Down Expand Up @@ -998,6 +999,7 @@ class DBMain {
query_trace_metrics_ = settings_manager->GetBool(settings::Param::query_trace_metrics_enable);
pipeline_metrics_ = settings_manager->GetBool(settings::Param::pipeline_metrics_enable);
pipeline_metrics_sample_rate_ = settings_manager->GetInt(settings::Param::pipeline_metrics_sample_rate);
logging_metrics_sample_rate_ = settings_manager->GetInt(settings::Param::logging_metrics_sample_rate);
transaction_metrics_ = settings_manager->GetBool(settings::Param::transaction_metrics_enable);
logging_metrics_ = settings_manager->GetBool(settings::Param::logging_metrics_enable);
gc_metrics_ = settings_manager->GetBool(settings::Param::gc_metrics_enable);
Expand All @@ -1023,6 +1025,7 @@ class DBMain {
std::unique_ptr<metrics::MetricsManager> metrics_manager = std::make_unique<metrics::MetricsManager>();
metrics_manager->SetMetricSampleRate(metrics::MetricsComponent::EXECUTION_PIPELINE,
pipeline_metrics_sample_rate_);
metrics_manager->SetMetricSampleRate(metrics::MetricsComponent::LOGGING, logging_metrics_sample_rate_);

if (query_trace_metrics_) metrics_manager->EnableMetric(metrics::MetricsComponent::QUERY_TRACE);
if (pipeline_metrics_) metrics_manager->EnableMetric(metrics::MetricsComponent::EXECUTION_PIPELINE);
Expand Down
10 changes: 10 additions & 0 deletions src/include/settings/settings_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ class Callbacks {
static void MetricsPipeline(void *old_value, void *new_value, DBMain *db_main,
common::ManagedPointer<common::ActionContext> action_context);

/**
* Update the sampling interval for logging
* @param old_value old settings value
* @param new_value new settings value
* @param db_main pointer to db_main
* @param action_context pointer to the action context for this settings change
*/
static void MetricsLoggingSampleRate(void *old_value, void *new_value, DBMain *db_main,
common::ManagedPointer<common::ActionContext> action_context);

/**
* Update the sampling interval for ExecutionEngine pipelines
* @param old_value old settings value
Expand Down
10 changes: 10 additions & 0 deletions src/include/settings/settings_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,16 @@ SETTING_int(
noisepage::settings::Callbacks::MetricsPipelineSampleRate
)

SETTING_int(
logging_metrics_sample_rate,
"Sampling rate of metrics collection for logging.",
100,
0,
100,
true,
noisepage::settings::Callbacks::MetricsLoggingSampleRate
)

SETTING_bool(
bind_command_metrics_enable,
"Metrics collection for the bind command.",
Expand Down
8 changes: 8 additions & 0 deletions src/settings/settings_callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ void Callbacks::MetricsPipelineSampleRate(void *old_value, void *new_value, DBMa
action_context->SetState(common::ActionState::SUCCESS);
}

void Callbacks::MetricsLoggingSampleRate(void *old_value, void *new_value, DBMain *db_main,
common::ManagedPointer<common::ActionContext> action_context) {
action_context->SetState(common::ActionState::IN_PROGRESS);
int interval = *static_cast<int *>(new_value);
db_main->GetMetricsManager()->SetMetricSampleRate(metrics::MetricsComponent::LOGGING, static_cast<uint8_t>(interval));
action_context->SetState(common::ActionState::SUCCESS);
}

void Callbacks::MetricsBindCommand(void *const old_value, void *const new_value, DBMain *const db_main,
common::ManagedPointer<common::ActionContext> action_context) {
action_context->SetState(common::ActionState::IN_PROGRESS);
Expand Down

0 comments on commit 86d87d1

Please sign in to comment.