fortinet-ansible-dev / ansible-galaxy-fortios-collection

GNU General Public License v3.0
85 stars 49 forks source link

fortios_json_generic module takes additional 20 seconds in GET method API call #271

Closed fortinetps closed 5 months ago

fortinetps commented 1 year ago

I am working with my customer on a playbook which uses fortios_json_generic module, and we noticed that if we use fortios_json_generic module for a GET method API call, the generic module will cost 20 seconds more. please see the following playbook and running result snippets:

playbook snippet:

TASK [get system ha-statistics with fortios_json_generic] *** Thursday 05 October 2023 01:34:07 +0000 (0:00:00.845) 0:00:00.956 ** changed: [fw-4444]

PLAY RECAP ** fw-4444 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

Thursday 05 October 2023 01:34:28 +0000 (0:00:20.833) 0:00:21.790 ** =============================================================================== get system ha-statistics with fortios_json_generic ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 20.83s get system ha-statistics with fortios_monitor_fact ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 0.85s

I did some debugging and I noticed the issue is within the file: plugins/httpapi/fortios.py on line#234: response, response_data = self.connection.send(url, data, method=method)

When using fortios_monitor_fact module, since this module knows the monitor API call method is always GET, so it doesn't pass anything to data, so the log shows: Sending request: METHOD:GET URL:/api/v2/monitor/system/ha-statistics?access_token=tpzkw9413zwHQm8sfQN37xNsHx4500 DATA:

When using fortios_json_generic module, even though the method is GET and we didn't specify the jsonbody, it always pass "" to the data, here is the log shows, see the DATA here is "", and this is the only difference and this cause extra 20 seconds wait for the same API call. Sending request: METHOD:GET URL:/api/v2/monitor/system/ha-statistics?access_token=tpzkw9413zwHQm8sfQN37xNsHx4500 DATA:""

Here is my env, and both my customer and me are having the same issue,

root@ansible:/workspaces/ansible# ansible-playbook --version ansible-playbook [core 2.13.9] config file = /workspaces/ansible/ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.8/site-packages/ansible ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections executable location = /usr/local/bin/ansible-playbook python version = 3.8.10 (default, Jun 23 2021, 15:19:53) [GCC 8.3.0] jinja version = 3.1.2 libyaml = True root@ansible:/workspaces/ansible# ansible-galaxy collection list

/root/.ansible/collections/ansible_collections

Collection Version


ansible.netcommon 5.2.0
ansible.posix 1.5.4
ansible.utils 2.11.0 community.general 7.4.0
fortinet.fortimanager 2.2.0
fortinet.fortios 2.3.2

Please let me know if you have any questions.

Thanks!

JieX19 commented 1 year ago

Hi @fortinetps,

Thanks for bringing us the question! I've optimized the code to spend less time when sending GET requests. There will be a new release at the end of this month, the fix will be included in it.

JieX19 commented 5 months ago

Hi @fortinetps,

The issue was resolved in the previous version. Please upgrade to the latest version and try the module again. I will close the ticket since the issue has been resolved.

Thanks, Jie