Skip to content

Commit b1fe0b2

Browse files
EitolHector Oliveros
and
Hector Oliveros
authored
Update connection limit logging to check for changes (#1777)
* Update connection limit logging to check for changes Added conditionals to log limit updates only when changes are detected, reducing unnecessary log noise. This applies to both server and client limit updates in the connection logic. * Fix indentation in server and client limit updates Adjusted indentation in the `update_limits` methods to ensure values are updated only when changes are detected. This aligns the logic with the condition and avoids unnecessary updates. * Fix ruff format --------- Co-authored-by: Hector Oliveros <holiveros.see@aminerals.cl>
1 parent c195f37 commit b1fe0b2

11 files changed

+37
-25
lines changed

asyncua/client/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ def get_subscription_revised_params(
796796
and new_keepalive_count != params.RequestedMaxKeepAliveCount
797797
):
798798
_logger.info(
799-
"KeepAliveCount will be updated to %s " "for consistency with RevisedPublishInterval",
799+
"KeepAliveCount will be updated to %s for consistency with RevisedPublishInterval",
800800
new_keepalive_count,
801801
)
802802
modified_params = ua.ModifySubscriptionParameters()

asyncua/client/ha/reconciliator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ async def update_nodes(self, real_map: SubMap, ideal_map: SubMap, targets: Set[s
219219
# in case the previous create_subscription request failed
220220
if not real_sub:
221221
_logger.warning(
222-
"Can't create nodes for %s since underlying " "subscription for %s doesn't exist", url, sub_name
222+
"Can't create nodes for %s since underlying subscription for %s doesn't exist", url, sub_name
223223
)
224224
continue
225225
vs_real = real_map[url][sub_name]

asyncua/common/connection.py

+26-13
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,18 @@ def create_acknowledge_and_set_limits(self, msg: ua.Hello) -> ua.Acknowledge:
5454
ack.SendBufferSize = min(msg.SendBufferSize, self.max_recv_buffer)
5555
ack.MaxChunkCount = self._select_limit(msg.MaxChunkCount, self.max_chunk_count)
5656
ack.MaxMessageSize = self._select_limit(msg.MaxMessageSize, self.max_message_size)
57-
self.max_chunk_count = ack.MaxChunkCount
58-
self.max_recv_buffer = ack.SendBufferSize
59-
self.max_send_buffer = ack.ReceiveBufferSize
60-
self.max_message_size = ack.MaxMessageSize
61-
_logger.info("updating server limits to: %s", self)
57+
have_changes = (
58+
self.max_chunk_count != ack.MaxChunkCount
59+
or self.max_recv_buffer != ack.ReceiveBufferSize
60+
or self.max_send_buffer != ack.SendBufferSize
61+
or self.max_message_size != ack.MaxMessageSize
62+
)
63+
if have_changes:
64+
_logger.info("updating server limits to: %s", self)
65+
self.max_chunk_count = ack.MaxChunkCount
66+
self.max_recv_buffer = ack.SendBufferSize
67+
self.max_send_buffer = ack.ReceiveBufferSize
68+
self.max_message_size = ack.MaxMessageSize
6269
return ack
6370

6471
def create_hello_limits(self, msg: ua.Hello) -> ua.Hello:
@@ -69,11 +76,18 @@ def create_hello_limits(self, msg: ua.Hello) -> ua.Hello:
6976
return msg
7077

7178
def update_client_limits(self, msg: ua.Acknowledge) -> None:
72-
self.max_chunk_count = msg.MaxChunkCount
73-
self.max_recv_buffer = msg.ReceiveBufferSize
74-
self.max_send_buffer = msg.SendBufferSize
75-
self.max_message_size = msg.MaxMessageSize
76-
_logger.info("updating client limits to: %s", self)
79+
have_changes = (
80+
self.max_chunk_count != msg.MaxChunkCount
81+
or self.max_recv_buffer != msg.ReceiveBufferSize
82+
or self.max_send_buffer != msg.SendBufferSize
83+
or self.max_message_size != msg.MaxMessageSize
84+
)
85+
if have_changes:
86+
_logger.info("updating client limits to: %s", self)
87+
self.max_chunk_count = msg.MaxChunkCount
88+
self.max_recv_buffer = msg.ReceiveBufferSize
89+
self.max_send_buffer = msg.SendBufferSize
90+
self.max_message_size = msg.MaxMessageSize
7791

7892

7993
class MessageChunk:
@@ -370,8 +384,7 @@ def _check_sym_header(self, security_hdr):
370384
)
371385
if timeout < datetime.now(timezone.utc):
372386
raise ua.UaError(
373-
f"Security token id {security_hdr.TokenId} has timed out "
374-
f"({timeout} < {datetime.now(timezone.utc)})"
387+
f"Security token id {security_hdr.TokenId} has timed out ({timeout} < {datetime.now(timezone.utc)})"
375388
)
376389
return
377390

@@ -386,7 +399,7 @@ def _check_incoming_chunk(self, chunk):
386399
if chunk.MessageHeader.MessageType != ua.MessageType.SecureOpen:
387400
if chunk.MessageHeader.ChannelId != self.security_token.ChannelId:
388401
raise ua.UaError(
389-
f"Wrong channel id {chunk.MessageHeader.ChannelId}," f" expected {self.security_token.ChannelId}"
402+
f"Wrong channel id {chunk.MessageHeader.ChannelId}, expected {self.security_token.ChannelId}"
390403
)
391404
if self._incoming_parts:
392405
if self._incoming_parts[0].SequenceHeader.RequestId != chunk.SequenceHeader.RequestId:

asyncua/common/copy_node_util.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ async def _read_and_copy_attrs(node_type: asyncua.Node, struct: Any, addnode: ua
118118
setattr(struct, name, variant.Value)
119119
else:
120120
_logger.warning(
121-
"Instantiate: while copying attributes from node type %s," " attribute %s, statuscode is %s",
121+
"Instantiate: while copying attributes from node type %s, attribute %s, statuscode is %s",
122122
str(node_type),
123123
str(name),
124124
str(results[idx].StatusCode),

asyncua/common/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, data, start_pos=0, size=-1):
4343
self._size = size
4444

4545
def __str__(self):
46-
return f"Buffer(size:{self._size}, data:{self._data[self._cur_pos:self._cur_pos + self._size]})"
46+
return f"Buffer(size:{self._size}, data:{self._data[self._cur_pos : self._cur_pos + self._size]})"
4747

4848
__repr__ = __str__
4949

asyncua/common/xmlimporter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ async def add_datatype(self, obj, no_namespace_migration=False):
669669
is_struct = True
670670
else:
671671
_logger.warning(
672-
"%s has datatypedefinition and path %s" " but we could not find out if this is a struct",
672+
"%s has datatypedefinition and path %s but we could not find out if this is a struct",
673673
obj,
674674
path,
675675
)

asyncua/server/history_sql.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ async def read_node_history(self, node_id, start, end, nb_values):
112112
try:
113113
validate_table_name(table)
114114
async with self._db.execute(
115-
f'SELECT * FROM "{table}" WHERE "SourceTimestamp" BETWEEN ? AND ? ' f'ORDER BY "_Id" {order} LIMIT ?',
115+
f'SELECT * FROM "{table}" WHERE "SourceTimestamp" BETWEEN ? AND ? ORDER BY "_Id" {order} LIMIT ?',
116116
(
117117
start_time,
118118
end_time,
@@ -294,7 +294,7 @@ def _get_select_clauses(self, source_id, evfilter):
294294
s_clauses.append(name)
295295
except AttributeError:
296296
self.logger.warning(
297-
"Historizing SQL OPC UA Select Clause Warning for node %s," " Clause: %s:", source_id, select_clause
297+
"Historizing SQL OPC UA Select Clause Warning for node %s, Clause: %s:", source_id, select_clause
298298
)
299299
# remove select clauses that the event type doesn't have; SQL will error because the column doesn't exist
300300
clauses = [x for x in s_clauses if x in self._event_fields[source_id]]

asyncua/server/internal_session.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ def __init__(
5959

6060
def __str__(self):
6161
return (
62-
f"InternalSession(name:{self.name},"
63-
f" user:{self.user}, id:{self.session_id}, auth_token:{self.auth_token})"
62+
f"InternalSession(name:{self.name}, user:{self.user}, id:{self.session_id}, auth_token:{self.auth_token})"
6463
)
6564

6665
async def get_endpoints(self, params=None, sockname=None):

asyncua/server/user_managers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async def add_role(self, certificate_path: Path, user_role: UserRole, name: str,
3939

4040
if name in self._trusted_certificates:
4141
logging.warning(
42-
"certificate with name %s " "attempted to be added multiple times, only the last version will be kept.",
42+
"certificate with name %s attempted to be added multiple times, only the last version will be kept.",
4343
name,
4444
)
4545
self._trusted_certificates[name] = {"certificate": uacrypto.der_from_x509(certificate), "user": user}

asyncua/ua/uatypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ def __init__(self, Text=None, Locale=None):
786786
if self.Text is not None:
787787
if not isinstance(self.Text, str):
788788
raise ValueError(
789-
f'A LocalizedText object takes a string as argument "text"' f"not a {type(self.Text)}, {self.Text}"
789+
f'A LocalizedText object takes a string as argument "text"not a {type(self.Text)}, {self.Text}'
790790
)
791791

792792
if self.Locale is not None:

tests/test_crypto_connect.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ async def test_security_level_endpoints(srv_crypto_all_certs: Tuple[Server, str]
503503
policy_type = ua.SecurityPolicyType.NoSecurity
504504
else:
505505
policy_type = ua.SecurityPolicyType[
506-
f'{end_point.SecurityPolicyUri.split("#")[1].replace("_", "")}_{end_point.SecurityMode.name}'
506+
f"{end_point.SecurityPolicyUri.split('#')[1].replace('_', '')}_{end_point.SecurityMode.name}"
507507
]
508508
assert end_point.SecurityLevel == SECURITY_POLICY_TYPE_MAP[policy_type][2]
509509

0 commit comments

Comments
 (0)