-
Notifications
You must be signed in to change notification settings - Fork 461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PISTON-542: add the cf_acdc_wait_time module #4619
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c246531
PISTON-542: add the cf_acdc_wait_time module
danielfinke 3ae69ad
PISTON-542: move cf_acdc_wait_time module into acdc app
danielfinke 7b397e9
PISTON-542: fixes for master, remove custom KVs code
danielfinke 03926f6
PISTON-542: make code_checks
danielfinke 4b85a66
PISTON-542: make docs
danielfinke 695eaba
PISTON-542: add documentation of cf_acdc_wait_time module purpose
danielfinke a6c0fa9
PISTON-556: acdc average wait time req custom window
danielfinke File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a one-liner or something here to describe the intended usage?