Skip to content

Commit

Permalink
Merge pull request #14978 from rgacogne/ddist19-backport-14888
Browse files Browse the repository at this point in the history
dnsdist-1.9.x: Backport of 14888 - Custom metrics: better error messages, small doc improvements
  • Loading branch information
rgacogne authored Dec 16, 2024
2 parents 7c2e345 + e8a92fe commit 0126083
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 3 additions & 3 deletions pdns/dnsdistdist/dnsdist-metrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ std::variant<uint64_t, Error> incrementCustomCounter(const std::string_view& nam
metric->second.d_value += step;
return metric->second.d_value.load();
}
return std::string("Unable to increment custom metric '") + std::string(name) + "': no such metric";
return std::string("Unable to increment custom metric '") + std::string(name) + "': no such counter";
}

std::variant<uint64_t, Error> decrementCustomCounter(const std::string_view& name, uint64_t step)
Expand All @@ -214,7 +214,7 @@ std::variant<uint64_t, Error> decrementCustomCounter(const std::string_view& nam
metric->second.d_value -= step;
return metric->second.d_value.load();
}
return std::string("Unable to decrement custom metric '") + std::string(name) + "': no such metric";
return std::string("Unable to decrement custom metric '") + std::string(name) + "': no such counter";
}

std::variant<double, Error> setCustomGauge(const std::string_view& name, const double value)
Expand All @@ -226,7 +226,7 @@ std::variant<double, Error> setCustomGauge(const std::string_view& name, const d
return value;
}

return std::string("Unable to set metric '") + std::string(name) + "': no such metric";
return std::string("Unable to set metric '") + std::string(name) + "': no such gauge";
}

std::variant<double, Error> getCustomMetric(const std::string_view& name)
Expand Down
24 changes: 15 additions & 9 deletions pdns/dnsdistdist/docs/reference/custommetrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ Then you can update those at runtime using the following functions, depending on
.. versionchanged:: 1.8.1
This function can now be used at runtime, instead of only at configuration time.

Return true if declaration was successful
Re-declaring an existing metric with the same name and type will not reset it.
Re-declaring with the same name but a different type will cause one of them to be masked.

Returns true if declaration was successful.

:param str name: The name of the metric, lowercase alphanumerical characters and dashes (-) only
:param str type: The desired type in ``gauge`` or ``counter``
:param str name: The description of the metric
:param str description: The description of the metric
:param str prometheusName: The name to use in the prometheus metrics, if supplied. Otherwise the regular name will be used, prefixed with ``dnsdist_`` and ``-`` replaced by ``_``.

.. function:: incMetric(name [, step]) -> int
Expand All @@ -31,8 +34,9 @@ Then you can update those at runtime using the following functions, depending on
.. versionchanged:: 1.8.1
Optional ``step`` parameter added.

Increment counter by one (or more, see the ``step`` parameter), will issue an error if the metric is not declared or not a ``counter``
Return the new value
Increment counter by one (or more, see the ``step`` parameter), will issue an error if the metric is not declared or not a ``counter``.

Returns the new value.

:param str name: The name of the metric
:param int step: By how much the counter should be incremented, default to 1.
Expand All @@ -44,8 +48,9 @@ Then you can update those at runtime using the following functions, depending on
.. versionchanged:: 1.8.1
Optional ``step`` parameter added.

Decrement counter by one (or more, see the ``step`` parameter), will issue an error if the metric is not declared or not a ``counter``
Return the new value
Decrement counter by one (or more, see the ``step`` parameter), will issue an error if the metric is not declared or not a ``counter``.

Returns the new value.

:param str name: The name of the metric
:param int step: By how much the counter should be decremented, default to 1.
Expand All @@ -54,16 +59,17 @@ Then you can update those at runtime using the following functions, depending on

.. versionadded:: 1.8.0

Get metric value
Get metric value.

:param str name: The name of the metric

.. function:: setMetric(name, value) -> double

.. versionadded:: 1.8.0

Set the new value, will issue an error if the metric is not declared or not a ``gauge``
Return the new value
Set the new value, will issue an error if the metric is not declared or not a ``gauge``.

Return the new value.

:param str name: The name of the metric
:param double value: The new value

0 comments on commit 0126083

Please sign in to comment.