forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metering connector actions request body bytes (elastic#186804)
Towards: elastic/response-ops-team#209 This PR collects body-bytes from the requests made by the connectors to the 3rd parties and saves them in the event-log. There is a new metric collector: `ConnectorMetricsCollector` Action TaskRunner, creates a new instance of it on each action execution and passes it to the actionType.executor. Then the actionType.executor passes it to the request function provided by the actions plugin. Request function passes the response (or the error) from axios to `addRequestBodyBytes` method of the `ConnectorMetricsCollector`. Since axios always returns `request.headers['Content-Length']` either in success result or error, metric collector uses its value to get the request body bytes. In case there is no `Content-Length` header, `addRequestBodyBytes` method fallbacks to the body object that we pass as the second param. So It calculates the body bytes by using `Buffer.byteLength(body, 'utf8');`, which is also used by axios to populate `request.headers['Content-Length']` For the connectors or the subActions that we don't use the request function or axios: addRequestBodyBytes method is called just before making the request only with the body param in order to force it to use the fallback. Note: If there are more than one requests in an execution, the bytes are summed. ## To verify: Create a rule with a connector that you would like to test. Let the rule run and check the event-log of your connector, request body bytes should be saved in: `kibana.action.execution.metrics.request_body_bytes` Alternatively: You can create a connector and run it on its test tab. You can use the below query to check the event-log: ``` { "query": { "bool": { "must": [ { "match": { "event.provider":"actions"}}, { "match": { "kibana.action.type_id":"{**your-action-type-id**}"}} ], "filter": [ { "term": { "event.action": "execute" }} ] } }, "size" : 100 } ```
- Loading branch information
1 parent
8431033
commit 9372027
Showing
114 changed files
with
4,347 additions
and
1,690 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
Oops, something went wrong.