incubator-pegasus
incubator-pegasus copied to clipboard
Meta server crashed in prometheus-cpp library
Meta server crashed if creating a backup policy with a name test_1-1 (contains - character), the assert information is as below:
meta_server: /data/jenkins/workspace/skv/prebuild_binary-multi-arch/sub-jobs/build-develop-x86_64/thirdparty/build/Source/prometheus-cpp/core/include/prometheus/family.h:142: prometheus::Family<T>::Family(const string&, const string&, const std::map<std::basic_string<char>, std::basic_string<char> >&) [with T = prometheus::Gauge; std::string = std::basic_string<char>]: Assertion `CheckMetricName(name_)' failed.
The prometheus-cpp code:
bool CheckMetricName(const std::string& name) {
// see https://prometheus.io/docs/concepts/data_model/
auto reserved_for_internal_purposes = name.compare(0, 2, "__") == 0;
if (reserved_for_internal_purposes) return false;
#ifdef STD_REGEX_IS_BROKEN
return !name.empty();
#else
static const std::regex metric_name_regex("[a-zA-Z_:][a-zA-Z0-9_:]*");
return std::regex_match(name, metric_name_regex);
#endif
}
bool CheckLabelName(const std::string& name) {
// see https://prometheus.io/docs/concepts/data_model/
auto reserved_for_internal_purposes = name.compare(0, 2, "__") == 0;
if (reserved_for_internal_purposes) return false;
#ifdef STD_REGEX_IS_BROKEN
return !name.empty();
#else
static const std::regex label_name_regex("[a-zA-Z_][a-zA-Z0-9_]*");
return std::regex_match(name, label_name_regex);
#endif
}
So the metric name should:
- not prefixed by
__ - not empty
- match
[a-zA-Z_][a-zA-Z0-9_]*
See https://prometheus.io/docs/concepts/data_model/
Metric names:
- Metric names may contain ASCII letters, digits, underscores, and colons. It must match the regex [a-zA-Z_:][a-zA-Z0-9_:]*.
Metric labels:
- Labels may contain ASCII letters, numbers, as well as underscores. They must match the regex [a-zA-Z_][a-zA-Z0-9_]*.
- Label names beginning with __ (two "_") are reserved for internal use.
- Label values may contain any Unicode characters.
- Labels with an empty label value are considered equivalent to labels that do not exist.
Because the servers don't expose prometheus metrics directly now, this commit https://github.com/apache/incubator-pegasus/commit/bcb92f0fd30374d691d1cc5535ca0bf5ae671988 seems useless, and we can remove the prometheus-cpp library directly.
You can do this when you remove perf_counter* related code. @empiredan