|
| 1 | +-module(prometheus_collectors_compat). |
| 2 | +-if(?OTP_RELEASE >= 27). |
| 3 | +-define(MODULEDOC(Str), -moduledoc(Str)). |
| 4 | +-define(DOC(Str), -doc(Str)). |
| 5 | +-else. |
| 6 | +-define(MODULEDOC(Str), -compile([])). |
| 7 | +-define(DOC(Str), -compile([])). |
| 8 | +-endif. |
| 9 | + |
| 10 | +?MODULEDOC(""" |
| 11 | +Compatibility with previous collector metric names. |
| 12 | +
|
| 13 | +Up to version 6.0, some default collector metrics did not have `promtool` compliant names. |
| 14 | +The issue was fixed in version 6.0. This module is a compatibility layer for the old names. |
| 15 | +
|
| 16 | +It is disabled by default, to configure you need to set |
| 17 | +```erlang |
| 18 | +{prometheus, [ |
| 19 | + {collectors_compat, true} |
| 20 | +]} |
| 21 | +``` |
| 22 | +
|
| 23 | +This will be supported only for one major version. |
| 24 | +"""). |
| 25 | +?MODULEDOC(#{deprecated => ~"Kept for compatibility and scheduled to be removed on the next major"}). |
| 26 | + |
| 27 | +-export([pre_promtool_compat/1]). |
| 28 | +-deprecated([{'_', '_', next_major_release}]). |
| 29 | + |
| 30 | +?DOC(false). |
| 31 | +-spec pre_promtool_compat([dynamic()]) -> [dynamic()]. |
| 32 | +pre_promtool_compat(Metrics) -> |
| 33 | + case is_enabled() of |
| 34 | + true -> |
| 35 | + lists:map(fun pre_promtool_compat_fun/1, Metrics); |
| 36 | + _ -> |
| 37 | + Metrics |
| 38 | + end. |
| 39 | + |
| 40 | +pre_promtool_compat_fun({failed_transactions_total, counter, Help, Fun}) -> |
| 41 | + {failed_transactions, counter, Help, Fun}; |
| 42 | +pre_promtool_compat_fun({committed_transactions_total, counter, Help, Fun}) -> |
| 43 | + {committed_transactions, counter, Help, Fun}; |
| 44 | +pre_promtool_compat_fun({logged_transactions_total, counter, Help, Fun}) -> |
| 45 | + {logged_transactions, counter, Help, Fun}; |
| 46 | +pre_promtool_compat_fun({restarted_transactions_total, counter, Help, Fun}) -> |
| 47 | + {restarted_transactions, counter, Help, Fun}; |
| 48 | +pre_promtool_compat_fun({atom_bytes, gauge, Help, Value}) -> |
| 49 | + {atom_bytes_total, gauge, Help, Value}; |
| 50 | +pre_promtool_compat_fun({bytes, gauge, Help, Value}) -> |
| 51 | + {bytes_total, gauge, Help, Value}; |
| 52 | +pre_promtool_compat_fun({processes_bytes, gauge, Help, Value}) -> |
| 53 | + {processes_bytes_total, gauge, Help, Value}; |
| 54 | +pre_promtool_compat_fun({system_bytes, gauge, Help, Value}) -> |
| 55 | + {system_bytes_total, gauge, Help, Value}; |
| 56 | +pre_promtool_compat_fun({context_switches_total, counter, Help, Value}) -> |
| 57 | + {context_switches, counter, Help, Value}; |
| 58 | +pre_promtool_compat_fun({garbage_collection_number_of_gcs_total, counter, Help, Value}) -> |
| 59 | + {garbage_collection_number_of_gcs, counter, Help, Value}; |
| 60 | +pre_promtool_compat_fun({garbage_collection_bytes_reclaimed_total, counter, Help, Value}) -> |
| 61 | + {garbage_collection_bytes_reclaimed, counter, Help, Value}; |
| 62 | +pre_promtool_compat_fun({garbage_collection_words_reclaimed_total, counter, Help, Value}) -> |
| 63 | + {garbage_collection_words_reclaimed, counter, Help, Value}; |
| 64 | +pre_promtool_compat_fun({runtime_seconds_total, counter, Help, Value}) -> |
| 65 | + {runtime_milliseconds, counter, Help, Value}; |
| 66 | +pre_promtool_compat_fun({wallclock_time_seconds_total, counter, Help, Value}) -> |
| 67 | + {wallclock_time_milliseconds, counter, Help, Value}; |
| 68 | +pre_promtool_compat_fun({ports, gauge, Help}) -> |
| 69 | + {port_count, gauge, Help}; |
| 70 | +pre_promtool_compat_fun({processes, gauge, Help}) -> |
| 71 | + {process_count, gauge, Help}; |
| 72 | +pre_promtool_compat_fun({atoms, gauge, Help}) -> |
| 73 | + {atom_count, gauge, Help}; |
| 74 | +pre_promtool_compat_fun(Metric) -> |
| 75 | + Metric. |
| 76 | + |
| 77 | +-spec is_enabled() -> dynamic(). |
| 78 | +is_enabled() -> |
| 79 | + application:get_env(prometheus, collectors_compat, false). |
0 commit comments