-
Notifications
You must be signed in to change notification settings - Fork 79
Add IoT Metrics Support #809
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?
Changes from all commits
1308b8e
cafa187
2dfc1fd
d9e87c5
12ff848
13f7258
5f8ad51
44f74f8
efb6a7e
407182d
c87dd51
cc0a9bf
1fa43d5
56b9dd5
a376718
5c33a50
5b4de7b
4bf6518
9118d69
5f46f21
397d9f2
79f0f8d
09ef78b
fc7dc0c
bdf3cfe
294b2ca
d6e059a
ef33cc7
8441493
7b5033f
c13556c
d91422c
33fd51b
f720cf2
56d5d4e
bb6add8
54f28d2
2320467
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /*! \cond DOXYGEN_PRIVATE | ||
| ** Hide API from this file in doxygen. Set DOXYGEN_PRIVATE in doxygen | ||
| ** config to enable this file for doxygen. | ||
| */ | ||
| #pragma once | ||
| /** | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0. | ||
| */ | ||
|
|
||
| #include <aws/crt/Types.h> | ||
|
|
||
| namespace Aws | ||
| { | ||
| namespace Crt | ||
| { | ||
| namespace Mqtt | ||
| { | ||
| /** | ||
| * @internal | ||
| * IoT Device SDK Metrics Structure | ||
| */ | ||
| struct IoTDeviceSDKMetrics | ||
| { | ||
| String LibraryName; | ||
|
|
||
| IoTDeviceSDKMetrics() { LibraryName = "IoTDeviceSDK/CPP"; } | ||
|
|
||
| void initializeRawOptions(aws_mqtt_iot_metrics &raw_options) noexcept | ||
| { | ||
| raw_options.library_name = ByteCursorFromString(LibraryName); | ||
| } | ||
| }; | ||
| } // namespace Mqtt | ||
| } // namespace Crt | ||
| } // namespace Aws | ||
|
|
||
| /*! \endcond */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -670,8 +670,8 @@ namespace Aws | |
| /* Error */ | ||
| int m_lastError; | ||
|
|
||
| /** Enable AWS IoT Metrics Collection. This is always set to true for now. */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trivial: Maybe it'll become clearer below but what does this mean it's always set to true? Is this not tied to the enableMetrics bools that can be set to false?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like this can't be changed to false. Is there a reason we're not allowing metrics to be disabled?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This option was originally there to match MQTT3 behavior, which allows users to disable metrics. Since the MQTT5 client does not supports toggling metrics collection, it should be safe to remove. |
||
| bool m_enableMetricsCollection; | ||
|
|
||
| Crt::String m_sdkName = "CPPv2"; | ||
| Crt::String m_sdkVersion = AWS_CRT_CPP_VERSION; | ||
sfod marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
675
to
676
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part sill confuses me. Will the library name sometimes be set to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned here, the SDK already exposes an API for setting a customized sdkName.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I understand that we can't remove this. But we can change the default value. Or am I missing something? |
||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,8 +40,8 @@ namespace Aws | |
| : m_underlyingConnection(nullptr), m_hostName(options.hostName), m_port(options.port), | ||
| m_tlsContext(std::move(options.tlsContext)), m_tlsOptions(std::move(options.tlsConnectionOptions)), | ||
| m_socketOptions(std::move(options.socketOptions)), m_onAnyCbData(nullptr), m_useTls(options.useTls), | ||
| m_useWebsocket(options.useWebsocket), m_allocator(options.allocator), | ||
| m_connection(std::move(connection)) | ||
| m_useWebsocket(options.useWebsocket), m_enableMetrics(options.enableMetrics), | ||
| m_allocator(options.allocator), m_connection(std::move(connection)) | ||
| { | ||
| if (client != nullptr) | ||
| { | ||
|
|
@@ -471,6 +471,21 @@ namespace Aws | |
|
|
||
| aws_mqtt_client_connection_set_connection_termination_handler( | ||
| m_underlyingConnection, MqttConnectionCore::s_onConnectionTermination, this); | ||
|
|
||
| if (m_enableMetrics) | ||
| { | ||
| struct aws_mqtt_iot_metrics metrics; | ||
| AWS_ZERO_STRUCT(metrics); | ||
| m_sdkMetrics.initializeRawOptions(metrics); | ||
| if (aws_mqtt_client_connection_set_metrics(m_underlyingConnection, &metrics)) | ||
|
Comment on lines
+477
to
+480
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will it be possible to add meta info into |
||
| { | ||
| AWS_LOGF_DEBUG(AWS_LS_MQTT_CLIENT, "Failed to set Mqtt Metrics"); | ||
| } | ||
| } | ||
| else if (aws_mqtt_client_connection_set_metrics(m_underlyingConnection, nullptr)) | ||
| { | ||
| AWS_LOGF_DEBUG(AWS_LS_MQTT_CLIENT, "Failed to set Mqtt Metrics"); | ||
| } | ||
| } | ||
| else | ||
| { | ||
|
|
||
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.
I think we should provide more details to users about what info we collect (version, configuration, etc.) and what we don't (probably something general like "private data" would suffice), so users won't opt out of metrics just in case we collect something they don't want to share.
I'd add these details to all public API that expose metrics-related functionality.