Skip to content

Commit

Permalink
Implement configurable GTP RTT metrics interval (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
Viacheslav Katsuba authored Feb 1, 2021
1 parent 483399f commit c9fb5f0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions config/ergw-c-node.config
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions src/ergw_config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
{nodes, []},
{ip_pools, []},
{apns, []},
{charging, [{default, []}]}]).
{charging, [{default, []}]},
{metrics, []}]).
-define(VrfDefaults, [{features, invalid}]).
-define(ApnDefaults, [{ip_pools, []},
{bearer_type, 'IPv4v6'},
Expand Down Expand Up @@ -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]) ->
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 23 additions & 1 deletion src/ergw_prometheus.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]},
Expand All @@ -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]},
Expand Down
4 changes: 4 additions & 0 deletions test/config_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down

0 comments on commit c9fb5f0

Please sign in to comment.