Skip to content

Commit

Permalink
[#25792] docdb: Remove boost/regex.hpp include from metric_entity.h
Browse files Browse the repository at this point in the history
Summary:
metric_entity.h is included by metrics.h which is included by a lot of other files.
Including boost/regex.hpp takes ~300ms and is almost never needed elsewhere.

Compile time of transaction_participant.cc (avg 10 runs):
- before changes: 15.377s
- after changes: 15.099s
Jira: DB-15082

Test Plan: Jenkins

Reviewers: yyan, asrivastava

Reviewed By: asrivastava

Subscribers: ybase

Tags: #jenkins-ready

Differential Revision: https://phorge.dev.yugabyte.com/D41505
  • Loading branch information
es1024 committed Jan 29, 2025
1 parent a0596a8 commit 014ccb5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 37 deletions.
2 changes: 2 additions & 0 deletions src/yb/util/metric_entity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
//
#include "yb/util/metric_entity.h"

#include <boost/regex.hpp>

#include "yb/gutil/map-util.h"

#include "yb/util/debug.h"
Expand Down
2 changes: 0 additions & 2 deletions src/yb/util/metric_entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include <map>
#include <unordered_map>

#include <boost/regex.hpp>

#include "yb/gutil/callback_forward.h"
#include "yb/gutil/map-util.h"

Expand Down
38 changes: 38 additions & 0 deletions src/yb/util/prometheus_metric_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,29 @@

#include "yb/util/prometheus_metric_filter.h"

#include <boost/regex.hpp>

namespace yb {

namespace {

class PrometheusMetricFilterV1 : public PrometheusMetricFilter {
public:
explicit PrometheusMetricFilterV1(const MetricPrometheusOptions& opts);

AggregationLevels GetAggregationLevels(
const std::string& metric_name, AggregationLevels default_aggregation_levels) override;

std::string Version() const override;

private:
bool ShouldCollectMetric(const std::string& metric_name) const;

const boost::regex priority_regex_;

const std::optional<std::vector<std::string>> general_metrics_allowlist_;
};

PrometheusMetricFilterV1::PrometheusMetricFilterV1(const MetricPrometheusOptions& opts)
: priority_regex_(opts.priority_regex_string),
general_metrics_allowlist_(opts.general_metrics_allowlist) {}
Expand Down Expand Up @@ -63,6 +84,21 @@ std::string PrometheusMetricFilterV1::Version() const {
return kFilterVersionOne;
}

class PrometheusMetricFilterV2 : public PrometheusMetricFilter {
public:
explicit PrometheusMetricFilterV2(const MetricPrometheusOptions& opts);

AggregationLevels GetAggregationLevels(
const std::string& metric_name, AggregationLevels default_aggregation_levels) override;

std::string Version() const override;

private:
const boost::regex table_allowlist_;
const boost::regex table_blocklist_;
const boost::regex server_allowlist_;
const boost::regex server_blocklist_;
};

PrometheusMetricFilterV2::PrometheusMetricFilterV2(const MetricPrometheusOptions& opts)
: table_allowlist_(opts.table_allowlist_string),
Expand Down Expand Up @@ -95,6 +131,8 @@ std::string PrometheusMetricFilterV2::Version() const {
return kFilterVersionTwo;
}

} // namespace

std::unique_ptr<PrometheusMetricFilter> CreatePrometheusMetricFilter(
const MetricPrometheusOptions& opts) {
DCHECK(opts.version == kFilterVersionOne || opts.version == kFilterVersionTwo);
Expand Down
35 changes: 0 additions & 35 deletions src/yb/util/prometheus_metric_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,6 @@ class PrometheusMetricFilter {
MetricAggregationMap metric_filter_;
};


class PrometheusMetricFilterV1 : public PrometheusMetricFilter {
public:
explicit PrometheusMetricFilterV1(const MetricPrometheusOptions& opts);

AggregationLevels GetAggregationLevels(
const std::string& metric_name, AggregationLevels default_aggregation_levels) override;

std::string Version() const override;

private:
bool ShouldCollectMetric(const std::string& metric_name) const;

const boost::regex priority_regex_;

const std::optional<std::vector<std::string>> general_metrics_allowlist_;
};


class PrometheusMetricFilterV2 : public PrometheusMetricFilter {
public:
explicit PrometheusMetricFilterV2(const MetricPrometheusOptions& opts);

AggregationLevels GetAggregationLevels(
const std::string& metric_name, AggregationLevels default_aggregation_levels) override;

std::string Version() const override;

private:
const boost::regex table_allowlist_;
const boost::regex table_blocklist_;
const boost::regex server_allowlist_;
const boost::regex server_blocklist_;
};

std::unique_ptr<PrometheusMetricFilter> CreatePrometheusMetricFilter(
const MetricPrometheusOptions& opts);

Expand Down

0 comments on commit 014ccb5

Please sign in to comment.