Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meta server crashed in prometheus-cpp library #1965

Open
acelyc111 opened this issue Mar 27, 2024 · 1 comment
Open

Meta server crashed in prometheus-cpp library #1965

acelyc111 opened this issue Mar 27, 2024 · 1 comment
Labels
type/bug This issue reports a bug.

Comments

@acelyc111
Copy link
Member

acelyc111 commented Mar 27, 2024

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.
@acelyc111 acelyc111 added the type/bug This issue reports a bug. label Mar 27, 2024
acelyc111 added a commit that referenced this issue Apr 7, 2024
#1965

After this patch, we can use CheckMetricName() and CheckLabelName() to check metric
names and labels when register metrics.
@acelyc111
Copy link
Member Author

Because the servers don't expose prometheus metrics directly now, this commit bcb92f0 seems useless, and we can remove the prometheus-cpp library directly.

You can do this when you remove perf_counter* related code. @empiredan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug This issue reports a bug.
Projects
None yet
Development

No branches or pull requests

1 participant