Skip to content

Commit 1ae8ed9

Browse files
committed
processor_sampling: fix handling of dropped spans
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 131f55d commit 1ae8ed9

File tree

3 files changed

+16
-34
lines changed

3 files changed

+16
-34
lines changed

plugins/processor_sampling/sampling_conf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,16 @@ void sampling_config_destroy(struct flb_config *config, struct sampling *ctx)
235235
return;
236236
}
237237

238-
if (ctx->sampling_conditions) {
239-
sampling_conditions_destroy(ctx->sampling_conditions);
240-
}
241-
242238
if (ctx->plugin) {
243239
if (ctx->plugin->cb_exit) {
244240
ctx->plugin->cb_exit(config, ctx->plugin_context);
245241
}
246242
}
247243

244+
if (ctx->sampling_conditions) {
245+
sampling_conditions_destroy(ctx->sampling_conditions);
246+
}
247+
248248
flb_kv_release(&ctx->plugin_settings_properties);
249249

250250
if (ctx->plugin_config_map) {

plugins/processor_sampling/sampling_span_registry.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,16 @@ struct sampling_span_registry *sampling_span_registry_create(uint64_t max_traces
4646
return reg;
4747
}
4848

49-
static void sampling_span_registry_delete_traces(struct sampling *ctx, struct sampling_span_registry *reg)
49+
static void sampling_span_registry_delete_traces(struct sampling *ctx,
50+
struct sampling_span_registry *reg)
5051
{
5152
struct cfl_list *head;
5253
struct cfl_list *tmp;
5354
struct trace_entry *t_entry;
5455

5556
cfl_list_foreach_safe(head, tmp, &reg->trace_list) {
5657
t_entry = cfl_list_entry(head, struct trace_entry, _head);
57-
cfl_list_del(&t_entry->_head);
58-
cfl_list_del(&t_entry->_head_complete);
59-
60-
/* free the trace_entry */
61-
cfl_sds_destroy(t_entry->hex_trace_id);
62-
63-
ctr_id_destroy(t_entry->trace_id);
64-
flb_free(t_entry);
58+
sampling_span_registry_delete_entry(ctx, reg, t_entry, FLB_TRUE);
6559
}
6660
}
6761

@@ -88,9 +82,14 @@ int sampling_span_registry_delete_entry(struct sampling *ctx, struct sampling_sp
8882
struct trace_span *t_span;
8983

9084
/* remove from the hash table */
91-
ret = flb_hash_table_del_ptr(reg->ht, ctr_id_get_buf(t_entry->trace_id), ctr_id_get_len(t_entry->trace_id), t_entry);
85+
ret = flb_hash_table_del_ptr(reg->ht,
86+
ctr_id_get_buf(t_entry->trace_id),
87+
ctr_id_get_len(t_entry->trace_id),
88+
t_entry);
9289
if (ret == -1) {
93-
flb_plg_error(ctx->ins, "failed to delete trace entry from buffer");
90+
if (ctx != NULL) {
91+
flb_plg_error(ctx->ins, "failed to delete trace entry from buffer");
92+
}
9493
return -1;
9594
}
9695

plugins/processor_sampling/sampling_tail.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -411,20 +411,6 @@ static int check_conditions(struct sampling *ctx, struct trace_entry *t_entry)
411411
return FLB_FALSE;
412412
}
413413

414-
static void trace_entry_delete_spans(struct trace_entry *t_entry)
415-
{
416-
struct cfl_list *tmp;
417-
struct cfl_list *head;
418-
struct trace_span *t_span;
419-
420-
cfl_list_foreach_safe(head, tmp, &t_entry->span_list) {
421-
t_span = cfl_list_entry(head, struct trace_span, _head);
422-
cfl_list_del(&t_span->_head);
423-
ctr_span_destroy(t_span->span);
424-
flb_free(t_span);
425-
}
426-
}
427-
428414
static int reconcile_and_dispatch_traces(struct sampling *ctx, struct sampling_settings *settings)
429415
{
430416
int ret;
@@ -451,11 +437,8 @@ static int reconcile_and_dispatch_traces(struct sampling *ctx, struct sampling_s
451437
*/
452438
ret = check_conditions(ctx, t_entry);
453439
if (ret == FLB_FALSE) {
454-
/* t_entry has many t_spans, since the spans will be discarded is safe to remove it original ctr_span reference */
455-
trace_entry_delete_spans(t_entry);
456-
457-
/* remove the trace entry */
458-
sampling_span_registry_delete_entry(ctx, settings->span_reg, t_entry, FLB_FALSE);
440+
/* discard the trace and delete all associated spans */
441+
sampling_span_registry_delete_entry(ctx, settings->span_reg, t_entry, FLB_TRUE);
459442
continue;
460443
}
461444

0 commit comments

Comments
 (0)