Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

feat: efm v2 support #930

wants to merge 1 commit into from

Conversation

JuanLeee
Copy link
Contributor

@JuanLeee JuanLeee commented Jul 31, 2025

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.

@JuanLeee JuanLeee force-pushed the feat/efmv2 branch 2 times, most recently from 876d0d5 to 5a504a7 Compare August 7, 2025 16:33
@JuanLeee JuanLeee changed the title WIP: feat: efm v2 support feat: efm v2 support Aug 7, 2025
@JuanLeee JuanLeee force-pushed the feat/efmv2 branch 9 times, most recently from f6e9154 to 9727b6a Compare August 12, 2025 23:10
# Conflicts:
#	aws_advanced_python_wrapper/plugin_service.py
#	aws_advanced_python_wrapper/utils/atomic.py
self._value = value


class AtomicReference:
Copy link
Contributor

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

from time import perf_counter_ns, sleep
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Optional, Set

import psycopg
Copy link
Contributor

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

Copy link
Contributor

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`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

@karenc-bq karenc-bq Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
current_time_ns = perf_counter_ns()
current_time_ns = get_current_time_ns()

Comment on lines +199 to +202
_THREAD_SLEEP_NANO = 100_000_000
_MONITORING_PROPERTY_PREFIX = "monitoring-"
_QUERY = "SELECT 1"

Copy link
Contributor

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._...

Comment on lines +252 to +254
queue: Queue = Queue()
self._new_contexts.compute_if_absent(start_monitoring_time_ns, lambda k: queue)
queue.put(weakref.ref(context))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor

@karenc-bq karenc-bq Aug 14, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants