Seastar
High performance C++ framework for concurrent servers
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 #ifndef SEASTAR_MODULE
22 #include <regex>
23 #endif
24 #include <seastar/util/modules.hh>
25 
26 namespace seastar {
27 namespace metrics {
28 
29 SEASTAR_MODULE_EXPORT_BEGIN
30 
38  std::string _regex_str;
39  std::regex _regex;
40 public:
41  relabel_config_regex() = default;
42  relabel_config_regex(const std::string& expr) : _regex_str(expr), _regex(std::regex(expr)) {}
43  relabel_config_regex(const char* expr) : _regex_str(expr), _regex(std::regex(expr)) {}
44  const std::string& str() const noexcept {
45  return _regex_str;
46  }
47  const std::regex& regex() const noexcept {
48  return _regex;
49  }
50 
51  relabel_config_regex& operator=(const char* expr) {
52  std::string str(expr);
53  return operator=(str);
54  }
55 
56  relabel_config_regex& operator=(const std::string& expr) {
57  _regex_str = expr;
58  _regex = std::regex(_regex_str);
59  return *this;
60  }
61 };
62 
92  enum class relabel_action {skip_when_empty, report_when_empty, replace, keep, drop, drop_label};
93  std::vector<std::string> source_labels;
94  std::string target_label;
95  std::string replacement = "${1}";
96  relabel_config_regex expr = "(.*)";
97  relabel_action action = relabel_action::replace;
98  std::string separator = ";";
99 };
100 
104 relabel_config::relabel_action relabel_config_action(const std::string& action);
105 
106 SEASTAR_MODULE_EXPORT_END
107 
108 }
109 }
a wrapper class around regex with the original expr
Definition: relabel_config.hh:37
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
Seastar API namespace.
Definition: abort_on_ebadf.hh:26
a relabel_config allows changing metrics labels dynamically
Definition: relabel_config.hh:91