Skip to content

Commit 51b0390

Browse files
Leonardo Alminanaedsiper
authored andcommitted
in_opentelemetry: added proper profile event ingestion support
Signed-off-by: Leonardo Alminana <[email protected]>
1 parent d8fe33b commit 51b0390

File tree

1 file changed

+9
-76
lines changed

1 file changed

+9
-76
lines changed

plugins/in_opentelemetry/opentelemetry_prot.c

Lines changed: 9 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,45 +2675,29 @@ static int process_payload_profiles_ng(struct flb_opentelemetry *ctx,
26752675
struct flb_http_request *request,
26762676
struct flb_http_response *response)
26772677
{
2678-
cfl_sds_t text_encoded_profiles_context;
2679-
struct cprof *profiles_context;
2680-
struct flb_log_event_encoder *encoder;
2681-
size_t offset;
2682-
int ret;
2683-
2684-
encoder = flb_log_event_encoder_create(FLB_LOG_EVENT_FORMAT_FLUENT_BIT_V2);
2685-
2686-
if (encoder == NULL) {
2687-
return -1;
2688-
}
2678+
struct cprof *profiles_context;
2679+
size_t offset;
2680+
int ret;
26892681

26902682
if (request->content_type == NULL) {
2691-
flb_log_event_encoder_destroy(encoder);
2692-
26932683
flb_error("[otel] content type missing");
26942684

26952685
return -1;
26962686
}
26972687
else if (strcasecmp(request->content_type, "application/json") == 0) {
2698-
flb_log_event_encoder_destroy(encoder);
2699-
27002688
flb_error("[otel] unsuported profiles encoding type : %s",
27012689
request->content_type);
27022690

27032691
return -1;
27042692
}
27052693
else if (strcasecmp(request->content_type, "application/x-protobuf") == 0) {
2706-
flb_log_event_encoder_destroy(encoder);
2707-
27082694
flb_error("[otel] unsuported profiles encoding type : %s",
27092695
request->content_type);
27102696

27112697
return -1;
27122698
}
27132699
else if (strcasecmp(request->content_type, "application/grpc") == 0) {
27142700
if (cfl_sds_len(request->body) < 5) {
2715-
flb_log_event_encoder_destroy(encoder);
2716-
27172701
flb_error("[otel] malformed grpc packet of size %zu",
27182702
cfl_sds_len(request->body));
27192703

@@ -2729,69 +2713,21 @@ static int process_payload_profiles_ng(struct flb_opentelemetry *ctx,
27292713
&offset);
27302714

27312715
if (ret != CPROF_DECODE_OPENTELEMETRY_SUCCESS) {
2732-
flb_log_event_encoder_destroy(encoder);
2733-
27342716
flb_error("[otel] profile decoding error : %d",
27352717
ret);
27362718

27372719
return -1;
27382720
}
27392721

2740-
ret = cprof_encode_text_create(&text_encoded_profiles_context, profiles_context);
2722+
ret = flb_input_profiles_append(ctx->ins,
2723+
tag,
2724+
flb_sds_len(tag),
2725+
profiles_context);
27412726

27422727
cprof_decode_opentelemetry_destroy(profiles_context);
27432728

2744-
if (ret != CPROF_DECODE_OPENTELEMETRY_SUCCESS) {
2745-
flb_log_event_encoder_destroy(encoder);
2746-
2747-
flb_error("[otel] profile text encoding error : %d",
2748-
ret);
2749-
2750-
return -1;
2751-
}
2752-
2753-
flb_log_event_encoder_begin_record(encoder);
2754-
2755-
flb_log_event_encoder_set_current_timestamp(encoder);
2756-
2757-
ret = flb_log_event_encoder_append_body_values(
2758-
encoder,
2759-
FLB_LOG_EVENT_CSTRING_VALUE("Profile"),
2760-
FLB_LOG_EVENT_STRING_VALUE(text_encoded_profiles_context,
2761-
cfl_sds_len(text_encoded_profiles_context)));
2762-
2763-
cprof_encode_text_destroy(text_encoded_profiles_context);
2764-
2765-
if (ret != FLB_EVENT_ENCODER_SUCCESS) {
2766-
flb_log_event_encoder_destroy(encoder);
2767-
2768-
flb_error("[otel] re encoded profile ingestion error : %d",
2769-
ret);
2770-
2771-
return -1;
2772-
}
2773-
2774-
ret = flb_log_event_encoder_commit_record(encoder);
2775-
2776-
if (ret != FLB_EVENT_ENCODER_SUCCESS) {
2777-
flb_log_event_encoder_destroy(encoder);
2778-
2779-
flb_error("[otel] re encoded profile ingestion error : %d",
2780-
ret);
2781-
2782-
return -1;
2783-
}
2784-
2785-
ret = flb_input_log_append(ctx->ins,
2786-
tag,
2787-
flb_sds_len(tag),
2788-
encoder->output_buffer,
2789-
encoder->output_length);
2790-
2791-
if (ret != FLB_EVENT_ENCODER_SUCCESS) {
2792-
flb_log_event_encoder_destroy(encoder);
2793-
2794-
flb_error("[otel] re encoded profile ingestion error : %d",
2729+
if (ret != 0) {
2730+
flb_error("[otel] profile ingestion error : %d",
27952731
ret);
27962732

27972733
return -1;
@@ -2805,9 +2741,6 @@ static int process_payload_profiles_ng(struct flb_opentelemetry *ctx,
28052741
ret = -1;
28062742
}
28072743

2808-
2809-
flb_log_event_encoder_destroy(encoder);
2810-
28112744
return ret;
28122745
}
28132746

0 commit comments

Comments
 (0)