@@ -41,7 +41,7 @@ class AWSIoTMetrics:
4141# Feature ID Constants
4242
4343
44- class MetricsFeatureId (str , Enum ):
44+ class _MetricsFeatureId (str , Enum ):
4545 """Feature IDs for IoT SDK metrics tracking.
4646
4747 Each ID is a single character used to encode feature usage in the metrics
@@ -63,7 +63,7 @@ class MetricsFeatureId(str, Enum):
6363# Feature Value Constants
6464
6565
66- class MetricsProtocolVersionValue (str , Enum ):
66+ class _MetricsProtocolVersionValue (str , Enum ):
6767 """Protocol version values for metrics encoding.
6868
6969 Maps MQTT protocol versions to their single-character metric representations.
@@ -72,7 +72,7 @@ class MetricsProtocolVersionValue(str, Enum):
7272 MQTT5 = "5"
7373
7474
75- class MetricsSocketImplementationValue (str , Enum ):
75+ class _MetricsSocketImplementationValue (str , Enum ):
7676 """Socket implementation values for metrics encoding.
7777
7878 Maps the underlying platform socket layer to its metric representation.
@@ -82,7 +82,7 @@ class MetricsSocketImplementationValue(str, Enum):
8282 WINSOCK = "B"
8383
8484
85- class MetricsHttpProxyTypeValue (str , Enum ):
85+ class _MetricsHttpProxyTypeValue (str , Enum ):
8686 """HTTP proxy type values for metrics encoding.
8787
8888 Indicates whether the proxy connection uses plain HTTP or HTTPS (TLS).
@@ -203,13 +203,13 @@ def _tls_cipher_preference_metrics_value(pref):
203203def _detect_socket_implementation ():
204204 """Detect the socket implementation based on the current platform.
205205
206- Returns MetricsSocketImplementationValue .WINSOCK on Windows,
207- MetricsSocketImplementationValue .POSIX on all other platforms
206+ Returns _MetricsSocketImplementationValue .WINSOCK on Windows,
207+ _MetricsSocketImplementationValue .POSIX on all other platforms
208208 (macOS, Linux).
209209 """
210210 if sys .platform == "win32" :
211- return MetricsSocketImplementationValue .WINSOCK
212- return MetricsSocketImplementationValue .POSIX
211+ return _MetricsSocketImplementationValue .WINSOCK
212+ return _MetricsSocketImplementationValue .POSIX
213213
214214
215215# MQTT5 encoding list
@@ -248,61 +248,61 @@ def _get_encoded_feature_list(client_options):
248248 if client_options .retry_jitter_mode is not None :
249249 val = _retry_jitter_metrics_value (client_options .retry_jitter_mode )
250250 if val :
251- features .append (f"{ MetricsFeatureId .RETRY_JITTER_MODE .value } /{ val } " )
251+ features .append (f"{ _MetricsFeatureId .RETRY_JITTER_MODE .value } /{ val } " )
252252
253253 # B: session_behavior
254254 if client_options .session_behavior is not None :
255255 val = _client_session_behavior_metrics_value (client_options .session_behavior )
256256 if val :
257- features .append (f"{ MetricsFeatureId .SESSION_BEHAVIOR .value } /{ val } " )
257+ features .append (f"{ _MetricsFeatureId .SESSION_BEHAVIOR .value } /{ val } " )
258258
259259 # C: offline_queue_behavior
260260 if client_options .offline_queue_behavior is not None :
261261 val = _client_operation_queue_behavior_metrics_value (client_options .offline_queue_behavior )
262262 if val :
263- features .append (f"{ MetricsFeatureId .OFFLINE_QUEUE_BEHAVIOR .value } /{ val } " )
263+ features .append (f"{ _MetricsFeatureId .OFFLINE_QUEUE_BEHAVIOR .value } /{ val } " )
264264
265265 # D: outbound_topic_alias_behavior
266266 if client_options .topic_aliasing_options is not None :
267267 if client_options .topic_aliasing_options .outbound_behavior is not None :
268268 val = _outbound_topic_alias_behavior_metrics_value (client_options .topic_aliasing_options .outbound_behavior )
269269 if val :
270- features .append (f"{ MetricsFeatureId .OUTBOUND_TOPIC_ALIAS_BEHAVIOR .value } /{ val } " )
270+ features .append (f"{ _MetricsFeatureId .OUTBOUND_TOPIC_ALIAS_BEHAVIOR .value } /{ val } " )
271271
272272 # E: inbound_topic_alias_behavior
273273 if client_options .topic_aliasing_options is not None :
274274 if client_options .topic_aliasing_options .inbound_behavior is not None :
275275 val = _inbound_topic_alias_behavior_metrics_value (client_options .topic_aliasing_options .inbound_behavior )
276276 if val :
277- features .append (f"{ MetricsFeatureId .INBOUND_TOPIC_ALIAS_BEHAVIOR .value } /{ val } " )
277+ features .append (f"{ _MetricsFeatureId .INBOUND_TOPIC_ALIAS_BEHAVIOR .value } /{ val } " )
278278
279279 # F: protocol_version - MQTT5 always uses client options
280- features .append (f"{ MetricsFeatureId .PROTOCOL_VERSION .value } /{ MetricsProtocolVersionValue .MQTT5 .value } " )
280+ features .append (f"{ _MetricsFeatureId .PROTOCOL_VERSION .value } /{ _MetricsProtocolVersionValue .MQTT5 .value } " )
281281
282282 # G: socket_implementation - Detect based on platform
283- features .append (f"{ MetricsFeatureId .SOCKET_IMPLEMENTATION .value } /{ _detect_socket_implementation ().value } " )
283+ features .append (f"{ _MetricsFeatureId .SOCKET_IMPLEMENTATION .value } /{ _detect_socket_implementation ().value } " )
284284
285285 # H: http_proxy_type - Determine based on whether proxy uses TLS
286286 if client_options .http_proxy_options is not None :
287- proxy_type = MetricsHttpProxyTypeValue .HTTPS if getattr (
287+ proxy_type = _MetricsHttpProxyTypeValue .HTTPS if getattr (
288288 client_options .http_proxy_options ,
289289 'tls_connection_options' ,
290- None ) is not None else MetricsHttpProxyTypeValue .HTTP
291- features .append (f"{ MetricsFeatureId .HTTP_PROXY_TYPE .value } /{ proxy_type .value } " )
290+ None ) is not None else _MetricsHttpProxyTypeValue .HTTP
291+ features .append (f"{ _MetricsFeatureId .HTTP_PROXY_TYPE .value } /{ proxy_type .value } " )
292292
293293 # I: certificate_source - Would need to be tracked from TLS context setup. This is set at a IoT SDK level
294294
295295 # J: tls_cipher_preference - security policy
296296 if client_options .tls_ctx is not None :
297- val = _tls_cipher_preference_metrics_value (client_options .tls_ctx .cipher_pref )
297+ val = _tls_cipher_preference_metrics_value (client_options .tls_ctx ._cipher_pref )
298298 if val :
299- features .append (f"{ MetricsFeatureId .TLS_CIPHER_PREFERENCE .value } /{ val } " )
299+ features .append (f"{ _MetricsFeatureId .TLS_CIPHER_PREFERENCE .value } /{ val } " )
300300
301301 # K: minimum_tls_version - The minimum TLS version set on TLSContextOptions
302302 if client_options .tls_ctx is not None :
303- val = _minimum_tls_version_metrics_value (client_options .tls_ctx .min_tls_ver )
303+ val = _minimum_tls_version_metrics_value (client_options .tls_ctx ._min_tls_ver )
304304 if val :
305- features .append (f"{ MetricsFeatureId .MINIMUM_TLS_VERSION .value } /{ val } " )
305+ features .append (f"{ _MetricsFeatureId .MINIMUM_TLS_VERSION .value } /{ val } " )
306306
307307 return "," .join (features )
308308
@@ -329,26 +329,26 @@ def _get_encoded_feature_list_mqtt3(proxy_options, tls_ctx=None):
329329 str: The encoded feature list string.
330330 """
331331 features = [
332- f"{ MetricsFeatureId .PROTOCOL_VERSION .value } /{ MetricsProtocolVersionValue .MQTT311 .value } " ,
333- f"{ MetricsFeatureId .SOCKET_IMPLEMENTATION .value } /{ _detect_socket_implementation ().value } "
332+ f"{ _MetricsFeatureId .PROTOCOL_VERSION .value } /{ _MetricsProtocolVersionValue .MQTT311 .value } " ,
333+ f"{ _MetricsFeatureId .SOCKET_IMPLEMENTATION .value } /{ _detect_socket_implementation ().value } "
334334 ]
335335 # H: http_proxy_type - Determine based on whether proxy uses TLS
336336 if proxy_options is not None :
337- proxy_type = MetricsHttpProxyTypeValue .HTTPS if getattr (
338- proxy_options , 'tls_connection_options' , None ) is not None else MetricsHttpProxyTypeValue .HTTP
339- features .append (f"{ MetricsFeatureId .HTTP_PROXY_TYPE .value } /{ proxy_type .value } " )
337+ proxy_type = _MetricsHttpProxyTypeValue .HTTPS if getattr (
338+ proxy_options , 'tls_connection_options' , None ) is not None else _MetricsHttpProxyTypeValue .HTTP
339+ features .append (f"{ _MetricsFeatureId .HTTP_PROXY_TYPE .value } /{ proxy_type .value } " )
340340
341341 # J: tls_cipher_preference - security policy
342342 if tls_ctx is not None :
343- val = _tls_cipher_preference_metrics_value (tls_ctx .cipher_pref )
343+ val = _tls_cipher_preference_metrics_value (tls_ctx ._cipher_pref )
344344 if val :
345- features .append (f"{ MetricsFeatureId .TLS_CIPHER_PREFERENCE .value } /{ val } " )
345+ features .append (f"{ _MetricsFeatureId .TLS_CIPHER_PREFERENCE .value } /{ val } " )
346346
347347 # K: minimum_tls_version - the minimum TLS version set on TLSContextOptions
348348 if tls_ctx is not None :
349- val = _minimum_tls_version_metrics_value (tls_ctx .min_tls_ver )
349+ val = _minimum_tls_version_metrics_value (tls_ctx ._min_tls_ver )
350350 if val :
351- features .append (f"{ MetricsFeatureId .MINIMUM_TLS_VERSION .value } /{ val } " )
351+ features .append (f"{ _MetricsFeatureId .MINIMUM_TLS_VERSION .value } /{ val } " )
352352
353353 return "," .join (features )
354354
@@ -357,14 +357,14 @@ def _merge_feature_lists(crt_features, user_features):
357357 """Merge CRT-generated features with user-provided (IoT SDK) features.
358358
359359 When both lists contain the same feature ID, the user-provided value
360- takes precedence. The result is sorted by feature ID.
360+ takes precedence.
361361
362362 Args:
363363 crt_features (str): CRT-generated feature list.
364364 user_features (str): User-provided feature list from the IoT SDK.
365365 May be empty string if no SDK features are provided.
366366 Returns:
367- str: The merged feature list string, sorted by feature ID .
367+ str: The merged feature list string.
368368 """
369369 merged = {}
370370 # Parse CRT Features
@@ -377,12 +377,12 @@ def _merge_feature_lists(crt_features, user_features):
377377 if "/" in pair :
378378 fid , val = pair .split ("/" , 1 )
379379 merged [fid ] = val
380- return "," .join (f"{ k } /{ v } " for k , v in sorted ( merged .items () ))
380+ return "," .join (f"{ k } /{ v } " for k , v in merged .items ())
381381
382382# Metrics creation
383383
384384
385- def create_metrics (user_metrics , crt_feature_list ):
385+ def _create_metrics (user_metrics , crt_feature_list ):
386386 """Create the final AWSIoTMetrics object by merging CRT and user-provided data.
387387
388388 Applies the following rules to produce the final metrics:
@@ -433,7 +433,7 @@ def create_metrics(user_metrics, crt_feature_list):
433433
434434 # Merge features: if version matches, merge CRT + SDK; otherwise CRT only
435435 if (user_metrics_version is not None and user_metrics_version .isdigit () and int (
436- user_metrics_version ) == IOT_SDK_METRICS_FEATURE_VERSION and user_feature ):
436+ user_metrics_version ) == IOT_SDK_METRICS_FEATURE_VERSION ):
437437 metadata ["IoTSDKFeature" ] = _merge_feature_lists (crt_feature_list , user_feature )
438438 else :
439439 metadata ["IoTSDKFeature" ] = _merge_feature_lists (crt_feature_list , "" )
@@ -445,7 +445,7 @@ def create_metrics(user_metrics, crt_feature_list):
445445 return final_metrics
446446
447447
448- def create_metrics_mqtt5 (client_options ):
448+ def _create_metrics_mqtt5 (client_options ):
449449 """Create the final AWSIoTMetrics object for an MQTT5 client.
450450
451451 Generates the CRT feature list from the full set of MQTT5 ClientOptions
@@ -457,10 +457,10 @@ def create_metrics_mqtt5(client_options):
457457 AWSIoTMetrics: The final metrics object with merged CRT and SDK features.
458458 """
459459 crt_feature_list = _get_encoded_feature_list (client_options )
460- return create_metrics (client_options .metrics , crt_feature_list )
460+ return _create_metrics (client_options .metrics , crt_feature_list )
461461
462462
463- def create_metrics_mqtt3 (user_metrics = None , proxy_options = None , tls_ctx = None ):
463+ def _create_metrics_mqtt3 (user_metrics = None , proxy_options = None , tls_ctx = None ):
464464 """Creates the final AWSIoTMetrics object for an MQTT3 connection.
465465
466466 Generates the CRT feature list from the MQTT3 connection parameters
@@ -477,4 +477,4 @@ def create_metrics_mqtt3(user_metrics=None, proxy_options=None, tls_ctx=None):
477477 AWSIoTMetrics: The final metrics object with merged CRT and SDK features.
478478 """
479479 crt_feature_list = _get_encoded_feature_list_mqtt3 (proxy_options , tls_ctx )
480- return create_metrics (user_metrics , crt_feature_list )
480+ return _create_metrics (user_metrics , crt_feature_list )
0 commit comments