aboutsummaryrefslogtreecommitdiffstats
path: root/test/metrics_SUITE.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2019-10-02 15:23:23 +0200
committerLoïc Hoguin <[email protected]>2019-10-02 15:23:23 +0200
commitf673e191b30ab440440c924476bb03000fff52c6 (patch)
tree0f74c7940c1a8f38ef1ca4e5e86552924072eccf /test/metrics_SUITE.erl
parenta14ecf19c68ba5b9eb828a41356b1adbc1c5739c (diff)
downloadcowboy-f673e191b30ab440440c924476bb03000fff52c6.tar.gz
cowboy-f673e191b30ab440440c924476bb03000fff52c6.tar.bz2
cowboy-f673e191b30ab440440c924476bb03000fff52c6.zip
Add {set_options, #{metrics_user_data := Map}}
This allows giving custom metadata to the metrics stream handler. This can be useful to for example provide the name of the module handling the request which is only known after routing. But any user data is allowed. When called multiple times the user data maps are merged.
Diffstat (limited to 'test/metrics_SUITE.erl')
-rw-r--r--test/metrics_SUITE.erl29
1 files changed, 20 insertions, 9 deletions
diff --git a/test/metrics_SUITE.erl b/test/metrics_SUITE.erl
index 4ead60c..d9ff7ea 100644
--- a/test/metrics_SUITE.erl
+++ b/test/metrics_SUITE.erl
@@ -76,6 +76,7 @@ init_routes(_) -> [
{"/default", default_h, []},
{"/full/:key", echo_h, []},
{"/resp/:key[/:arg]", resp_h, []},
+ {"/set_options/:key", set_options_h, []},
{"/ws_echo", ws_echo, []}
]}
].
@@ -98,9 +99,13 @@ do_metrics_callback() ->
hello_world(Config) ->
doc("Confirm metrics are correct for a normal GET request."),
- do_get("/", Config).
+ do_get("/", #{}, Config).
-do_get(Path, Config) ->
+user_data(Config) ->
+ doc("Confirm user data can be attached to metrics."),
+ do_get("/set_options/metrics_user_data", #{handler => set_options_h}, Config).
+
+do_get(Path, UserData, Config) ->
%% Perform a GET request.
ConnPid = gun_open(Config),
Ref = gun:get(ConnPid, Path, [
@@ -153,7 +158,8 @@ do_get(Path, Config) ->
streamid := 1,
reason := normal,
req := #{},
- informational := []
+ informational := [],
+ user_data := UserData
} = Metrics,
%% All good!
ok
@@ -216,7 +222,8 @@ post_body(Config) ->
streamid := 1,
reason := normal,
req := #{},
- informational := []
+ informational := [],
+ user_data := #{}
} = Metrics,
%% All good!
ok
@@ -273,7 +280,8 @@ no_resp_body(Config) ->
streamid := 1,
reason := normal,
req := #{},
- informational := []
+ informational := [],
+ user_data := #{}
} = Metrics,
%% All good!
ok
@@ -361,7 +369,7 @@ do_early_error_request_line(Config) ->
%% This test is identical to normal GET except for the handler.
stream_reply(Config) ->
doc("Confirm metrics are correct for long polling."),
- do_get("/resp/stream_reply2/200", Config).
+ do_get("/resp/stream_reply2/200", #{}, Config).
ws(Config) ->
case config(protocol, Config) of
@@ -421,7 +429,8 @@ do_ws(Config) ->
<<"sec-websocket-accept">> := _
},
time := _
- }]
+ }],
+ user_data := #{}
} = Metrics,
%% All good!
ok
@@ -487,7 +496,8 @@ error_response(Config) ->
streamid := 1,
reason := {internal_error, {'EXIT', _Pid, {crash, _StackTrace}}, 'Stream process crashed.'},
req := #{},
- informational := []
+ informational := [],
+ user_data := #{}
} = Metrics,
%% All good!
ok
@@ -546,7 +556,8 @@ error_response_after_reply(Config) ->
streamid := 1,
reason := {internal_error, {'EXIT', _Pid, {crash, _StackTrace}}, 'Stream process crashed.'},
req := #{},
- informational := []
+ informational := [],
+ user_data := #{}
} = Metrics,
%% All good!
ok