Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85823672
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
88 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/prometheus/buckets.ex b/lib/prometheus/buckets.ex
index 574045f..468ec38 100644
--- a/lib/prometheus/buckets.ex
+++ b/lib/prometheus/buckets.ex
@@ -1,48 +1,48 @@
defmodule Prometheus.Buckets do
@moduledoc """
Histogram buckets generators.
"""
use Prometheus.Erlang, :prometheus_buckets
@doc """
Default histogram buckets:
iex(2)> Prometheus.Buckets.default()
[0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10]
Please note these buckets are floats so you'll have to use `Prometheus.Metric.Histogram.dobserve/2`.
"""
defmacro default do
Erlang.call()
end
@doc """
Creates `count` buckets, each `width` wide, where the lowest
bucket has an upper bound of `start`. The returned list is meant to be
used for the `:buckets` key of histogram constructors options.
iex(2)> Prometheus.Buckets.linear(10, 5, 6)
[10, 15, 20, 25, 30, 35]
- The function raises `Prometheus.Error.InvalidValue` exception if `count` is zero or negative.
+ The function raises `Prometheus.InvalidValueError` exception if `count` is zero or negative.
"""
defmacro linear(start, step, count) do
Erlang.call([start, step, count])
end
@doc """
Creates `count` buckets, where the lowest bucket has an
upper bound of `start` and each following bucket's upper bound is `factor`
times the previous bucket's upper bound. The returned list is meant to be
used for the `:buckets` key of histogram constructors options.
- The function raises `Prometheus.Error.InvalidValue` if `count` is 0 or negative,
+ The function raises `Prometheus.InvalidValueError` if `count` is 0 or negative,
if `start` is 0 or negative, or if `factor` is less than or equal 1.
"""
defmacro exponential(start, factor, count) do
Erlang.call([start, factor, count])
end
end
diff --git a/lib/prometheus/contrib/http.ex b/lib/prometheus/contrib/http.ex
index 08fa91c..677ce7d 100644
--- a/lib/prometheus/contrib/http.ex
+++ b/lib/prometheus/contrib/http.ex
@@ -1,34 +1,34 @@
defmodule Prometheus.Contrib.HTTP do
@moduledoc """
HTTP instrumentation helpers
"""
@doc """
Default microseconds buckets for measuring http requests duration:
iex(6)> Prometheus.Contrib.HTTP.microseconds_duration_buckets
[10, 100, 1000, 10000, 100000, 300000, 500000, 750000, 1000000, 1500000,
2000000, 3000000]
"""
defmacro microseconds_duration_buckets do
:prometheus_http.microseconds_duration_buckets
end
@doc """
Returns class of http status code:
iex(7)> Prometheus.Contrib.HTTP.status_class(202)
'success'
- The function raises `Prometheus.Error.InvalidValue` exception if `code` is not a positive integer.
+ The function raises `Prometheus.InvalidValueError` exception if `code` is not a positive integer.
"""
defmacro status_class(code) do
quote do
require Prometheus.Error
Prometheus.Error.with_prometheus_error(
:prometheus_http.status_class(unquote(code))
)
end
end
end
diff --git a/lib/prometheus/error.ex b/lib/prometheus/error.ex
index 9f786b3..906fee6 100644
--- a/lib/prometheus/error.ex
+++ b/lib/prometheus/error.ex
@@ -1,190 +1,191 @@
-defmodule Prometheus.Error do
- @moduledoc false
-
- defmodule InvalidValue do
- @moduledoc """
- Raised when given `value` is invalid i.e. when you pass a negative number to `Prometheus.Metric.Counter.inc/2`.
- """
- defexception [:value, :orig_message]
-
- def message(%{value: value, orig_message: message}) do
- "Invalid value: #{value} (#{message})."
- end
+defmodule Prometheus.InvalidValueError do
+ @moduledoc """
+ Raised when given `value` is invalid i.e. when you pass a negative number to `Prometheus.Metric.Counter.inc/2`.
+ """
+ defexception [:value, :orig_message]
+
+ def message(%{value: value, orig_message: message}) do
+ "Invalid value: #{value} (#{message})."
end
+end
- defmodule InvalidMetricName do
- @moduledoc """
- Raised when given metric `name` is invalid i.e. can't be represented as printable utf-8 string that matches
- `^[a-zA-Z_:][a-zA-Z0-9_:]*$` regular expression.
- """
- defexception [:name]
+defmodule Prometheus.InvalidMetricNameError do
+ @moduledoc """
+ Raised when given metric `name` is invalid i.e. can't be represented as printable utf-8 string that matches
+ `^[a-zA-Z_:][a-zA-Z0-9_:]*$` regular expression.
+ """
+ defexception [:name]
- def message(%{name: name}) do
- "Invalid metric name: #{name}."
- end
+ def message(%{name: name}) do
+ "Invalid metric name: #{name}."
end
+end
- defmodule InvalidMetricLabels do
- @moduledoc """
- Raised when `labels` isn't a list.
- """
- defexception [:labels]
+defmodule Prometheus.InvalidMetricLabelsError do
+ @moduledoc """
+ Raised when `labels` isn't a list.
+ """
+ defexception [:labels]
- def message(%{labels: labels}) do
- "Invalid metric labels: #{labels}."
- end
+ def message(%{labels: labels}) do
+ "Invalid metric labels: #{labels}."
end
+end
- defmodule InvalidMetricHelp do
- @moduledoc """
- Raised when given metric `help` is invalid i.e. isn't a printable utf-8 string.
- """
- defexception [:help]
+defmodule Prometheus.InvalidMetricHelpError do
+ @moduledoc """
+ Raised when given metric `help` is invalid i.e. isn't a printable utf-8 string.
+ """
+ defexception [:help]
- def message(%{help: help}) do
- "Invalid metric help: #{help}."
- end
+ def message(%{help: help}) do
+ "Invalid metric help: #{help}."
end
+end
- defmodule InvalidMetricArity do
- @moduledoc """
- Raised when metric arity is invalid e.g. counter metric was created with two labels but
- only one label value is passed to `Prometheus.Metric.Counter.inc/2`.
- """
- defexception [:present, :expected]
+defmodule Prometheus.InvalidMetricArityError do
+ @moduledoc """
+ Raised when metric arity is invalid e.g. counter metric was created with two labels but
+ only one label value is passed to `Prometheus.Metric.Counter.inc/2`.
+ """
+ defexception [:present, :expected]
- def message(%{present: present, expected: expected}) do
- "Invalid metric arity: got #{present}, expected #{expected}."
- end
+ def message(%{present: present, expected: expected}) do
+ "Invalid metric arity: got #{present}, expected #{expected}."
end
+end
- defmodule UnknownMetric do
- defexception [:registry, :name]
+defmodule Prometheus.UnknownMetricError do
+ defexception [:registry, :name]
- def message(%{registry: registry, name: name}) do
- "Unknown metric {registry: #{registry}, name: #{name}}."
- end
+ def message(%{registry: registry, name: name}) do
+ "Unknown metric {registry: #{registry}, name: #{name}}."
end
+end
- defmodule InvalidLabelName do
- @moduledoc """
- Raised when label `name` is invalid i.e. can't be represented as printable utf-8 string that matches
- `^[a-zA-Z_][a-zA-Z0-9_]*$` regular expression or starts with `__`.
+defmodule Prometheus.InvalidLabelNameError do
+ @moduledoc """
+ Raised when label `name` is invalid i.e. can't be represented as printable utf-8 string that matches
+ `^[a-zA-Z_][a-zA-Z0-9_]*$` regular expression or starts with `__`.
- Metric can impose further restrictions on label names.
- """
- defexception [:name, :orig_message]
+ Metric can impose further restrictions on label names.
+ """
+ defexception [:name, :orig_message]
- def message(%{name: name, orig_message: message}) do
- "Invalid label name: #{name} (#{message})."
- end
+ def message(%{name: name, orig_message: message}) do
+ "Invalid label name: #{name} (#{message})."
end
+end
- defmodule MFAlreadyExists do
- @moduledoc """
- Raised when one tries to create metric in `registry` with `name` it already exists.
- """
- defexception [:registry, :name]
+defmodule Prometheus.MFAlreadyExistsError do
+ @moduledoc """
+ Raised when one tries to create metric in `registry` with `name` it already exists.
+ """
+ defexception [:registry, :name]
- def message(%{registry: registry, name: name}) do
- "Metric #{registry}:#{name} already exists."
- end
+ def message(%{registry: registry, name: name}) do
+ "Metric #{registry}:#{name} already exists."
end
+end
- defmodule HistogramNoBuckets do
- @moduledoc """
- Raised by histogram constructors when buckets can't be found in spec, or
- found value is empty list.
- """
- defexception [:buckets]
+defmodule Prometheus.HistogramNoBucketsError do
+ @moduledoc """
+ Raised by histogram constructors when buckets can't be found in spec, or
+ found value is empty list.
+ """
+ defexception [:buckets]
- def message(%{buckets: buckets}) do
- "Invalid histogram buckets: #{buckets}."
- end
+ def message(%{buckets: buckets}) do
+ "Invalid histogram buckets: #{buckets}."
end
+end
- defmodule HistogramInvalidBuckets do
- @moduledoc """
- Raised by histogram constructors when buckets are invalid i.e. not sorted in increasing
- order or generator spec is unknown.
- """
- defexception [:buckets, :orig_message]
+defmodule Prometheus.HistogramInvalidBucketsError do
+ @moduledoc """
+ Raised by histogram constructors when buckets are invalid i.e. not sorted in increasing
+ order or generator spec is unknown.
+ """
+ defexception [:buckets, :orig_message]
- def message(%{buckets: buckets, orig_message: message}) do
- buckets = :io_lib.format("~p", [buckets])
- "Invalid histogram buckets: #{buckets} (#{message})."
- end
+ def message(%{buckets: buckets, orig_message: message}) do
+ buckets = :io_lib.format("~p", [buckets])
+ "Invalid histogram buckets: #{buckets} (#{message})."
end
+end
- defmodule HistogramInvalidBound do
- @moduledoc """
- Raised by histogram constructors when bucket bound isn't a number.
- """
- defexception [:bound]
+defmodule Prometheus.HistogramInvalidBoundError do
+ @moduledoc """
+ Raised by histogram constructors when bucket bound isn't a number.
+ """
+ defexception [:bound]
- def message(%{bound: bound}) do
- "Invalid histogram bound: #{bound}."
- end
+ def message(%{bound: bound}) do
+ "Invalid histogram bound: #{bound}."
end
+end
- defmodule MissingMetricSpecKey do
- @moduledoc """
- Raised when required metric `spec` `key` is missing. All metrics
- require at least `name` and when metric created `help`.
+defmodule Prometheus.MissingMetricSpecKeyError do
+ @moduledoc """
+ Raised when required metric `spec` `key` is missing. All metrics
+ require at least `name` and when metric created `help`.
- Metrics can have their specific required keys.
- """
- defexception [:key, :spec]
+ Metrics can have their specific required keys.
+ """
+ defexception [:key, :spec]
- def message(%{key: key}) do
- "Required key #{key} is missing from metric spec."
- end
+ def message(%{key: key}) do
+ "Required key #{key} is missing from metric spec."
end
+end
+
+defmodule Prometheus.Error do
+ @moduledoc false
def normalize(erlang_error) do
case erlang_error do
%ErlangError{original: original} ->
case original do
{:invalid_value, value, message} ->
- %InvalidValue{value: value, orig_message: message}
+ %Prometheus.InvalidValueError{value: value, orig_message: message}
{:invalid_metric_name, name, _message} ->
- %InvalidMetricName{name: name}
+ %Prometheus.InvalidMetricNameError{name: name}
{:invalid_metric_help, help, _message} ->
- %InvalidMetricHelp{help: help}
+ %Prometheus.InvalidMetricHelpError{help: help}
{:invalid_metric_arity, present, expected} ->
- %InvalidMetricArity{present: present, expected: expected}
+ %Prometheus.InvalidMetricArityError{present: present, expected: expected}
{:unknown_metric, registry, name} ->
- %UnknownMetric{registry: registry, name: name}
+ %Prometheus.UnknownMetricError{registry: registry, name: name}
{:invalid_metric_labels, labels, _message} ->
- %InvalidMetricLabels{labels: labels}
+ %Prometheus.InvalidMetricLabelsError{labels: labels}
{:invalid_metric_label_name, name, message} ->
- %InvalidLabelName{name: name, orig_message: message}
+ %Prometheus.InvalidLabelNameError{name: name, orig_message: message}
{:mf_already_exists, {registry, name}, _message} ->
- %MFAlreadyExists{registry: registry, name: name}
+ %Prometheus.MFAlreadyExistsError{registry: registry, name: name}
{:histogram_no_buckets, buckets} ->
- %HistogramNoBuckets{buckets: buckets}
+ %Prometheus.HistogramNoBucketsError{buckets: buckets}
{:histogram_invalid_buckets, buckets, message} ->
- %HistogramInvalidBuckets{buckets: buckets, orig_message: message}
+ %Prometheus.HistogramInvalidBucketsError{buckets: buckets, orig_message: message}
{:histogram_invalid_bound, bound} ->
- %HistogramInvalidBound{bound: bound}
+ %Prometheus.HistogramInvalidBoundError{bound: bound}
{:missing_metric_spec_key, key, spec} ->
- %MissingMetricSpecKey{key: key, spec: spec}
+ %Prometheus.MissingMetricSpecKeyError{key: key, spec: spec}
_ ->
erlang_error
end
_ ->
erlang_error
end
end
defmacro with_prometheus_error(block) do
quote do
try do
unquote(block)
rescue
e in ErlangError -> reraise Prometheus.Error.normalize(e), System.stacktrace
end
end
end
+
end
diff --git a/lib/prometheus/metric/counter.ex b/lib/prometheus/metric/counter.ex
index ed439d4..1c16430 100644
--- a/lib/prometheus/metric/counter.ex
+++ b/lib/prometheus/metric/counter.ex
@@ -1,140 +1,140 @@
defmodule Prometheus.Metric.Counter do
@moduledoc """
Counter is a Metric that represents a single numerical value that only ever
goes up. That implies that it cannot be used to count items whose number can
also go down, e.g. the number of currently running processes. Those
"counters" are represented by `Prometheus.Metric.Gauge`.
A Counter is typically used to count requests served, tasks completed, errors
occurred, etc.
Example use cases for Counters:
- Number of requests processed;
- Number of items that were inserted into a queue;
- Total amount of data that a system has processed.
Use the [`rate()`](https://prometheus.io/docs/querying/functions/#rate())/
[`irate()`](https://prometheus.io/docs/querying/functions/#irate())
functions in Prometheus to calculate the rate of increase of a Counter.
By convention, the names of Counters are suffixed by `_total`.
To create a counter use either `new/1` or `declare/`, the difference is that
- `new/` will raise `Prometheus.Error.MFAlreadyExists` exception if counter with
+ `new/` will raise `Prometheus.MFAlreadyExistsError` exception if counter with
the same `registry`, `name` and `labels` combination already exists.
Both accept `spec` `Keyword` with the same set of keys:
- `:registry` - optional, default is `:default`;
- `:name` - required, can be an atom or a string;
- `:help` - required, must be a string;
- `:labels` - optional, default is `[]`.
Example:
```
defmodule MyServiceInstrumenter do
use Prometheus.Metric
## to be called at app/supervisor startup.
## to tolerate restarts use declare.
def setup() do
Counter.declare([name: :my_service_total_requests,
help: "Total requests.",
labels: [:caller]])
end
def inc(caller) do
Counter.inc([name: :my_service_total_requests,
labels: [caller]])
end
end
```
"""
use Prometheus.Erlang, :prometheus_counter
@doc """
Creates a counter using `spec`.
- Raises `Prometheus.Error.MissingMetricSpecKey` if required `spec` key is missing.<br>
- Raises `Prometheus.Error.InvalidMetricName` if metric name is invalid.<br>
- Raises `Prometheus.Error.InvalidMetricHelp` if help is invalid.<br>
- Raises `Prometheus.Error.InvalidMetricLabels` if labels isn't a list.<br>
- Raises `Prometheus.Error.InvalidMetricName` if label name is invalid.<br>
- Raises `Prometheus.Error.MFAlreadyExists` if a counter with the same `spec` already exists.
+ Raises `Prometheus.MissingMetricSpecKeyError` if required `spec` key is missing.<br>
+ Raises `Prometheus.InvalidMetricNameError` if metric name is invalid.<br>
+ Raises `Prometheus.InvalidMetricHelpError` if help is invalid.<br>
+ Raises `Prometheus.InvalidMetricLabelsError` if labels isn't a list.<br>
+ Raises `Prometheus.InvalidMetricNameError` if label name is invalid.<br>
+ Raises `Prometheus.MFAlreadyExistsError` if a counter with the same `spec` already exists.
"""
defmacro new(spec) do
Erlang.call([spec])
end
@doc """
Creates a counter using `spec`.
If a counter with the same `spec` exists returns `false`.
- Raises `Prometheus.Error.MissingMetricSpecKey` if required `spec` key is missing.<br>
- Raises `Prometheus.Error.InvalidMetricName` if metric name is invalid.<br>
- Raises `Prometheus.Error.InvalidMetricHelp` if help is invalid.<br>
- Raises `Prometheus.Error.InvalidMetricLabels` if labels isn't a list.<br>
- Raises `Prometheus.Error.InvalidMetricName` if label name is invalid.
+ Raises `Prometheus.MissingMetricSpecKeyError` if required `spec` key is missing.<br>
+ Raises `Prometheus.InvalidMetricNameError` if metric name is invalid.<br>
+ Raises `Prometheus.InvalidMetricHelpError` if help is invalid.<br>
+ Raises `Prometheus.InvalidMetricLabelsError` if labels isn't a list.<br>
+ Raises `Prometheus.InvalidMetricNameError` if label name is invalid.
"""
defmacro declare(spec) do
Erlang.call([spec])
end
@doc """
Increments the counter identified by `spec` by `value`.
- Raises `Prometheus.Error.InvalidValue` exception if `value` isn't a positive integer.<br>
- Raises `Prometheus.Error.UnknownMetric` exception if a counter for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.InvalidValueError` exception if `value` isn't a positive integer.<br>
+ Raises `Prometheus.UnknownMetricError` exception if a counter for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro inc(spec, value \\ 1) do
Erlang.metric_call(:inc, spec, [value])
end
@doc """
Increments the counter identified by `spec` by `value`.
If `value` happened to be a float number even one time(!) you shouldn't use `inc/2` after dinc.
- Raises `Prometheus.Error.InvalidValue` exception if `value` isn't a positive number.<br>
- Raises `Prometheus.Error.UnknownMetric` exception if a counter for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.InvalidValueError` exception if `value` isn't a positive number.<br>
+ Raises `Prometheus.UnknownMetricError` exception if a counter for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro dinc(spec, value \\ 1) do
Erlang.metric_call({:prometheus_counter, :dinc}, spec, [value])
end
@doc """
Removes counter series identified by spec.
- Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.UnknownMetricError` exception if a gauge for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro remove(spec) do
Erlang.metric_call(spec)
end
@doc """
Resets the value of the counter identified by `spec`.
- Raises `Prometheus.Error.UnknownMetric` exception if a counter for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.UnknownMetricError` exception if a counter for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro reset(spec) do
Erlang.metric_call(spec)
end
@doc """
Returns the value of the counter identified by `spec`. If there is no counter for
given labels combination, returns `:undefined`.
- Raises `Prometheus.Error.UnknownMetric` exception if a counter for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.UnknownMetricError` exception if a counter for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro value(spec) do
Erlang.metric_call({:prometheus_counter, :value}, spec)
end
end
diff --git a/lib/prometheus/metric/gauge.ex b/lib/prometheus/metric/gauge.ex
index 54dffea..80865c6 100644
--- a/lib/prometheus/metric/gauge.ex
+++ b/lib/prometheus/metric/gauge.ex
@@ -1,199 +1,199 @@
defmodule Prometheus.Metric.Gauge do
@moduledoc """
Gauge metric, to report instantaneous values.
Gauge is a metric that represents a single numerical value that can
arbitrarily go up and down.
A Gauge is typically used for measured values like temperatures or current
memory usage, but also "counts" that can go up and down, like the number of
running processes.
Example use cases for Gauges:
- Inprogress requests;
- Number of items in a queue;
- Free memory;
- Total memory;
- Temperature.
Example:
```
defmodule MyPoolInstrumenter do
use Prometheus.Metric
## to be called at app/supervisor startup.
## to tolerate restarts use declare.
def setup() do
Gauge.declare([name: :my_pool_size,
help: "Pool size."])
Gauge.declare([name: :my_pool_checked_out,
help: "Number of sockets checked out from the pool"])
end
def set_size(size) do
Gauge.set([name: :my_pool_size], size)
end
def track_checked_out_sockets(checkout_fun) do
Gauge.track_inprogress([name: :my_pool_checked_out], checkout_fun)
end
end
```
"""
use Prometheus.Erlang, :prometheus_gauge
@doc """
Creates a gauge using `spec`.
- Raises `Prometheus.Error.MissingMetricSpecKey` if required `spec` key is missing.<br>
- Raises `Prometheus.Error.InvalidMetricName` if metric name is invalid.<br>
- Raises `Prometheus.Error.InvalidMetricHelp` if help is invalid.<br>
- Raises `Prometheus.Error.InvalidMetricLabels` if labels isn't a list.<br>
- Raises `Prometheus.Error.InvalidMetricName` if label name is invalid.<br>
- Raises `Prometheus.Error.MFAlreadyExists` if a gauge with the same `spec` exists.
+ Raises `Prometheus.MissingMetricSpecKeyError` if required `spec` key is missing.<br>
+ Raises `Prometheus.InvalidMetricNameError` if metric name is invalid.<br>
+ Raises `Prometheus.InvalidMetricHelpError` if help is invalid.<br>
+ Raises `Prometheus.InvalidMetricLabelsError` if labels isn't a list.<br>
+ Raises `Prometheus.InvalidMetricNameError` if label name is invalid.<br>
+ Raises `Prometheus.MFAlreadyExistsError` if a gauge with the same `spec` exists.
"""
defmacro new(spec) do
Erlang.call([spec])
end
@doc """
Creates a gauge using `spec`.
If a gauge with the same `spec` exists returns `false`.
- Raises `Prometheus.Error.MissingMetricSpecKey` if required `spec` key is missing.<br>
- Raises `Prometheus.Error.InvalidMetricName` if metric name is invalid.<br>
- Raises `Prometheus.Error.InvalidMetricHelp` if help is invalid.<br>
- Raises `Prometheus.Error.InvalidMetricLabels` if labels isn't a list.<br>
- Raises `Prometheus.Error.InvalidMetricName` if label name is invalid.
+ Raises `Prometheus.MissingMetricSpecKeyError` if required `spec` key is missing.<br>
+ Raises `Prometheus.InvalidMetricNameError` if metric name is invalid.<br>
+ Raises `Prometheus.InvalidMetricHelpError` if help is invalid.<br>
+ Raises `Prometheus.InvalidMetricLabelsError` if labels isn't a list.<br>
+ Raises `Prometheus.InvalidMetricNameError` if label name is invalid.
"""
defmacro declare(spec) do
Erlang.call([spec])
end
@doc """
Sets the gauge identified by `spec` to `value`.
- Raises `Prometheus.Error.InvalidValue` exception if `value` isn't a number.<br>
- Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.InvalidValueError` exception if `value` isn't a number.<br>
+ Raises `Prometheus.UnknownMetricError` exception if a gauge for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro set(spec, value) do
Erlang.metric_call(spec, [value])
end
@doc """
Increments the gauge identified by `spec` by `value`.
- Raises `Prometheus.Error.InvalidValue` exception if `value` isn't an integer.<br>
- Raises `Prometheus.Error.UnknownMetric` exception if a counter for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.InvalidValueError` exception if `value` isn't an integer.<br>
+ Raises `Prometheus.UnknownMetricError` exception if a counter for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro inc(spec, value \\ 1) do
Erlang.metric_call(spec, [value])
end
@doc """
Decrements the gauge identified by `spec` by `value`.
- Raises `Prometheus.Error.InvalidValue` exception if `value` isn't an integer.<br>
- Raises `Prometheus.Error.UnknownMetric` exception if a counter for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.InvalidValueError` exception if `value` isn't an integer.<br>
+ Raises `Prometheus.UnknownMetricError` exception if a counter for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro dec(spec, value \\ 1) do
Erlang.metric_call(spec, [value])
end
@doc """
Increments the gauge identified by `spec` by `value`.
If `value` happened to be a float number even one time(!) you shouldn't use `inc/2` or `dec/2` after dinc.
- Raises `Prometheus.Error.InvalidValue` exception if `value` isn't a number.<br>
- Raises `Prometheus.Error.UnknownMetric` exception if a counter for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.InvalidValueError` exception if `value` isn't a number.<br>
+ Raises `Prometheus.UnknownMetricError` exception if a counter for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro dinc(spec, value \\ 1) do
Erlang.metric_call(spec, [value])
end
@doc """
Decrements the gauge identified by `spec` by `value`.
If `value` happened to be a float number even one time(!) you shouldn't use `inc/2` or `dec/2` after ddec.
- Raises `Prometheus.Error.InvalidValue` exception if `value` isn't a number.<br>
- Raises `Prometheus.Error.UnknownMetric` exception if a counter for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.InvalidValueError` exception if `value` isn't a number.<br>
+ Raises `Prometheus.UnknownMetricError` exception if a counter for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro ddec(spec, value \\ 1) do
Erlang.metric_call(spec, [value])
end
@doc """
Sets the gauge identified by `spec` to the current unixtime.
- Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.UnknownMetricError` exception if a gauge for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro set_to_current_time(spec) do
Erlang.metric_call(spec)
end
@doc """
Tracks inprogress functions.
- Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
- Raises `Prometheus.Error.InvalidValue` exception if fun isn't a function or block.
+ Raises `Prometheus.UnknownMetricError` exception if a gauge for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
+ Raises `Prometheus.InvalidValueError` exception if fun isn't a function or block.
"""
defmacro track_inprogress(spec, fun) do
Erlang.metric_call(spec, [Erlang.ensure_fn(fun)])
end
@doc """
Tracks the amount of seconds spent executing `fun`.
- Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
- Raises `Prometheus.Error.InvalidValue` exception if fun isn't a function or block.
+ Raises `Prometheus.UnknownMetricError` exception if a gauge for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
+ Raises `Prometheus.InvalidValueError` exception if fun isn't a function or block.
"""
defmacro set_duration(spec, fun) do
Erlang.metric_call(spec, [Erlang.ensure_fn(fun)])
end
@doc """
Removes gauge series identified by spec.
- Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.UnknownMetricError` exception if a gauge for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro remove(spec) do
Erlang.metric_call(spec)
end
@doc """
Resets the value of the gauge identified by `spec`.
- Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.UnknownMetricError` exception if a gauge for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro reset(spec) do
Erlang.metric_call(spec)
end
@doc """
Returns the value of the gauge identified by `spec`.
- Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.UnknownMetricError` exception if a gauge for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro value(spec) do
Erlang.metric_call(spec)
end
end
diff --git a/lib/prometheus/metric/histogram.ex b/lib/prometheus/metric/histogram.ex
index 7f91563..5040152 100644
--- a/lib/prometheus/metric/histogram.ex
+++ b/lib/prometheus/metric/histogram.ex
@@ -1,151 +1,151 @@
defmodule Prometheus.Metric.Histogram do
@moduledoc """
A Histogram tracks the size and number of events in buckets.
You can use Histograms for aggregatable calculation of quantiles.
Example use cases for Histograms:
- Response latency;
- Request size.
Histogram expects `buckets` key in a metric spec. Buckets can be:
- a list of numbers in increasing order;
- on of the generate specs (essentially shortcuts for `Prometheus.Buckets` macros)
- :default;
- {:linear, start, step, count};
- {:exponential, start, step, count}.
Example:
```
defmodule ExampleInstrumenter do
use Prometheus.Metric
## to be called at app/supervisor startup.
## to tolerate restarts use declare.
def setup do
Histogram.new([name: :http_request_duration_milliseconds,
labels: [:method],
buckets: [100, 300, 500, 750, 1000],
help: "Http Request execution time"])
end
def instrument(%{time: time, method: method}) do
Histogram.observe([name: :http_request_duration_milliseconds, labels: [method]], time)
end
end
```
"""
use Prometheus.Erlang, :prometheus_histogram
@doc """
Creates a histogram using `spec`.
Histogram cannot have a label named "le".
- Raises `Prometheus.Error.MissingMetricSpecKey` if required `spec` key is missing.<br>
- Raises `Prometheus.Error.InvalidMetricName` if metric name is invalid.<br>
- Raises `Prometheus.Error.InvalidMetricHelp` if help is invalid.<br>
- Raises `Prometheus.Error.InvalidMetricLabels` if labels isn't a list.<br>
- Raises `Prometheus.Error.InvalidMetricName` if label name is invalid.
- Raises `Prometheus.Error.MFAlreadyExists` if a histogram with the same `spec` exists.
+ Raises `Prometheus.MissingMetricSpecKeyError` if required `spec` key is missing.<br>
+ Raises `Prometheus.InvalidMetricNameError` if metric name is invalid.<br>
+ Raises `Prometheus.InvalidMetricHelpError` if help is invalid.<br>
+ Raises `Prometheus.InvalidMetricLabelsError` if labels isn't a list.<br>
+ Raises `Prometheus.InvalidMetricNameError` if label name is invalid.
+ Raises `Prometheus.MFAlreadyExistsError` if a histogram with the same `spec` exists.
Histogram Specific exceptions:
- Raises `Prometheus.Error.HistogramNoBuckets` if buckets are missing, not a list, empty list or not known buckets spec.<br>
- Raises `Prometheus.Error.HistogramInvalidBuckets` if buckets aren't in increasing order.<br>
- Raises `Prometheus.Error.HistogramInvalidBound` if bucket bound isn't a number.
+ Raises `Prometheus.HistogramNoBucketsError` if buckets are missing, not a list, empty list or not known buckets spec.<br>
+ Raises `Prometheus.HistogramInvalidBucketsError` if buckets aren't in increasing order.<br>
+ Raises `Prometheus.HistogramInvalidBoundError` if bucket bound isn't a number.
"""
defmacro new(spec) do
Erlang.call([spec])
end
@doc """
Creates a histogram using `spec`.
Histogram cannot have a label named "le".
If a histogram with the same `spec` exists returns `false`.
- Raises `Prometheus.Error.MissingMetricSpecKey` if required `spec` key is missing.<br>
- Raises `Prometheus.Error.InvalidMetricName` if metric name is invalid.<br>
- Raises `Prometheus.Error.InvalidMetricHelp` if help is invalid.<br>
- Raises `Prometheus.Error.InvalidMetricLabels` if labels isn't a list.<br>
- Raises `Prometheus.Error.InvalidMetricName` if label name is invalid.
+ Raises `Prometheus.MissingMetricSpecKeyError` if required `spec` key is missing.<br>
+ Raises `Prometheus.InvalidMetricNameError` if metric name is invalid.<br>
+ Raises `Prometheus.InvalidMetricHelpError` if help is invalid.<br>
+ Raises `Prometheus.InvalidMetricLabelsError` if labels isn't a list.<br>
+ Raises `Prometheus.InvalidMetricNameError` if label name is invalid.
Histogram Specific exceptions:
- Raises `Prometheus.Error.HistogramNoBuckets` if buckets are missing, not a list, empty list or not known buckets spec.<br>
- Raises `Prometheus.Error.HistogramInvalidBuckets` if buckets aren't in increasing order.<br>
- Raises `Prometheus.Error.HistogramInvalidBound` if bucket bound isn't a number.
+ Raises `Prometheus.HistogramNoBucketsError` if buckets are missing, not a list, empty list or not known buckets spec.<br>
+ Raises `Prometheus.HistogramInvalidBucketsError` if buckets aren't in increasing order.<br>
+ Raises `Prometheus.HistogramInvalidBoundError` if bucket bound isn't a number.
"""
defmacro declare(spec) do
Erlang.call([spec])
end
@doc """
Observes the given amount.
- Raises `Prometheus.Error.InvalidValue` exception if `amount` isn't a positive integer.<br>
- Raises `Prometheus.Error.UnknownMetric` exception if a histogram for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.InvalidValueError` exception if `amount` isn't a positive integer.<br>
+ Raises `Prometheus.UnknownMetricError` exception if a histogram for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro observe(spec, amount \\ 1) do
Erlang.metric_call(spec, [amount])
end
@doc """
Observes the given amount.
If `amount` happened to be a float number even one time(!) you shouldn't use `observe/2` after dobserve.
- Raises `Prometheus.Error.InvalidValue` exception if `amount` isn't a positive integer.<br>
- Raises `Prometheus.Error.UnknownMetric` exception if a histogram for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.InvalidValueError` exception if `amount` isn't a positive integer.<br>
+ Raises `Prometheus.UnknownMetricError` exception if a histogram for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro dobserve(spec, amount \\ 1) do
Erlang.metric_call(spec, [amount])
end
@doc """
Observes the amount of seconds spent executing `fun`.
- Raises `Prometheus.Error.UnknownMetric` exception if a histogram for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
- Raises `Prometheus.Error.InvalidValue` exception if fun isn't a function or block.
+ Raises `Prometheus.UnknownMetricError` exception if a histogram for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
+ Raises `Prometheus.InvalidValueError` exception if fun isn't a function or block.
"""
defmacro observe_duration(spec, fun) do
Erlang.metric_call(spec, [Erlang.ensure_fn(fun)])
end
@doc """
Removes histogram series identified by spec.
- Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.UnknownMetricError` exception if a gauge for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro remove(spec) do
Erlang.metric_call(spec)
end
@doc """
Resets the value of the histogram identified by `spec`.
- Raises `Prometheus.Error.UnknownMetric` exception if a histogram for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.UnknownMetricError` exception if a histogram for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro reset(spec) do
Erlang.metric_call(spec)
end
@doc """
Returns the value of the histogram identified by `spec`. If there is no histogram for
given labels combination, returns `:undefined`.
- Raises `Prometheus.Error.UnknownMetric` exception if a histogram for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.UnknownMetricError` exception if a histogram for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro value(spec) do
Erlang.metric_call(spec)
end
end
diff --git a/lib/prometheus/metric/summary.ex b/lib/prometheus/metric/summary.ex
index 0af59d9..b7e96eb 100644
--- a/lib/prometheus/metric/summary.ex
+++ b/lib/prometheus/metric/summary.ex
@@ -1,136 +1,136 @@
defmodule Prometheus.Metric.Summary do
@moduledoc """
Summary metric, to track the size of events.
Example use cases for Summaries:
- Response latency;
- Request size;
- Response size.
Example:
```
defmodule MyProxyInstrumenter do
use Prometheus.Metric
## to be called at app/supervisor startup.
## to tolerate restarts use declare.
def setup() do
Summary.declare([name: :request_size_bytes,
help: "Request size in bytes."])
Summary.declare([name: :response_size_bytes,
help: "Response size in bytes."])
end
def observe_request(size) do
Summary.observe([name: :request_size_bytes], size)
end
def observe_response(size) do
Summary.observe([name: :response_size_bytes], size)
end
end
```
"""
use Prometheus.Erlang, :prometheus_summary
@doc """
Creates a summary using `spec`.
Summary cannot have a label named "quantile".
- Raises `Prometheus.Error.MissingMetricSpecKey` if required `spec` key is missing.<br>
- Raises `Prometheus.Error.InvalidMetricName` if metric name is invalid.<br>
- Raises `Prometheus.Error.InvalidMetricHelp` if help is invalid.<br>
- Raises `Prometheus.Error.InvalidMetricLabels` if labels isn't a list.<br>
- Raises `Prometheus.Error.InvalidMetricName` if label name is invalid.<br>
- Raises `Prometheus.Error.MFAlreadyExists` if a summary with the same `spec` already exists.
+ Raises `Prometheus.MissingMetricSpecKeyError` if required `spec` key is missing.<br>
+ Raises `Prometheus.InvalidMetricNameError` if metric name is invalid.<br>
+ Raises `Prometheus.InvalidMetricHelpError` if help is invalid.<br>
+ Raises `Prometheus.InvalidMetricLabelsError` if labels isn't a list.<br>
+ Raises `Prometheus.InvalidMetricNameError` if label name is invalid.<br>
+ Raises `Prometheus.MFAlreadyExistsError` if a summary with the same `spec` already exists.
"""
defmacro new(spec) do
Erlang.call([spec])
end
@doc """
Creates a summary using `spec`.
Summary cannot have a label named "quantile".
If a summary with the same `spec` exists returns `false`.
- Raises `Prometheus.Error.MissingMetricSpecKey` if required `spec` key is missing.<br>
- Raises `Prometheus.Error.InvalidMetricName` if metric name is invalid.<br>
- Raises `Prometheus.Error.InvalidMetricHelp` if help is invalid.<br>
- Raises `Prometheus.Error.InvalidMetricLabels` if labels isn't a list.<br>
- Raises `Prometheus.Error.InvalidMetricName` if label name is invalid.
+ Raises `Prometheus.MissingMetricSpecKeyError` if required `spec` key is missing.<br>
+ Raises `Prometheus.InvalidMetricNameError` if metric name is invalid.<br>
+ Raises `Prometheus.InvalidMetricHelpError` if help is invalid.<br>
+ Raises `Prometheus.InvalidMetricLabelsError` if labels isn't a list.<br>
+ Raises `Prometheus.InvalidMetricNameError` if label name is invalid.
"""
defmacro declare(spec) do
Erlang.call([spec])
end
@doc """
Observes the given amount.
- Raises `Prometheus.Error.InvalidValue` exception if `amount` isn't a positive integer.<br>
- Raises `Prometheus.Error.UnknownMetric` exception if a summary for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.InvalidValueError` exception if `amount` isn't a positive integer.<br>
+ Raises `Prometheus.UnknownMetricError` exception if a summary for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro observe(spec, amount \\ 1) do
Erlang.metric_call(spec, [amount])
end
@doc """
Observes the given amount.
If `amount` happened to be a float number even one time(!) you shouldn't use `observe/2` after dobserve.
- Raises `Prometheus.Error.InvalidValue` exception if `amount` isn't a positive integer.<br>
- Raises `Prometheus.Error.UnknownMetric` exception if a summary for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.InvalidValueError` exception if `amount` isn't a positive integer.<br>
+ Raises `Prometheus.UnknownMetricError` exception if a summary for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro dobserve(spec, amount \\ 1) do
Erlang.metric_call(spec, [amount])
end
@doc """
Observes the amount of seconds spent executing `fun`.
- Raises `Prometheus.Error.UnknownMetric` exception if a summary for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
- Raises `Prometheus.Error.InvalidValue` exception if fun isn't a function or block.
+ Raises `Prometheus.UnknownMetricError` exception if a summary for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
+ Raises `Prometheus.InvalidValueError` exception if fun isn't a function or block.
"""
defmacro observe_duration(spec, fun) do
Erlang.metric_call(spec, [Erlang.ensure_fn(fun)])
end
@doc """
Removes summary series identified by spec.
- Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.UnknownMetricError` exception if a gauge for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro remove(spec) do
Erlang.metric_call(spec)
end
@doc """
Resets the value of the summary identified by `spec`.
- Raises `Prometheus.Error.UnknownMetric` exception if a summary for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.UnknownMetricError` exception if a summary for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro reset(spec) do
Erlang.metric_call(spec)
end
@doc """
Returns the value of the summary identified by `spec`. If there is no summary for
given labels combination, returns `:undefined`.
- Raises `Prometheus.Error.UnknownMetric` exception if a summary for `spec` can't be found.<br>
- Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
+ Raises `Prometheus.UnknownMetricError` exception if a summary for `spec` can't be found.<br>
+ Raises `Prometheus.InvalidMetricArityError` exception if labels count mismatch.
"""
defmacro value(spec) do
Erlang.metric_call(spec)
end
end
diff --git a/test/buckets_test.exs b/test/buckets_test.exs
index b03b0c5..d62b01f 100644
--- a/test/buckets_test.exs
+++ b/test/buckets_test.exs
@@ -1,34 +1,33 @@
defmodule Prometheus.BucketsTest do
use ExUnit.Case
use Prometheus
- alias Prometheus.Error
doctest Prometheus.Buckets
test "linear buckets generator tests" do
- assert_raise Error.InvalidValue, fn ->
+ assert_raise Prometheus.InvalidValueError, fn ->
Prometheus.Buckets.linear(-15, 5, 0)
end
assert [-15, -10, -5, 0, 5, 10] == Prometheus.Buckets.linear(-15, 5, 6)
end
test "exponential buckets generator tests" do
- assert_raise Error.InvalidValue, fn ->
+ assert_raise Prometheus.InvalidValueError, fn ->
Prometheus.Buckets.exponential(-15, 5, 0)
end
- assert_raise Error.InvalidValue, fn ->
+ assert_raise Prometheus.InvalidValueError, fn ->
Prometheus.Buckets.exponential(-15, 5, 2)
end
- assert_raise Error.InvalidValue, fn ->
+ assert_raise Prometheus.InvalidValueError, fn ->
Prometheus.Buckets.exponential(15, 0.5, 3)
end
assert [100, 120, 144] == Prometheus.Buckets.exponential(100, 1.2, 3)
end
test "default buckets test" do
assert [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10] == Prometheus.Buckets.default
end
end
diff --git a/test/error_test.exs b/test/error_test.exs
index 831be0f..76d7154 100644
--- a/test/error_test.exs
+++ b/test/error_test.exs
@@ -1,20 +1,21 @@
defmodule Prometheus.ErrorTest do
use Prometheus.Case
+ require Prometheus.Error
def erlang_error do
raise ErlangError
end
test "properly proxies unknown exceptions" do
assert_raise ArgumentError,
fn ->
Prometheus.Error.with_prometheus_error :ets.tab2list(:qweqweqwe)
end
assert_raise ErlangError,
fn ->
Prometheus.Error.with_prometheus_error erlang_error
end
end
end
diff --git a/test/metric/counter_test.exs b/test/metric/counter_test.exs
index 6aca51b..cbcd1bd 100644
--- a/test/metric/counter_test.exs
+++ b/test/metric/counter_test.exs
@@ -1,209 +1,209 @@
defmodule Prometheus.CounterTest do
use Prometheus.Case
test "registration" do
spec = [name: :name,
help: "",
registry: :qwe]
assert true == Counter.declare(spec)
assert false == Counter.declare(spec)
- assert_raise Prometheus.Error.MFAlreadyExists,
+ assert_raise Prometheus.MFAlreadyExistsError,
"Metric qwe:name already exists.",
fn ->
Counter.new(spec)
end
end
test "spec errors" do
- assert_raise Prometheus.Error.MissingMetricSpecKey,
+ assert_raise Prometheus.MissingMetricSpecKeyError,
"Required key name is missing from metric spec.",
fn ->
Counter.new([help: ""])
end
- assert_raise Prometheus.Error.InvalidMetricName,
+ assert_raise Prometheus.InvalidMetricNameError,
"Invalid metric name: 12.",
fn ->
Counter.new([name: 12, help: ""])
end
- assert_raise Prometheus.Error.InvalidMetricLabels,
+ assert_raise Prometheus.InvalidMetricLabelsError,
"Invalid metric labels: 12.",
fn ->
Counter.new([name: "qwe", labels: 12, help: ""])
end
- assert_raise Prometheus.Error.InvalidMetricHelp,
+ assert_raise Prometheus.InvalidMetricHelpError,
"Invalid metric help: 12.",
fn ->
Counter.new([name: "qwe", help: 12])
end
end
test "counter specific errors" do
spec = [name: :http_requests_total,
help: ""]
## inc
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: -1 (inc accepts only non-negative integers).",
fn ->
Counter.inc(spec, -1)
end
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: 1.5 (inc accepts only non-negative integers).",
fn ->
Counter.inc(spec, 1.5)
end
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: qwe (inc accepts only non-negative integers).",
fn ->
Counter.inc(spec, "qwe")
end
## dinc
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: -1 (dinc accepts only non-negative numbers).",
fn ->
Counter.dinc(spec, -1)
end
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: qwe (dinc accepts only non-negative numbers).",
fn ->
Counter.dinc(spec, "qwe")
end
end
test "mf/arity errors" do
spec = [name: :metric_with_label,
labels: [:label],
help: ""]
Counter.declare(spec)
## inc
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Counter.inc(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Counter.inc([name: :metric_with_label, labels: [:l1, :l2]])
end
## dinc
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Counter.dinc(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Counter.dinc([name: :metric_with_label, labels: [:l1, :l2]])
end
## remove
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Counter.remove(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Counter.remove([name: :metric_with_label, labels: [:l1, :l2]])
end
## reset
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Counter.reset(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Counter.reset([name: :metric_with_label, labels: [:l1, :l2]])
end
## value
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Counter.value(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Counter.value([name: :metric_with_label, labels: [:l1, :l2]])
end
end
test "inc" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Counter.new(spec)
Counter.inc(spec)
Counter.inc(spec, 3)
assert 4 == Counter.value(spec)
Counter.reset(spec)
assert 0 == Counter.value(spec)
end
test "dinc" do
spec = [name: :http_requests_total,
help: ""]
Counter.new(spec)
Counter.dinc(spec)
Counter.dinc(spec, 3.5)
## dinc is async so lets make sure gen_server processed our increment request
Process.sleep(10)
assert 4.5 == Counter.value(spec)
Counter.reset(spec)
assert 0 == Counter.value(spec)
end
test "undefined value" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Counter.new(spec)
assert :undefined == Counter.value(spec)
end
test "remove" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
wl_spec = [name: :simple_counter,
help: ""]
Counter.new(spec)
Counter.new(wl_spec)
Counter.inc(spec)
Counter.inc(wl_spec)
assert 1 == Counter.value(spec)
assert 1 == Counter.value(wl_spec)
assert true == Counter.remove(spec)
assert true == Counter.remove(wl_spec)
assert :undefined == Counter.value(spec)
assert :undefined == Counter.value(wl_spec)
assert false == Counter.remove(spec)
assert false == Counter.remove(wl_spec)
end
end
diff --git a/test/metric/gauge_test.exs b/test/metric/gauge_test.exs
index 50e234d..3f1f7ce 100644
--- a/test/metric/gauge_test.exs
+++ b/test/metric/gauge_test.exs
@@ -1,461 +1,461 @@
defmodule Prometheus.GaugeTest do
use Prometheus.Case
test "registration" do
spec = [name: :name,
help: "",
registry: :qwe]
assert true == Gauge.declare(spec)
assert false == Gauge.declare(spec)
- assert_raise Prometheus.Error.MFAlreadyExists,
+ assert_raise Prometheus.MFAlreadyExistsError,
"Metric qwe:name already exists.",
fn ->
Gauge.new(spec)
end
end
test "spec errors" do
- assert_raise Prometheus.Error.MissingMetricSpecKey,
+ assert_raise Prometheus.MissingMetricSpecKeyError,
"Required key name is missing from metric spec.",
fn ->
Gauge.new([help: ""])
end
- assert_raise Prometheus.Error.InvalidMetricName,
+ assert_raise Prometheus.InvalidMetricNameError,
"Invalid metric name: 12.",
fn ->
Gauge.new([name: 12, help: ""])
end
- assert_raise Prometheus.Error.InvalidMetricLabels,
+ assert_raise Prometheus.InvalidMetricLabelsError,
"Invalid metric labels: 12.",
fn ->
Gauge.new([name: "qwe", labels: 12, help: ""])
end
- assert_raise Prometheus.Error.InvalidMetricHelp,
+ assert_raise Prometheus.InvalidMetricHelpError,
"Invalid metric help: 12.",
fn ->
Gauge.new([name: "qwe", help: 12])
end
end
test "gauge specific errors" do
spec = [name: :http_requests_total,
help: ""]
## set
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: qwe (set accepts only numbers).",
fn ->
Gauge.set(spec, "qwe")
end
## inc
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: qwe (inc accepts only integers).",
fn ->
Gauge.inc(spec, "qwe")
end
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: -1.5 (inc accepts only integers).",
fn ->
Gauge.inc(spec, -1.5)
end
## dec
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: qwe (dec accepts only integers).",
fn ->
Gauge.dec(spec, "qwe")
end
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: -1.5 (dec accepts only integers).",
fn ->
Gauge.dec(spec, -1.5)
end
## dinc
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: qwe (dinc accepts only numbers).",
fn ->
Gauge.dinc(spec, "qwe")
end
## ddec
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: qwe (ddec accepts only numbers).",
fn ->
Gauge.ddec(spec, "qwe")
end
## track_inprogress
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: qwe (track_inprogress accepts only functions).",
fn ->
Gauge.track_inprogress(spec, "qwe")
end
## set_duration
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: qwe (set_duration accepts only functions).",
fn ->
Gauge.set_duration(spec, "qwe")
end
end
test "mf/arity errors" do
spec = [name: :metric_with_label,
labels: [:label],
help: ""]
Gauge.declare(spec)
## set
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Gauge.set(:unknown_metric, 1)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Gauge.set([name: :metric_with_label, labels: [:l1, :l2]], 1)
end
## inc
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Gauge.inc(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Gauge.inc([name: :metric_with_label, labels: [:l1, :l2]])
end
## dinc
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Gauge.dinc(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Gauge.dinc([name: :metric_with_label, labels: [:l1, :l2]])
end
## dec
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Gauge.dec(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Gauge.dec([name: :metric_with_label, labels: [:l1, :l2]])
end
## ddec
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Gauge.ddec(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Gauge.ddec([name: :metric_with_label, labels: [:l1, :l2]])
end
## set_to_current_time
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Gauge.set_to_current_time(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Gauge.set_to_current_time([name: :metric_with_label, labels: [:l1, :l2]])
end
## track_inprogress
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Gauge.track_inprogress(:unknown_metric, fn -> 1 end)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Gauge.track_inprogress([name: :metric_with_label, labels: [:l1, :l2]], fn -> 1 end)
end
## set_duration
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Gauge.set_duration(:unknown_metric, fn -> 1 end)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Gauge.set_duration([name: :metric_with_label, labels: [:l1, :l2]], fn -> 1 end)
end
## remove
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Gauge.remove(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Gauge.remove([name: :metric_with_label, labels: [:l1, :l2]])
end
## reset
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Gauge.reset(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Gauge.reset([name: :metric_with_label, labels: [:l1, :l2]])
end
## value
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Gauge.value(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Gauge.value([name: :metric_with_label, labels: [:l1, :l2]])
end
end
test "set" do
spec = [name: :metric_with_label,
labels: [:label],
help: ""]
Gauge.declare(spec)
Gauge.set(spec, 100)
assert 100 == Gauge.value(spec)
Gauge.set(spec, 105)
assert 105 == Gauge.value(spec)
Gauge.reset(spec)
assert 0 == Gauge.value(spec)
end
test "inc" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Gauge.new(spec)
Gauge.inc(spec)
Gauge.inc(spec, 3)
assert 4 == Gauge.value(spec)
Gauge.reset(spec)
assert 0 == Gauge.value(spec)
end
test "dinc" do
spec = [name: :http_requests_total,
help: ""]
Gauge.new(spec)
Gauge.dinc(spec)
Gauge.dinc(spec, 3.5)
## dinc is async so lets make sure gen_server processed our increment request
Process.sleep(10)
assert 4.5 == Gauge.value(spec)
Gauge.reset(spec)
assert 0 == Gauge.value(spec)
end
test "dec" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Gauge.new(spec)
Gauge.dec(spec)
Gauge.dec(spec, 3)
assert -4 == Gauge.value(spec)
Gauge.reset(spec)
assert 0 == Gauge.value(spec)
end
test "ddec" do
spec = [name: :http_requests_total,
help: ""]
Gauge.new(spec)
Gauge.ddec(spec)
Gauge.ddec(spec, 3.5)
## ddec is async so lets make sure gen_server processed our increment request
Process.sleep(10)
assert -4.5 == Gauge.value(spec)
Gauge.reset(spec)
assert 0 == Gauge.value(spec)
end
test "set_to_current_time" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Gauge.new(spec)
Gauge.set_to_current_time(spec)
assert :os.system_time(:seconds) == Gauge.value(spec)
end
test "test_track_inprogress fn" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Gauge.new(spec)
assert 1 == Gauge.track_inprogress(spec, fn ->
Gauge.value(spec)
end)
assert_raise ErlangError, fn ->
Gauge.track_inprogress(spec, fn ->
:erlang.error({:qwe})
end)
end
assert 0 = Gauge.value(spec)
end
test "test_track_inprogress block" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Gauge.new(spec)
assert 1 == Gauge.track_inprogress(spec, do: Gauge.value(spec))
assert_raise ErlangError, fn ->
Gauge.track_inprogress spec do
:erlang.error({:qwe})
end
end
assert 0 = Gauge.value(spec)
end
test "set_duration fn" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Gauge.new(spec)
assert 1 == Gauge.set_duration(spec, fn ->
Process.sleep(1000)
1
end)
## set_duration is async so lets make sure gen_server processed our increment request
Process.sleep(10)
assert 1 < Gauge.value(spec) and Gauge.value(spec) < 1.2
assert_raise ErlangError, fn ->
Gauge.set_duration(spec, fn ->
:erlang.error({:qwe})
end)
end
## set_duration is async so lets make sure gen_server processed our increment request
Process.sleep(10)
assert 0.0 < Gauge.value(spec) and Gauge.value(spec) < 0.2
end
test "set_duration block" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Gauge.new(spec)
assert :ok == Gauge.set_duration(spec, do: Process.sleep(1000))
## set_duration is async so lets make sure gen_server processed our increment request
Process.sleep(10)
assert 1 < Gauge.value(spec) and Gauge.value(spec) < 1.2
assert_raise ErlangError, fn ->
Gauge.set_duration spec do
:erlang.error({:qwe})
end
end
## set_duration is async so lets make sure gen_server processed our increment request
Process.sleep(10)
assert 0.0 < Gauge.value(spec) and Gauge.value(spec) < 0.2
end
test "undefined value" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Gauge.new(spec)
assert :undefined == Gauge.value(spec)
end
test "remove" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
wl_spec = [name: :simple_gauge,
help: ""]
Gauge.new(spec)
Gauge.new(wl_spec)
Gauge.inc(spec)
Gauge.inc(wl_spec)
assert 1 == Gauge.value(spec)
assert 1 == Gauge.value(wl_spec)
assert true == Gauge.remove(spec)
assert true == Gauge.remove(wl_spec)
assert :undefined == Gauge.value(spec)
assert :undefined == Gauge.value(wl_spec)
assert false == Gauge.remove(spec)
assert false == Gauge.remove(wl_spec)
end
end
diff --git a/test/metric/histogram_test.exs b/test/metric/histogram_test.exs
index fe11ea1..59170c8 100644
--- a/test/metric/histogram_test.exs
+++ b/test/metric/histogram_test.exs
@@ -1,306 +1,306 @@
defmodule Prometheus.HistogramTest do
use Prometheus.Case
test "registration" do
spec = [name: :name,
help: "",
registry: :qwe]
assert true == Histogram.declare(spec)
assert false == Histogram.declare(spec)
- assert_raise Prometheus.Error.MFAlreadyExists,
+ assert_raise Prometheus.MFAlreadyExistsError,
"Metric qwe:name already exists.",
fn ->
Histogram.new(spec)
end
end
test "spec errors" do
- assert_raise Prometheus.Error.MissingMetricSpecKey,
+ assert_raise Prometheus.MissingMetricSpecKeyError,
"Required key name is missing from metric spec.",
fn ->
Histogram.new([help: ""])
end
- assert_raise Prometheus.Error.InvalidMetricName,
+ assert_raise Prometheus.InvalidMetricNameError,
"Invalid metric name: 12.",
fn ->
Histogram.new([name: 12, help: ""])
end
- assert_raise Prometheus.Error.InvalidMetricLabels,
+ assert_raise Prometheus.InvalidMetricLabelsError,
"Invalid metric labels: 12.",
fn ->
Histogram.new([name: "qwe", labels: 12, help: ""])
end
- assert_raise Prometheus.Error.InvalidMetricHelp,
+ assert_raise Prometheus.InvalidMetricHelpError,
"Invalid metric help: 12.",
fn ->
Histogram.new([name: "qwe", help: 12])
end
- assert_raise Prometheus.Error.InvalidLabelName,
+ assert_raise Prometheus.InvalidLabelNameError,
"Invalid label name: le (histogram cannot have a label named \"le\").",
fn ->
Histogram.new([name: "qwe", help: "", labels: ["le"]])
end
## buckets
- assert_raise Prometheus.Error.HistogramNoBuckets,
+ assert_raise Prometheus.HistogramNoBucketsError,
"Invalid histogram buckets: .",
fn ->
Histogram.new([name: "qwe", help: "", buckets: []])
end
- assert_raise Prometheus.Error.HistogramNoBuckets,
+ assert_raise Prometheus.HistogramNoBucketsError,
"Invalid histogram buckets: undefined.",
fn ->
Histogram.new([name: "qwe", help: "", buckets: :undefined])
end
- assert_raise Prometheus.Error.HistogramInvalidBuckets,
+ assert_raise Prometheus.HistogramInvalidBucketsError,
"Invalid histogram buckets: 1 (not a list).",
fn ->
Histogram.new([name: "qwe", help: "", buckets: 1])
end
- assert_raise Prometheus.Error.HistogramInvalidBuckets,
+ assert_raise Prometheus.HistogramInvalidBucketsError,
"Invalid histogram buckets: [1,3,2] (buckets not sorted).",
fn ->
Histogram.new([name: "qwe", help: "", buckets: [1, 3, 2]])
end
- assert_raise Prometheus.Error.HistogramInvalidBound,
+ assert_raise Prometheus.HistogramInvalidBoundError,
"Invalid histogram bound: qwe.",
fn ->
Histogram.new([name: "qwe", help: "", buckets: ["qwe"]])
end
end
test "histogram specific errors" do
spec = [name: :http_requests_total,
help: ""]
## observe
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: qwe (observe accepts only integers).",
fn ->
Histogram.observe(spec, "qwe")
end
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: 1.5 (observe accepts only integers).",
fn ->
Histogram.observe(spec, 1.5)
end
## dobserve
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: qwe (dobserve accepts only numbers).",
fn ->
Histogram.dobserve(spec, "qwe")
end
## observe_duration
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: qwe (observe_duration accepts only functions).",
fn ->
Histogram.observe_duration(spec, "qwe")
end
end
test "mf/arity errors" do
spec = [name: :metric_with_label,
labels: [:label],
help: ""]
Histogram.declare(spec)
## observe
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Histogram.observe(:unknown_metric, 1)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Histogram.observe([name: :metric_with_label, labels: [:l1, :l2]], 1)
end
## dobserve
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Histogram.dobserve(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Histogram.dobserve([name: :metric_with_label, labels: [:l1, :l2]])
end
## observe_duration
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Histogram.observe_duration(:unknown_metric, fn -> 1 end)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Histogram.observe_duration([name: :metric_with_label, labels: [:l1, :l2]], fn -> 1 end)
end
## remove
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Histogram.remove(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Histogram.remove([name: :metric_with_label, labels: [:l1, :l2]])
end
## reset
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Histogram.reset(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Histogram.reset([name: :metric_with_label, labels: [:l1, :l2]])
end
## value
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Histogram.value(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Histogram.value([name: :metric_with_label, labels: [:l1, :l2]])
end
end
test "observe" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Histogram.new(spec)
Histogram.observe(spec)
Histogram.observe(spec, 3)
assert {[0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0], 4} == Histogram.value(spec)
Histogram.reset(spec)
assert {[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 0} == Histogram.value(spec)
end
test "dobserve" do
spec = [name: :http_requests_total,
help: ""]
Histogram.new(spec)
Histogram.dobserve(spec)
Histogram.dobserve(spec, 3.5)
## dobserve is async so lets make sure gen_server processed our increment request
Process.sleep(10)
assert {[0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0], 4.5} == Histogram.value(spec)
Histogram.reset(spec)
assert {[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 0} == Histogram.value(spec)
end
test "observe_duration fn" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Histogram.new(spec)
assert 1 == Histogram.observe_duration(spec, fn ->
Process.sleep(1000)
1
end)
## observe_duration is async so lets make sure gen_server processed our increment request
Process.sleep(10)
{buckets, sum} = Histogram.value(spec)
assert [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0] == buckets
assert 1 < sum and sum < 1.2
assert_raise ErlangError, fn ->
Histogram.observe_duration(spec, fn ->
:erlang.error({:qwe})
end)
end
## observe_duration is async so lets make sure gen_server processed our increment request
Process.sleep(10)
{buckets, sum} = Histogram.value(spec)
assert [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0] == buckets
assert 1 < sum and sum < 1.2
end
test "observe_duration block" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Histogram.new(spec)
assert :ok == Histogram.observe_duration(spec, do: Process.sleep(1000))
## observe_duration is async so lets make sure gen_server processed our increment request
Process.sleep(10)
{buckets, sum} = Histogram.value(spec)
assert [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0] == buckets
assert 1 < sum and sum < 1.2
assert_raise ErlangError, fn ->
Histogram.observe_duration spec do
:erlang.error({:qwe})
end
end
## observe_duration is async so lets make sure gen_server processed our increment request
Process.sleep(10)
{buckets, sum} = Histogram.value(spec)
assert [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0] == buckets
assert 1 < sum and sum < 1.2
end
test "undefined value" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Histogram.new(spec)
assert :undefined == Histogram.value(spec)
end
test "remove" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
wl_spec = [name: :simple_histogram,
help: ""]
Histogram.new(spec)
Histogram.new(wl_spec)
Histogram.observe(spec)
Histogram.observe(wl_spec)
assert {[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], 1} == Histogram.value(spec)
assert {[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0], 1} == Histogram.value(wl_spec)
assert true == Histogram.remove(spec)
assert true == Histogram.remove(wl_spec)
assert :undefined == Histogram.value(spec)
assert :undefined == Histogram.value(wl_spec)
assert false == Histogram.remove(spec)
assert false == Histogram.remove(wl_spec)
end
end
diff --git a/test/metric/summary_test.exs b/test/metric/summary_test.exs
index 9664768..2381c94 100644
--- a/test/metric/summary_test.exs
+++ b/test/metric/summary_test.exs
@@ -1,280 +1,280 @@
defmodule Prometheus.SummaryTest do
use Prometheus.Case
test "registration" do
spec = [name: :name,
help: "",
registry: :qwe]
assert true == Summary.declare(spec)
assert false == Summary.declare(spec)
- assert_raise Prometheus.Error.MFAlreadyExists,
+ assert_raise Prometheus.MFAlreadyExistsError,
"Metric qwe:name already exists.",
fn ->
Summary.new(spec)
end
end
test "spec errors" do
- assert_raise Prometheus.Error.MissingMetricSpecKey,
+ assert_raise Prometheus.MissingMetricSpecKeyError,
"Required key name is missing from metric spec.",
fn ->
Summary.new([help: ""])
end
- assert_raise Prometheus.Error.InvalidMetricName,
+ assert_raise Prometheus.InvalidMetricNameError,
"Invalid metric name: 12.",
fn ->
Summary.new([name: 12, help: ""])
end
- assert_raise Prometheus.Error.InvalidMetricLabels,
+ assert_raise Prometheus.InvalidMetricLabelsError,
"Invalid metric labels: 12.",
fn ->
Summary.new([name: "qwe", labels: 12, help: ""])
end
- assert_raise Prometheus.Error.InvalidMetricHelp,
+ assert_raise Prometheus.InvalidMetricHelpError,
"Invalid metric help: 12.",
fn ->
Summary.new([name: "qwe", help: 12])
end
- assert_raise Prometheus.Error.InvalidLabelName,
+ assert_raise Prometheus.InvalidLabelNameError,
"Invalid label name: quantile (summary cannot have a label named \"quantile\").",
fn ->
Summary.new([name: "qwe", help: "", labels: ["quantile"]])
end
end
test "summary specific errors" do
spec = [name: :http_requests_total,
help: ""]
## observe
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: qwe (observe accepts only integers).",
fn ->
Summary.observe(spec, "qwe")
end
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: 1.5 (observe accepts only integers).",
fn ->
Summary.observe(spec, 1.5)
end
## dobserve
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: qwe (dobserve accepts only numbers).",
fn ->
Summary.dobserve(spec, "qwe")
end
## observe_duration
- assert_raise Prometheus.Error.InvalidValue,
+ assert_raise Prometheus.InvalidValueError,
"Invalid value: qwe (observe_duration accepts only functions).",
fn ->
Summary.observe_duration(spec, "qwe")
end
end
test "mf/arity errors" do
spec = [name: :metric_with_label,
labels: [:label],
help: ""]
Summary.declare(spec)
## observe
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Summary.observe(:unknown_metric, 1)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Summary.observe([name: :metric_with_label, labels: [:l1, :l2]], 1)
end
## dobserve
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Summary.dobserve(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Summary.dobserve([name: :metric_with_label, labels: [:l1, :l2]])
end
## observe_duration
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Summary.observe_duration(:unknown_metric, fn -> 1 end)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Summary.observe_duration([name: :metric_with_label, labels: [:l1, :l2]], fn -> 1 end)
end
## remove
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Summary.remove(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Summary.remove([name: :metric_with_label, labels: [:l1, :l2]])
end
## reset
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Summary.reset(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Summary.reset([name: :metric_with_label, labels: [:l1, :l2]])
end
## value
- assert_raise Prometheus.Error.UnknownMetric,
+ assert_raise Prometheus.UnknownMetricError,
"Unknown metric {registry: default, name: unknown_metric}.",
fn ->
Summary.value(:unknown_metric)
end
- assert_raise Prometheus.Error.InvalidMetricArity,
+ assert_raise Prometheus.InvalidMetricArityError,
"Invalid metric arity: got 2, expected 1.",
fn ->
Summary.value([name: :metric_with_label, labels: [:l1, :l2]])
end
end
test "observe" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Summary.new(spec)
Summary.observe(spec)
Summary.observe(spec, 3)
assert {2, 4} == Summary.value(spec)
Summary.reset(spec)
assert {0, 0} == Summary.value(spec)
end
test "dobserve" do
spec = [name: :http_requests_total,
help: ""]
Summary.new(spec)
Summary.dobserve(spec)
Summary.dobserve(spec, 3.5)
## dobserve is async so lets make sure gen_server processed our increment request
Process.sleep(10)
assert {2, 4.5} == Summary.value(spec)
Summary.reset(spec)
assert {0, 0} == Summary.value(spec)
end
test "observe_duration fn" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Summary.new(spec)
assert 1 == Summary.observe_duration(spec, fn ->
Process.sleep(1000)
1
end)
## observe_duration is async so lets make sure gen_server processed our increment request
Process.sleep(10)
{count, sum} = Summary.value(spec)
assert 1 == count
assert 1 < sum and sum < 1.2
assert_raise ErlangError, fn ->
Summary.observe_duration(spec, fn ->
:erlang.error({:qwe})
end)
end
## observe_duration is async so lets make sure gen_server processed our increment request
Process.sleep(10)
{count, sum} = Summary.value(spec)
assert 2 == count
assert 1 < sum and sum < 1.2
end
test "observe_duration block" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Summary.new(spec)
assert :ok == Summary.observe_duration(spec, do: Process.sleep(1000))
## observe_duration is async so lets make sure gen_server processed our increment request
Process.sleep(10)
{count, sum} = Summary.value(spec)
assert 1 == count
assert 1 < sum and sum < 1.2
assert_raise ErlangError, fn ->
Summary.observe_duration spec do
:erlang.error({:qwe})
end
end
## observe_duration is async so lets make sure gen_server processed our increment request
Process.sleep(10)
{count, sum} = Summary.value(spec)
assert 2 == count
assert 1 < sum and sum < 1.2
end
test "undefined value" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
Summary.new(spec)
assert :undefined == Summary.value(spec)
end
test "remove" do
spec = [name: :http_requests_total,
labels: [:method],
help: ""]
wl_spec = [name: :simple_summary,
help: ""]
Summary.new(spec)
Summary.new(wl_spec)
Summary.observe(spec)
Summary.observe(wl_spec)
assert {1, 1} == Summary.value(spec)
assert {1, 1} == Summary.value(wl_spec)
assert true == Summary.remove(spec)
assert true == Summary.remove(wl_spec)
assert :undefined == Summary.value(spec)
assert :undefined == Summary.value(wl_spec)
assert false == Summary.remove(spec)
assert false == Summary.remove(wl_spec)
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Oct 29, 8:04 AM (12 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1797762
Default Alt Text
(88 KB)
Attached To
Mode
R26 prometheus.ex
Attached
Detach File
Event Timeline