-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PISTON-542: add the cf_acdc_wait_time module (#4619)
PISTON-542: move cf_acdc_wait_time module into acdc app PISTON-542: fixes for master, remove custom KVs code PISTON-542: make code_checks PISTON-542: make docs PISTON-542: add documentation of cf_acdc_wait_time module purpose PISTON-556: acdc average wait time req custom window Conflicts: applications/acdc/src/acdc_stats.erl applications/acdc/src/cf_acdc_wait_time.erl applications/callflow/doc/acdc_wait_time.md applications/callflow/doc/ref/acdc_wait_time.md applications/crossbar/priv/api/swagger.json applications/crossbar/priv/couchdb/schemas/callflows.acdc_wait_time.json address edoc
- Loading branch information
1 parent
3a75fa9
commit b870ca0
Showing
9 changed files
with
191 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
%%%----------------------------------------------------------------------------- | ||
%%% @copyright (C) 2018-, Voxter Communications Inc | ||
%%% @doc Handles branching the callflow based on the current average wait time | ||
%%% of a queue | ||
%%% Data: { | ||
%%% "id":"queue id", | ||
%%% "window":900 // Window over which average wait time is calc'd | ||
%%% } | ||
%%% | ||
%%% | ||
%%% @author Daniel Finke | ||
%%% @end | ||
%%%----------------------------------------------------------------------------- | ||
-module(cf_acdc_wait_time). | ||
|
||
-export([handle/2]). | ||
|
||
-include_lib("callflow/src/callflow.hrl"). | ||
|
||
%%------------------------------------------------------------------------------ | ||
%% @doc Handle execution of this callflow module | ||
%% @end | ||
%%------------------------------------------------------------------------------ | ||
-spec handle(kz_json:object(), kapps_call:call()) -> 'ok'. | ||
handle(Data, Call) -> | ||
AccountId = kapps_call:account_id(Call), | ||
QueueId = kz_json:get_ne_binary_value(<<"id">>, Data), | ||
Window = kz_json:get_integer_value(<<"window">>, Data), | ||
|
||
case Window of | ||
'undefined' -> 'ok'; | ||
_ -> lager:info("evaluating average wait time over last ~b seconds", [Window]) | ||
end, | ||
|
||
Req = props:filter_undefined( | ||
[{<<"Account-ID">>, AccountId} | ||
,{<<"Queue-ID">>, QueueId} | ||
,{<<"Window">>, Window} | ||
| kz_api:default_headers(?APP_NAME, ?APP_VERSION) | ||
]), | ||
case kapps_util:amqp_pool_request(Req | ||
,fun kapi_acdc_stats:publish_average_wait_time_req/1 | ||
,fun kapi_acdc_stats:average_wait_time_resp_v/1 | ||
) | ||
of | ||
{'ok', Resp} -> | ||
AverageWaitTime = kz_json:get_integer_value(<<"Average-Wait-Time">>, Resp, 0), | ||
lager:info("average wait time for account ~s queue ~s is ~B seconds", [AccountId, QueueId, AverageWaitTime]), | ||
{'branch_keys', BranchKeys} = cf_exe:get_branch_keys(Call), | ||
evaluate_average_wait_time(AverageWaitTime, BranchKeys, Call); | ||
{'error', E} -> | ||
lager:error("could not fetch average wait time for account ~s queue ~s: ~p", [AccountId, QueueId, E]), | ||
cf_exe:continue(Call) | ||
end. | ||
|
||
%%------------------------------------------------------------------------------ | ||
%% @doc Continue to the branch of the callflow with the highest exceeded | ||
%% threshold | ||
%% @end | ||
%%------------------------------------------------------------------------------ | ||
-spec evaluate_average_wait_time(non_neg_integer(), kz_json:path(), kapps_call:call()) -> 'ok'. | ||
evaluate_average_wait_time(AverageWaitTime, Keys, Call) -> | ||
Keys1 = lists:sort(fun(Key1, Key2) -> | ||
kz_term:to_integer(Key1) >= kz_term:to_integer(Key2) | ||
end, Keys), | ||
evaluate_average_wait_time2(AverageWaitTime, Keys1, Call). | ||
|
||
-spec evaluate_average_wait_time2(non_neg_integer(), kz_json:path(), kapps_call:call()) -> 'ok'. | ||
evaluate_average_wait_time2(_, [], Call) -> | ||
cf_exe:continue(Call); | ||
evaluate_average_wait_time2(AverageWaitTime, [Key|Keys], Call) -> | ||
Threshold = kz_term:to_integer(Key), | ||
case AverageWaitTime >= Threshold of | ||
'true' -> | ||
lager:info("average wait time exceeded threshold ~B", [Threshold]), | ||
cf_exe:continue(Key, Call); | ||
'false' -> | ||
evaluate_average_wait_time2(AverageWaitTime, Keys, Call) | ||
end. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
## Acdc Wait Time | ||
|
||
### About Acdc Wait Time | ||
|
||
Handles branching the callflow based on the current average wait time of a queue. | ||
Branch keys are integer-convertible binaries (e.g. `<<"60">>`) that represent wait time thresholds in seconds. The default branch is represented by the `_` key. The branch with the highest threshold which the queue's current average wait time exceeds is the branch followed in the callflow's execution. If none are exceeded, the default branch is followed. | ||
|
||
#### Schema | ||
|
||
Validator for the acdc_wait_time callflow's data object | ||
|
||
|
||
|
||
Key | Description | Type | Default | Required | ||
--- | ----------- | ---- | ------- | -------- | ||
`id` | Queue ID | `string()` | | `false` | ||
`window` | Window over which average wait time is calculated (in seconds) | `integer()` | | `false` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## Acdc Wait Time | ||
|
||
### About Acdc Wait Time | ||
|
||
#### Schema | ||
|
||
Validator for the acdc_wait_time callflow's data object | ||
|
||
|
||
|
||
Key | Description | Type | Default | Required | ||
--- | ----------- | ---- | ------- | -------- | ||
`id` | Queue ID | `string()` | | `false` | ||
`window` | Window over which average wait time is calculated (in seconds) | `integer()` | | `false` | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
applications/crossbar/priv/couchdb/schemas/callflows.acdc_wait_time.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"_id": "callflows.acdc_wait_time", | ||
"description": "Validator for the acdc_wait_time callflow's data object", | ||
"properties": { | ||
"id": { | ||
"description": "Queue ID", | ||
"type": "string" | ||
}, | ||
"window": { | ||
"description": "Window over which average wait time is calculated (in seconds)", | ||
"type": "integer" | ||
} | ||
}, | ||
"type": "object" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,9 @@ | |
"Queue-ID": { | ||
"minLength": 1, | ||
"type": "string" | ||
}, | ||
"Window": { | ||
"type": "integer" | ||
} | ||
}, | ||
"required": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters