Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cmetrics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# CMetrics Version
set(CMT_VERSION_MAJOR 2)
set(CMT_VERSION_MINOR 1)
set(CMT_VERSION_PATCH 3)
set(CMT_VERSION_PATCH 4)
set(CMT_VERSION_STR "${CMT_VERSION_MAJOR}.${CMT_VERSION_MINOR}.${CMT_VERSION_PATCH}")

# Include helpers
Expand Down
10 changes: 6 additions & 4 deletions lib/cmetrics/src/cmt_decode_prometheus.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,16 @@ int cmt_decode_prometheus_create(

result = cmt_decode_prometheus_parse(scanner, &context);

if (result == 0) {
if (context.errcode) {
result = context.errcode;
cmt_destroy(cmt);
reset_context(&context, true);
}
else if (result == 0) {
*out_cmt = cmt;
}
else {
cmt_destroy(cmt);
if (context.errcode) {
result = context.errcode;
}
reset_context(&context, true);
}

Expand Down
93 changes: 79 additions & 14 deletions lib/cmetrics/src/cmt_decode_prometheus.l
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,79 @@
%{

#include <cmetrics/cmt_decode_prometheus.h>
#include <stdio.h>

#define STRBUF_RET \
yylval->str = context->strbuf; \
context->strbuf = NULL

static void set_allocation_error(struct cmt_decode_prometheus_context *context)
{
context->errcode = CMT_DECODE_PROMETHEUS_ALLOCATION_ERROR;

if (context->opts.errbuf != NULL && context->opts.errbuf_size > 0) {
snprintf(context->opts.errbuf,
context->opts.errbuf_size - 1,
"memory allocation failed");
}
}

static int reset_strbuf(struct cmt_decode_prometheus_context *context)
{
if (context->strbuf != NULL) {
cfl_sds_destroy(context->strbuf);
}

context->strbuf = cfl_sds_create_size(256);
if (context->strbuf == NULL) {
set_allocation_error(context);

return -1;
}

return 0;
}

static int append_strbuf(struct cmt_decode_prometheus_context *context,
const char *text, int length)
{
cfl_sds_t result;

result = cfl_sds_cat(context->strbuf, text, length);
if (result == NULL) {
set_allocation_error(context);

return -1;
}

context->strbuf = result;

return 0;
}

#define STRBUF_CREATE() \
do { \
if (reset_strbuf(context) != 0) { \
return 0; \
} \
} while (0)

#define STRBUF_APPEND(text, length) \
do { \
if (append_strbuf(context, (text), (length)) != 0) { \
return 0; \
} \
} while (0)

#define SET_STR_TOKEN() \
do { \
yylval->str = cfl_sds_create(yytext); \
if (yylval->str == NULL) { \
set_allocation_error(context); \
return 0; \
} \
} while (0)

%}

/* here we define some states that allow us to create rules only
Expand Down Expand Up @@ -74,7 +142,7 @@

<HELPTAG,TYPETAG>[^ \t]+ {
// The next token will be the metric name
yylval->str = cfl_sds_create(yytext);
SET_STR_TOKEN();
return YYSTATE == HELPTAG ? HELP : TYPE;
}

Expand All @@ -86,7 +154,7 @@
// separate start condition for this to handle "\\" and "\n" escapes
// more easily.
BEGIN(INHELPTAG);
context->strbuf = cfl_sds_create_size(256);
STRBUF_CREATE();
}
else {
// For TYPETAG we enter INTYPETAG start condition to check only valid
Expand All @@ -107,17 +175,17 @@

<INHELPTAG>\\n {
// Process linefeed escape sequence
context->strbuf = cfl_sds_cat(context->strbuf, "\n", 1);
STRBUF_APPEND("\n", 1);
}

<INHELPTAG>\\\\ {
// Process backslack escape sequence
context->strbuf = cfl_sds_cat(context->strbuf, "\\", 1);
STRBUF_APPEND("\\", 1);
}

<INHELPTAG>[^\r\n\\]+ {
// Put everything that is not a backslash or a line feed into strbuf
context->strbuf = cfl_sds_cat(context->strbuf, yytext, yyleng);
STRBUF_APPEND(yytext, yyleng);
}

<INTYPETAG>counter {
Expand Down Expand Up @@ -146,26 +214,23 @@

["] {
BEGIN(INQUOTE);
if (context->strbuf != NULL) {
cfl_sds_destroy(context->strbuf);
}
context->strbuf = cfl_sds_create_size(256);
STRBUF_CREATE();
}

<INQUOTE>[\\]["] {
context->strbuf = cfl_sds_cat(context->strbuf, "\"", 1);
STRBUF_APPEND("\"", 1);
}

<INQUOTE>\\n {
context->strbuf = cfl_sds_cat(context->strbuf, "\n", 1);
STRBUF_APPEND("\n", 1);
}

<INQUOTE>\\\\ {
context->strbuf = cfl_sds_cat(context->strbuf, "\\", 1);
STRBUF_APPEND("\\", 1);
}

<INQUOTE>[^\r\n\\"]+ {
context->strbuf = cfl_sds_cat(context->strbuf, yytext, yyleng);
STRBUF_APPEND(yytext, yyleng);
}

<INQUOTE>["] {
Expand All @@ -180,7 +245,7 @@
}

[a-zA-Z_][a-zA-Z_0-9]* {
yylval->str = cfl_sds_create(yytext);
SET_STR_TOKEN();
return IDENTIFIER;
}

Expand Down
1 change: 1 addition & 0 deletions plugins/out_kafka/kafka.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ int produce_message(struct flb_time *tm, msgpack_object *map,
flb_info("[out_kafka] new topic added: %s", dynamic_topic);
}
}
flb_utils_split_free(topics);
flb_free(dynamic_topic);
}
}
Expand Down
6 changes: 1 addition & 5 deletions plugins/out_opentelemetry/opentelemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,10 @@ int opentelemetry_post(struct opentelemetry_context *ctx,

if (result != 0) {
flb_plg_error(ctx->ins, "error setting http authorization data");
flb_http_client_request_destroy(request, FLB_TRUE);

return FLB_RETRY;
}

flb_http_request_set_authorization(request,
HTTP_WWW_AUTHORIZATION_SCHEME_BASIC,
ctx->http_user,
ctx->http_passwd);
}

#ifdef FLB_HAVE_SIGNV4
Expand Down
80 changes: 64 additions & 16 deletions src/flb_http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -2899,6 +2899,9 @@ static int flb_http_encode_basic_auth_value(cfl_sds_t *output_buffer,
*output_buffer = sds_result;
}
else {
cfl_sds_destroy(*output_buffer);
*output_buffer = NULL;

result = -1;
}
}
Expand All @@ -2913,7 +2916,7 @@ static int flb_http_encode_basic_auth_value(cfl_sds_t *output_buffer,
cfl_sds_destroy(encoded_value);
cfl_sds_destroy(raw_value);

return 0;
return result;
}

static int flb_http_encode_bearer_auth_value(cfl_sds_t *output_buffer,
Expand Down Expand Up @@ -3082,34 +3085,59 @@ int flb_http_request_set_parameters_internal(
if (value_type == FLB_HTTP_CLIENT_ARGUMENT_TYPE_METHOD) {
method = va_arg(arguments, size_t);

flb_http_request_set_method(request, (int) method);
result = flb_http_request_set_method(request, (int) method);
if (result != 0) {
flb_debug("http request method error");

failure_detected = FLB_TRUE;
}
}
else if (value_type == FLB_HTTP_CLIENT_ARGUMENT_TYPE_HOST) {
host = va_arg(arguments, char *);

flb_http_request_set_host(request, host);
result = flb_http_request_set_host(request, host);
if (result != 0) {
flb_debug("http request host error");

failure_detected = FLB_TRUE;
}
}
else if (value_type == FLB_HTTP_CLIENT_ARGUMENT_TYPE_URL) {
url = va_arg(arguments, char *);

flb_http_request_set_url(request, url);
result = flb_http_request_set_url(request, url);
if (result != 0) {
flb_debug("http request URL error");

failure_detected = FLB_TRUE;
}
}
else if (value_type == FLB_HTTP_CLIENT_ARGUMENT_TYPE_URI) {
uri = va_arg(arguments, char *);

flb_http_request_set_uri(request, uri);
result = flb_http_request_set_uri(request, uri);
if (result != 0) {
flb_debug("http request URI error");

failure_detected = FLB_TRUE;
}
}
else if (value_type == FLB_HTTP_CLIENT_ARGUMENT_TYPE_USER_AGENT) {
user_agent = va_arg(arguments, char *);

flb_http_request_set_user_agent(request, user_agent);
result = flb_http_request_set_user_agent(request, user_agent);
if (result != 0) {
flb_debug("http request user agent error");

failure_detected = FLB_TRUE;
}
}
else if (value_type == FLB_HTTP_CLIENT_ARGUMENT_TYPE_CONTENT_TYPE) {
content_type = va_arg(arguments, char *);

result = flb_http_request_set_content_type(request, content_type);

if (request == NULL) {
if (result != 0) {
flb_debug("http request : error setting content type");

failure_detected = FLB_TRUE;
Expand All @@ -3125,8 +3153,8 @@ int flb_http_request_set_parameters_internal(
body_len,
compression_algorithm);

if (request == NULL) {
flb_debug("http request creation error");
if (result != 0) {
flb_debug("http request body error");

failure_detected = FLB_TRUE;
}
Expand Down Expand Up @@ -3188,17 +3216,31 @@ int flb_http_request_set_parameters_internal(
username = va_arg(arguments, char *);
password = va_arg(arguments, char *);

flb_http_request_set_authorization(request,
HTTP_WWW_AUTHORIZATION_SCHEME_BASIC,
username,
password);
result = flb_http_request_set_authorization(
request,
HTTP_WWW_AUTHORIZATION_SCHEME_BASIC,
username,
password);

if (result != 0) {
flb_debug("http request basic authorization error");

failure_detected = FLB_TRUE;
}
}
else if (value_type == FLB_HTTP_CLIENT_ARGUMENT_TYPE_AUTH_BEARER_TOKEN) {
bearer_token = va_arg(arguments, char *);

flb_http_request_set_authorization(request,
HTTP_WWW_AUTHORIZATION_SCHEME_BEARER,
bearer_token);
result = flb_http_request_set_authorization(
request,
HTTP_WWW_AUTHORIZATION_SCHEME_BEARER,
bearer_token);

if (result != 0) {
flb_debug("http request bearer authorization error");

failure_detected = FLB_TRUE;
}
}
else if (value_type == FLB_HTTP_CLIENT_ARGUMENT_TYPE_AUTH_SIGNV4) {
aws_region = va_arg(arguments, char *);
Expand All @@ -3209,6 +3251,12 @@ int flb_http_request_set_parameters_internal(
aws_region,
aws_service,
aws_provider);

if (result != 0) {
flb_debug("http request signv4 authorization error");

failure_detected = FLB_TRUE;
}
}
} while (!failure_detected &&
value_type != FLB_HTTP_CLIENT_ARGUMENT_TYPE_TERMINATOR);
Expand Down
Loading
Loading