apache / incubator-pegasus

Apache Pegasus - A horizontally scalable, strongly consistent and high-performance key-value store
https://pegasus.apache.org/
Apache License 2.0
1.97k stars 314 forks source link

Meta server crashed in prometheus-cpp library #1965

Open acelyc111 opened 6 months ago

acelyc111 commented 6 months ago

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:

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.
acelyc111 commented 5 months ago

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