@@ -500,40 +500,36 @@ std::string PrometheusExporterUtils::MapToPrometheusName(
500500 bool without_type_suffix)
501501{
502502 auto sanitized_name = SanitizeNames (name);
503- std::string prometheus_equivalent_unit;
504- if (without_units)
503+ if (!without_units)
505504 {
506- prometheus_equivalent_unit = " " ;
507- }
508- else
509- {
510- prometheus_equivalent_unit = GetEquivalentPrometheusUnit (unit);
511- }
512-
513- // Append prometheus unit if not null or empty.
514- if (!prometheus_equivalent_unit.empty () &&
515- sanitized_name.find (prometheus_equivalent_unit) == std::string::npos)
516- {
517- sanitized_name += " _" + prometheus_equivalent_unit;
518- }
519-
520- // Special case - counter
521- if (prometheus_type == prometheus_client::MetricType::Counter && !without_type_suffix)
522- {
523- auto t_pos = sanitized_name.rfind (" _total" );
524- bool ends_with_total = t_pos == sanitized_name.size () - 6 ;
525- if (!ends_with_total)
505+ std::string prometheus_equivalent_unit = GetEquivalentPrometheusUnit (unit);
506+ // Append prometheus unit if not null or empty.
507+ if (!prometheus_equivalent_unit.empty () &&
508+ sanitized_name.find (prometheus_equivalent_unit) == std::string::npos)
509+ {
510+ sanitized_name += " _" + prometheus_equivalent_unit;
511+ }
512+ // Special case - gauge
513+ if (unit == " 1" && prometheus_type == prometheus_client::MetricType::Gauge &&
514+ sanitized_name.find (" ratio" ) == std::string::npos)
526515 {
527- sanitized_name += " _total" ;
516+ // this is replacing the unit name
517+ sanitized_name += " _ratio" ;
528518 }
529519 }
530520
531- // Special case - gauge
532- if (unit == " 1" && prometheus_type == prometheus_client::MetricType::Gauge &&
533- sanitized_name.find (" ratio" ) == std::string::npos && !without_units)
521+ if (!without_type_suffix)
534522 {
535- // this is replacing the unit name
536- sanitized_name += " _ratio" ;
523+ // Special case - counter
524+ if (prometheus_type == prometheus_client::MetricType::Counter)
525+ {
526+ auto t_pos = sanitized_name.rfind (" _total" );
527+ bool ends_with_total = t_pos == sanitized_name.size () - 6 ;
528+ if (!ends_with_total)
529+ {
530+ sanitized_name += " _total" ;
531+ }
532+ }
537533 }
538534
539535 return CleanUpString (SanitizeNames (sanitized_name));
0 commit comments