diff --git a/README.md b/README.md index 70f49ced..235f036f 100644 --- a/README.md +++ b/README.md @@ -351,7 +351,11 @@ Then fill just created **ergw.config** file with content like described below pr {[<<"APN1">>], [{vrf, sgi}]} ]}, - {teid, {3, 6}}, % {teid, {Prefix, Length}} + {teid, {3, 6}}, % {teid, {Prefix, Length}} - optional, default: {0, 0} + + {metrics, [ + {gtp_path_rtt_millisecond_intervals, [10, 100]} % optional, default: [10, 30, 50, 75, 100, 1000, 2000] + ]}, {node_selection, [{default, diff --git a/config/ergw-c-node.config b/config/ergw-c-node.config index 2cd45a46..776cd1ef 100644 --- a/config/ergw-c-node.config +++ b/config/ergw-c-node.config @@ -59,6 +59,7 @@ ]}, %% {teid, {3, 6}}, % {teid, {Prefix, Length}} + %% {metrics, [{gtp_path_rtt_millisecond_intervals, [10, 30, 50, 75, 100, 1000, 2000]}]}, {node_selection, [{default, diff --git a/src/ergw_config.erl b/src/ergw_config.erl index 69d73e9a..6a403f8b 100644 --- a/src/ergw_config.erl +++ b/src/ergw_config.erl @@ -35,7 +35,8 @@ {nodes, []}, {ip_pools, []}, {apns, []}, - {charging, [{default, []}]}]). + {charging, [{default, []}]}, + {metrics, []}]). -define(VrfDefaults, [{features, invalid}]). -define(ApnDefaults, [{ip_pools, []}, {bearer_type, 'IPv4v6'}, @@ -79,7 +80,8 @@ load_env_config([{Key, Value} | T]) Key =:= charging; Key =:= proxy_map; Key =:= teid; - Key =:= node_id -> + Key =:= node_id; + Key =:= metrics -> ok = application:set_env(ergw, Key, Value), load_env_config(T); load_env_config([_ | T]) -> @@ -272,6 +274,8 @@ validate_option(path_management, Opts) when ?is_opts(Opts) -> gtp_path:validate_options(Opts); validate_option(teid, Value) -> ergw_tei_mngr:validate_option(Value); +validate_option(metrics, Opts) -> + ergw_prometheus:validate_options(Opts); validate_option(Opt, Value) when Opt == plmn_id; Opt == node_id; diff --git a/src/ergw_prometheus.erl b/src/ergw_prometheus.erl index 06052657..1f2fbeea 100644 --- a/src/ergw_prometheus.erl +++ b/src/ergw_prometheus.erl @@ -7,6 +7,8 @@ -module(ergw_prometheus). +-export([validate_options/1]). + -export([declare/0]). -export([gtp_error/3, gtp/4, gtp/5, gtp_request_duration/4, @@ -22,11 +24,31 @@ -include_lib("gtplib/include/gtp_packet.hrl"). -include_lib("pfcplib/include/pfcp_packet.hrl"). +%%%=================================================================== +%%% Options Validation +%%%=================================================================== + +-define(DefaultMetricsOpts, [{gtp_path_rtt_millisecond_intervals, [10, 30, 50, 75, 100, 1000, 2000]}]). + +validate_options(Opts) -> + ergw_config:validate_options(fun validate_option/2, Opts, ?DefaultMetricsOpts, map). + +validate_option(gtp_path_rtt_millisecond_intervals = Opt, Value) -> + case [V || V <- Value, is_integer(V), V > 0] of + [_|_] = Value -> + Value; + _ -> + throw({error, {options, {Opt, Value}}}) + end. + %%%=================================================================== %%% API %%%=================================================================== declare() -> + %% Metrics Config + {ok, Config} = application:get_env(ergw, metrics), + %% GTP path metrics prometheus_counter:declare([{name, gtp_path_messages_processed_total}, {labels, [name, remote, direction, version, type]}, @@ -45,7 +67,7 @@ declare() -> {help, "Total number of reply GTP message on path"}]), prometheus_histogram:declare([{name, gtp_path_rtt_milliseconds}, {labels, [name, ip, version, type]}, - {buckets, [10, 30, 50, 75, 100, 1000, 2000]}, + {buckets, maps:get(gtp_path_rtt_millisecond_intervals, Config)}, {help, "GTP path round trip time"}]), prometheus_gauge:declare([{name, gtp_path_contexts_total}, {labels, [name, ip, version]}, diff --git a/test/config_SUITE.erl b/test/config_SUITE.erl index 10365243..1f2dc5d5 100644 --- a/test/config_SUITE.erl +++ b/test/config_SUITE.erl @@ -920,6 +920,10 @@ config(_Config) -> ?error_option(set_cfg_value([nodes, default, request], [{timeout, invalid}], ?GGSN_CONFIG)), ?ok_option(set_cfg_value([nodes, default, request], [{timeout, 30000}, {retry, 5}], ?GGSN_CONFIG)), + ?error_option(set_cfg_value([metrics, gtp_path_rtt_millisecond_intervals], [invalid], ?GGSN_CONFIG)), + ?error_option(set_cfg_value([metrics, gtp_path_rtt_millisecond_intervals], [-100], ?GGSN_CONFIG)), + ?ok_option(set_cfg_value([metrics, gtp_path_rtt_millisecond_intervals], [10, 100], ?GGSN_CONFIG)), + ?error_option(set_cfg_value([nodes, test], [], ?GGSN_PROXY_CONFIG)), ?ok_option(set_cfg_value([nodes, "test"], [], ?GGSN_PROXY_CONFIG)), ?ok_option(set_cfg_value([nodes, "test", vrfs, cp, features], ['CP-Function'], ?GGSN_PROXY_CONFIG)),