From aeee3083aa1b64abb25d66c9763518ca017f0ea0 Mon Sep 17 00:00:00 2001 From: "xiang.zhou" Date: Sun, 29 Sep 2024 15:14:23 +0800 Subject: [PATCH 1/2] plugin:rm so and schema file when remove custom plugin --- src/core/plugin_manager.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/core/plugin_manager.c b/src/core/plugin_manager.c index a4632d10..01a3ab40 100644 --- a/src/core/plugin_manager.c +++ b/src/core/plugin_manager.c @@ -252,6 +252,20 @@ int neu_plugin_manager_del(neu_plugin_manager_t *mgr, const char *plugin_name) HASH_FIND_STR(mgr->plugins, plugin_name, plugin); if (plugin != NULL) { if (plugin->kind != NEU_PLUGIN_KIND_SYSTEM) { + + char so_file_path[128] = { 0 }; + char schema_file_path[128] = { 0 }; + snprintf(so_file_path, sizeof(so_file_path), "%s/custom/%s", + g_plugin_dir, plugin->lib_name); + snprintf(schema_file_path, sizeof(schema_file_path), + "%s/custom/schema/%s.json", g_plugin_dir, plugin->schema); + if (remove(so_file_path) != 0) { + nlog_error("rm %s file fail!", so_file_path); + } + if (remove(schema_file_path) != 0) { + nlog_error("rm %s file fail!", schema_file_path); + } + HASH_DEL(mgr->plugins, plugin); entity_free(plugin); ret = NEU_ERR_SUCCESS; From 7a1198014b6fe2ce5a54df6ed036ead501c14fa2 Mon Sep 17 00:00:00 2001 From: "xiang.zhou" Date: Sun, 29 Sep 2024 15:34:03 +0800 Subject: [PATCH 2/2] mqtt trace:add resp playload --- plugins/mqtt/azure_iot_plugin.c | 2 +- plugins/mqtt/mqtt_handle.c | 6 +++++- plugins/mqtt/mqtt_handle.h | 2 +- plugins/mqtt/mqtt_plugin_intf.c | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/plugins/mqtt/azure_iot_plugin.c b/plugins/mqtt/azure_iot_plugin.c index a1697d35..7b78e37f 100644 --- a/plugins/mqtt/azure_iot_plugin.c +++ b/plugins/mqtt/azure_iot_plugin.c @@ -330,7 +330,7 @@ static int azure_plugin_request(neu_plugin_t *plugin, neu_reqresp_head_t *head, switch (head->type) { case NEU_RESP_ERROR: - error = handle_write_response(plugin, head->ctx, data); + error = handle_write_response(plugin, head->ctx, data, NULL); break; case NEU_RESP_READ_GROUP: // error = handle_read_response(plugin, head->ctx, data); diff --git a/plugins/mqtt/mqtt_handle.c b/plugins/mqtt/mqtt_handle.c index adabbe0d..01b7d597 100644 --- a/plugins/mqtt/mqtt_handle.c +++ b/plugins/mqtt/mqtt_handle.c @@ -460,7 +460,7 @@ void handle_write_req(neu_mqtt_qos_e qos, const char *topic, } int handle_write_response(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt_json, - neu_resp_error_t *data) + neu_resp_error_t *data, void *trace_scope) { int rv = 0; char *json_str = NULL; @@ -485,6 +485,10 @@ int handle_write_response(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt_json, goto end; } + if (trace_scope) { + neu_otel_scope_add_span_attr_string(trace_scope, "playload", json_str); + } + char * topic = plugin->config.write_resp_topic; neu_mqtt_qos_e qos = plugin->config.qos; rv = publish(plugin, qos, topic, json_str, strlen(json_str)); diff --git a/plugins/mqtt/mqtt_handle.h b/plugins/mqtt/mqtt_handle.h index aa0cc9e0..1b098252 100644 --- a/plugins/mqtt/mqtt_handle.h +++ b/plugins/mqtt/mqtt_handle.h @@ -40,7 +40,7 @@ void handle_write_req(neu_mqtt_qos_e qos, const char *topic, trace_w3c_t *trace_w3c); int handle_write_response(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt_json, - neu_resp_error_t *data); + neu_resp_error_t *data, void *trace_scope); void handle_read_req(neu_mqtt_qos_e qos, const char *topic, const uint8_t *payload, uint32_t len, void *data, diff --git a/plugins/mqtt/mqtt_plugin_intf.c b/plugins/mqtt/mqtt_plugin_intf.c index 456f64c4..2680e8ba 100644 --- a/plugins/mqtt/mqtt_plugin_intf.c +++ b/plugins/mqtt/mqtt_plugin_intf.c @@ -482,7 +482,7 @@ int mqtt_plugin_request(neu_plugin_t *plugin, neu_reqresp_head_t *head, switch (head->type) { case NEU_RESP_ERROR: - error = handle_write_response(plugin, head->ctx, data); + error = handle_write_response(plugin, head->ctx, data, scope); break; case NEU_RESP_GET_NODES_STATE: { handle_nodes_state(head->ctx, (neu_resp_get_nodes_state_t *) data); @@ -537,7 +537,7 @@ int mqtt_plugin_request(neu_plugin_t *plugin, neu_reqresp_head_t *head, } if (trace) { - neu_otel_scope_add_span_attr_int(scope, "error", error); + neu_otel_scope_add_span_attr_int(scope, "handle error", error); neu_otel_scope_set_span_end_time(scope, neu_time_ms()); neu_otel_trace_set_final(trace); }