Skip to content

Commit a02390b

Browse files
authored
Merge pull request #2249 from ZhouBox/v2.10
[v2.10]plugin:rm so and schema file when remove custom plugin && mqtt trace:add resp playload
2 parents 309610a + 18684d7 commit a02390b

File tree

5 files changed

+23
-5
lines changed

5 files changed

+23
-5
lines changed

plugins/mqtt/azure_iot_plugin.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ static int azure_plugin_request(neu_plugin_t *plugin, neu_reqresp_head_t *head,
330330

331331
switch (head->type) {
332332
case NEU_RESP_ERROR:
333-
error = handle_write_response(plugin, head->ctx, data);
333+
error = handle_write_response(plugin, head->ctx, data, NULL);
334334
break;
335335
case NEU_RESP_READ_GROUP:
336336
// error = handle_read_response(plugin, head->ctx, data);

plugins/mqtt/mqtt_handle.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ void handle_write_req(neu_mqtt_qos_e qos, const char *topic,
460460
}
461461

462462
int handle_write_response(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt_json,
463-
neu_resp_error_t *data)
463+
neu_resp_error_t *data, void *trace_scope)
464464
{
465465
int rv = 0;
466466
char *json_str = NULL;
@@ -485,6 +485,10 @@ int handle_write_response(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt_json,
485485
goto end;
486486
}
487487

488+
if (trace_scope) {
489+
neu_otel_scope_add_span_attr_string(trace_scope, "playload", json_str);
490+
}
491+
488492
char * topic = plugin->config.write_resp_topic;
489493
neu_mqtt_qos_e qos = plugin->config.qos;
490494
rv = publish(plugin, qos, topic, json_str, strlen(json_str));

plugins/mqtt/mqtt_handle.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void handle_write_req(neu_mqtt_qos_e qos, const char *topic,
4040
trace_w3c_t *trace_w3c);
4141

4242
int handle_write_response(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt_json,
43-
neu_resp_error_t *data);
43+
neu_resp_error_t *data, void *trace_scope);
4444

4545
void handle_read_req(neu_mqtt_qos_e qos, const char *topic,
4646
const uint8_t *payload, uint32_t len, void *data,

plugins/mqtt/mqtt_plugin_intf.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ int mqtt_plugin_request(neu_plugin_t *plugin, neu_reqresp_head_t *head,
482482

483483
switch (head->type) {
484484
case NEU_RESP_ERROR:
485-
error = handle_write_response(plugin, head->ctx, data);
485+
error = handle_write_response(plugin, head->ctx, data, scope);
486486
break;
487487
case NEU_RESP_GET_NODES_STATE: {
488488
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,
537537
}
538538

539539
if (trace) {
540-
neu_otel_scope_add_span_attr_int(scope, "error", error);
540+
neu_otel_scope_add_span_attr_int(scope, "handle error", error);
541541
neu_otel_scope_set_span_end_time(scope, neu_time_ms());
542542
neu_otel_trace_set_final(trace);
543543
}

src/core/plugin_manager.c

+14
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,20 @@ int neu_plugin_manager_del(neu_plugin_manager_t *mgr, const char *plugin_name)
252252
HASH_FIND_STR(mgr->plugins, plugin_name, plugin);
253253
if (plugin != NULL) {
254254
if (plugin->kind != NEU_PLUGIN_KIND_SYSTEM) {
255+
256+
char so_file_path[128] = { 0 };
257+
char schema_file_path[128] = { 0 };
258+
snprintf(so_file_path, sizeof(so_file_path), "%s/custom/%s",
259+
g_plugin_dir, plugin->lib_name);
260+
snprintf(schema_file_path, sizeof(schema_file_path),
261+
"%s/custom/schema/%s.json", g_plugin_dir, plugin->schema);
262+
if (remove(so_file_path) != 0) {
263+
nlog_error("rm %s file fail!", so_file_path);
264+
}
265+
if (remove(schema_file_path) != 0) {
266+
nlog_error("rm %s file fail!", schema_file_path);
267+
}
268+
255269
HASH_DEL(mgr->plugins, plugin);
256270
entity_free(plugin);
257271
ret = NEU_ERR_SUCCESS;

0 commit comments

Comments
 (0)