Seastar
High performance C++ framework for concurrent servers
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
relabel_config.hh
1/*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18/*
19 * Copyright 2022 ScyllaDB
20 */
21
22#pragma once
23
24#ifndef SEASTAR_MODULE
25#include <regex>
26#endif
27#include <seastar/util/modules.hh>
28
29namespace seastar {
30namespace metrics {
31
32SEASTAR_MODULE_EXPORT_BEGIN
33
41 std::string _regex_str;
42 std::regex _regex;
43public:
44 relabel_config_regex() = default;
45 relabel_config_regex(const std::string& expr) : _regex_str(expr), _regex(std::regex(expr)) {}
46 relabel_config_regex(const char* expr) : _regex_str(expr), _regex(std::regex(expr)) {}
47 const std::string& str() const noexcept {
48 return _regex_str;
49 }
50 const std::regex& regex() const noexcept {
51 return _regex;
52 }
53
54 relabel_config_regex& operator=(const char* expr) {
55 std::string str(expr);
56 return operator=(str);
57 }
58
59 relabel_config_regex& operator=(const std::string& expr) {
60 _regex_str = expr;
61 _regex = std::regex(_regex_str);
62 return *this;
63 }
64 bool empty() const noexcept {
65 return _regex_str.empty();
66 }
67
68 bool match(const std::string& str) const noexcept {
69 return !empty() && std::regex_match(str, _regex);
70 }
71};
72
102 enum class relabel_action {skip_when_empty, report_when_empty, replace, keep, drop, drop_label};
103 std::vector<std::string> source_labels;
104 std::string target_label;
105 std::string replacement = "${1}";
106 relabel_config_regex expr = "(.*)";
107 relabel_action action = relabel_action::replace;
108 std::string separator = ";";
109};
110
114relabel_config::relabel_action relabel_config_action(const std::string& action);
115
130 std::string name;
131 relabel_config_regex regex_name = "";
132 std::vector<std::string> aggregate_labels;
133};
134
135SEASTAR_MODULE_EXPORT_END
136
137}
138}
a wrapper class around regex with the original expr
Definition: relabel_config.hh:40
relabel_config::relabel_action relabel_config_action(const std::string &action)
a helper function to translate a string to relabel_config::relabel_action enum values
metric_family_config allow changing metrics family configuration
Definition: relabel_config.hh:129
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
a relabel_config allows changing metrics labels dynamically
Definition: relabel_config.hh:101