-
Notifications
You must be signed in to change notification settings - Fork 50
Add IoT Metrics Support #710
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
bf5456e
d3d6352
21fe38d
13fe021
da7ed31
c167b43
2368721
c456258
03e5d98
9a9c89d
5f3868c
ec40b81
fb81ecc
0435c7f
3a7b509
a21e542
c51a273
2f31d9d
a6a3c30
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 |
|---|---|---|
|
|
@@ -437,6 +437,39 @@ static void s_on_connect( | |
| PyGILState_Release(state); | ||
| } | ||
|
|
||
| /* If unsuccessful, false is returned and a Python error has been set */ | ||
| bool s_set_metrics(struct aws_mqtt_client_connection *connection, PyObject *metrics) { | ||
| assert(metrics && (metrics != Py_None)); | ||
|
|
||
| if (connection == NULL) { | ||
| return false; | ||
| } | ||
|
|
||
| bool success = false; | ||
|
|
||
| PyObject *library_name_py = PyObject_GetAttrString(metrics, "library_name"); | ||
| struct aws_byte_cursor library_name = aws_byte_cursor_from_pyunicode(library_name_py); | ||
| if (!library_name.ptr) { | ||
| PyErr_SetString(PyExc_TypeError, "metrics.library_name must be str type"); | ||
| goto done; | ||
| } | ||
|
|
||
| struct aws_mqtt_iot_sdk_metrics metrics_struct = { | ||
| .library_name = library_name, | ||
| }; | ||
|
|
||
| if (aws_mqtt_client_connection_set_metrics(connection, &metrics_struct)) { | ||
| PyErr_SetAwsLastError(); | ||
| goto done; | ||
| } | ||
|
|
||
| success = true; | ||
|
|
||
| done: | ||
| Py_DECREF(library_name_py); | ||
| return success; | ||
| } | ||
|
|
||
| /* If unsuccessful, false is returned and a Python error has been set */ | ||
| bool s_set_will(struct aws_mqtt_client_connection *connection, PyObject *will) { | ||
| assert(will && (will != Py_None)); | ||
|
|
@@ -668,9 +701,10 @@ PyObject *aws_py_mqtt_client_connection_connect(PyObject *self, PyObject *args) | |
| PyObject *is_clean_session; | ||
| PyObject *on_connect; | ||
| PyObject *proxy_options_py; | ||
| PyObject *metrics_py; | ||
| if (!PyArg_ParseTuple( | ||
| args, | ||
| "Os#s#IOOKKHIIOz#z#OOO", | ||
| "Os#s#IOOKKHIIOz#z#OOOO", | ||
| &impl_capsule, | ||
| &client_id, | ||
| &client_id_len, | ||
|
|
@@ -691,7 +725,8 @@ PyObject *aws_py_mqtt_client_connection_connect(PyObject *self, PyObject *args) | |
| &password_len, | ||
| &is_clean_session, | ||
| &on_connect, | ||
| &proxy_options_py)) { | ||
| &proxy_options_py, | ||
| &metrics_py)) { | ||
| return NULL; | ||
| } | ||
|
|
||
|
|
@@ -773,6 +808,13 @@ PyObject *aws_py_mqtt_client_connection_connect(PyObject *self, PyObject *args) | |
| } | ||
| } | ||
|
|
||
| // If metrics is None, we do not set metrics at all. | ||
| if (metrics_py != Py_None) { | ||
| if (!s_set_metrics(py_connection->native, metrics_py)) { | ||
| goto done; | ||
|
Comment on lines
+813
to
+814
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. In crt-cpp, a failure on setting metrics is ignored. Here, it fails connection attempts. I think we should document the correct behavior and implement it everywhere.
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. There is still inconsistency on setting metrics failure between crt-cpp (just log failure and proceed with connection) and crt-python (fail connect attempt on failure). I think the cpp logic is the correct one because we don't want the metrics-related issues to break users. |
||
| } | ||
| } | ||
|
|
||
| if (on_connect != Py_None) { | ||
| Py_INCREF(on_connect); | ||
| py_connection->on_connect = on_connect; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.