d_pd.emplace_back("now", &g_now);
+ d_lw->writeFunction("initMetric", [](const std::string& str, const std::string& maybePrometheusName, const std::string& maybePrometheusTypeName, boost::optional<std::string> maybeDescr){
+ // Shift arguments, because it's actually the second `prometheusName` argument which is optional
+ // to match the optional `prometheusName` in `getMetric`.
+ std::string prometheusName;
+ std::string prometheusTypeName;
+ std::string prometheusDescr;
+ if (maybeDescr) {
+ prometheusName = maybePrometheusName;
+ prometheusTypeName = maybePrometheusTypeName;
+ prometheusDescr = *maybeDescr;
+ } else {
+ prometheusDescr = prometheusTypeName;
+ prometheusTypeName = prometheusName;
+ prometheusName = "";
+ }
+
+ return DynMetric{initDynMetric(str, prometheusName, prometheusTypeName, prometheusDescr)};
+ });
+
d_lw->writeFunction("getMetric", [](const std::string& str, boost::optional<std::string> prometheusName) {
return DynMetric{getDynMetric(str, prometheusName ? *prometheusName : "")};
});
{
std::string d_prometheusName;
std::string d_value;
+ std::optional<std::string> d_prometheusTypeName = std::nullopt;
+ std::optional<std::string> d_prometheusDescr = std::nullopt;
};
class PrefixDashNumberCompare
std::vector<ComboAddress>* pleaseGetTimeouts();
DNSName getRegisteredName(const DNSName& dom);
std::atomic<unsigned long>* getDynMetric(const std::string& str, const std::string& prometheusName);
+std::atomic<unsigned long>* initDynMetric(const std::string& str, const std::string& prometheusName, const std::string& prometheusTypeName, const std::string& prometheusDescr);
std::optional<uint64_t> getStatByName(const std::string& name);
bool isStatDisabled(StatComponent component, const std::string& name);
void disableStat(StatComponent component, const string& name);
{
std::atomic<unsigned long>* d_ptr;
std::string d_prometheusName;
+ std::optional<string> d_prometheusTypeName;
+ std::optional<string> d_prometheusDescr;
};
static LockGuarded<map<string, dynmetrics>> d_dynmetrics;
}
std::atomic<unsigned long>* getDynMetric(const std::string& str, const std::string& prometheusName)
+{
+ return initDynMetric(str, prometheusName, "", "");
+}
+
+std::atomic<unsigned long>* initDynMetric(const std::string& str, const std::string& prometheusName, const std::string& prometheusTypeName, const std::string& prometheusDescr)
{
auto locked = d_dynmetrics.lock();
auto iter = locked->find(str);
name = getPrometheusName(name);
}
- auto ret = dynmetrics{new std::atomic<unsigned long>(), std::move(name)};
+ std::optional<std::string> typeName;
+ if (!prometheusTypeName.empty()) {
+ typeName = std::optional(std::move(prometheusTypeName));
+ }
+ std::optional<std::string> descr;
+ if (!prometheusDescr.empty()) {
+ descr = std::optional(std::move(prometheusDescr));
+ }
+
+ auto ret = dynmetrics{new std::atomic<unsigned long>(), std::move(name), typeName, descr};
(*locked)[str] = ret;
return ret.d_ptr;
}
{
for (const auto& value : *(d_dynmetrics.lock())) {
if (disabledlistMap.count(value.first) == 0) {
- ret.emplace(value.first, StatsMapEntry{value.second.d_prometheusName, std::to_string(*value.second.d_ptr)});
+ ret.emplace(value.first, StatsMapEntry{value.second.d_prometheusName, std::to_string(*value.second.d_ptr), value.second.d_prometheusTypeName, value.second.d_prometheusDescr});
}
}
}
for (const auto& tup : varmap) {
std::string metricName = tup.first;
std::string prometheusMetricName = tup.second.d_prometheusName;
+ std::string prometheusTypeName;
+ std::string prometheusDescr;
std::string helpname = tup.second.d_prometheusName;
MetricDefinition metricDetails;
if (s_metricDefinitions.getMetricDetails(metricName, metricDetails)) {
- std::string prometheusTypeName = MetricDefinitionStorage::getPrometheusStringMetricType(
+ prometheusTypeName = MetricDefinitionStorage::getPrometheusStringMetricType(
metricDetails.d_prometheusType);
+ prometheusDescr = metricDetails.d_description;
if (prometheusTypeName.empty()) {
continue;
// name is XXX_count, strip the _count part
helpname = helpname.substr(0, helpname.length() - 6);
}
+ } else {
+ if (tup.second.d_prometheusTypeName) {
+ prometheusTypeName = *tup.second.d_prometheusTypeName;
+ }
+ if (tup.second.d_prometheusDescr) {
+ prometheusDescr = *tup.second.d_prometheusDescr;
+ }
+ }
+
+ if (!prometheusTypeName.empty()) {
output << "# TYPE " << helpname << " " << prometheusTypeName << "\n";
- output << "# HELP " << helpname << " " << metricDetails.d_description << "\n";
+ }
+ if (!prometheusDescr.empty()) {
+ output << "# HELP " << helpname << " " << prometheusDescr << "\n";
}
output << prometheusMetricName << " " << tup.second.d_value << "\n";
}