Close elastic APM client to release connections (#7517)

* Close elastic APM client to release connections

* Changelog fragment
pull/7534/head
Iuri de Silvio 2023-11-15 18:07:24 -03:00 committed by GitHub
parent d0870a022e
commit 8d886b42ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 16 deletions

View File

@ -0,0 +1,2 @@
minor_changes:
- elastic callback plugin - close elastic client to not leak resources (https://github.com/ansible-collections/community.general/pull/7517).

View File

@ -84,6 +84,7 @@ import time
import uuid import uuid
from collections import OrderedDict from collections import OrderedDict
from contextlib import closing
from os.path import basename from os.path import basename
from ansible.errors import AnsibleError, AnsibleRuntimeError from ansible.errors import AnsibleError, AnsibleRuntimeError
@ -201,6 +202,7 @@ class ElasticSource(object):
apm_cli = self.init_apm_client(apm_server_url, apm_service_name, apm_verify_server_cert, apm_secret_token, apm_api_key) apm_cli = self.init_apm_client(apm_server_url, apm_service_name, apm_verify_server_cert, apm_secret_token, apm_api_key)
if apm_cli: if apm_cli:
with closing(apm_cli):
instrument() # Only call this once, as early as possible. instrument() # Only call this once, as early as possible.
if traceparent: if traceparent:
parent = trace_parent_from_string(traceparent) parent = trace_parent_from_string(traceparent)