-
Notifications
You must be signed in to change notification settings - Fork 11
feat: efm v2 support #930
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
base: main
Are you sure you want to change the base?
feat: efm v2 support #930
Conversation
876d0d5
to
5a504a7
Compare
f6e9154
to
9727b6a
Compare
# Conflicts: # aws_advanced_python_wrapper/plugin_service.py # aws_advanced_python_wrapper/utils/atomic.py
self._value = value | ||
|
||
|
||
class AtomicReference: |
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.
does it make sense to use generics here instead of Any? might be an overkill
docs/using-the-python-driver/using-plugins/UsingTheHostMonitoringPlugin.md
Show resolved
Hide resolved
from time import perf_counter_ns, sleep | ||
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Optional, Set | ||
|
||
import psycopg |
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.
This import shouldn't be here
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.
This will cause import errors for mysql users, even though efm is not supported for mysql
|
||
class HostMonitorV2: | ||
""" | ||
This class uses a background thread to monitor a particular server with one or more active :py:class:`Connection` |
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.
This class uses a background thread to monitor a particular server with one or more active :py:class:`Connection` | |
This class uses a background thread to monitor a particular server with one or more active :py:class:Connection |
logger.warning("HostMonitorV2.MonitorIsStopped", self._host_info.host) | ||
|
||
current_time_ns = perf_counter_ns() | ||
start_monitoring_time_ns = ((current_time_ns + self._failure_detection_time_ns) // 10**9) * 10**9 |
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.
start_monitoring_time_ns = ((current_time_ns + self._failure_detection_time_ns) // 10**9) * 10**9 | |
start_monitoring_time_ns = current_time_ns + self._failure_detection_time_ns |
Can we create helper methods for these time conversions to make the intent more clear
if self.is_stopped: | ||
logger.warning("HostMonitorV2.MonitorIsStopped", self._host_info.host) | ||
|
||
current_time_ns = perf_counter_ns() |
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.
current_time_ns = perf_counter_ns() | |
current_time_ns = get_current_time_ns() |
_THREAD_SLEEP_NANO = 100_000_000 | ||
_MONITORING_PROPERTY_PREFIX = "monitoring-" | ||
_QUERY = "SELECT 1" | ||
|
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.
Please check the usage of these. Should use them as static variables instead of self._...
queue: Queue = Queue() | ||
self._new_contexts.compute_if_absent(start_monitoring_time_ns, lambda k: queue) | ||
queue.put(weakref.ref(context)) |
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.
queue: Queue = Queue() | |
self._new_contexts.compute_if_absent(start_monitoring_time_ns, lambda k: queue) | |
queue.put(weakref.ref(context)) | |
compute_if_absent returns the existing queue if key exists | |
```suggestion | |
queue: Optional[Queue] = self._new_contexts.compute_if_absent(start_monitoring_time_ns, lambda k: Queue()) | |
if queue is not None: | |
queue.put(weakref.ref(context)) |
logger.debug("HostMonitorV2.OpenedMonitoringConnection", self._host_info.url) | ||
return True | ||
|
||
valid_timeout = ((self._failure_detection_interval_ns - self._THREAD_SLEEP_NANO) // 2) * 10**9 |
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.
valid_timeout = ((self._failure_detection_interval_ns - self._THREAD_SLEEP_NANO) // 2) * 10**9 | |
valid_timeout = ((self._failure_detection_interval_ns - self._THREAD_SLEEP_NANO) // 2) // 10**9 |
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.
Should we switch all the 10**9 to 1_000_000_000
instead, not sure if the extra calculation has any performance impact
Description
Adding support for enhanced host monitoring V2 with documentation and tests.
Tested manual E2E tests and integration tests.
Porting from JDBC efm v2 implementation.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.