Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http_client: new http client feature addition #9273

Draft
wants to merge 43 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
0129205
http_client: initial commit of the new http client
leonardo-albertovich Aug 24, 2024
20204b6
http_server: conflict resolution
leonardo-albertovich Aug 24, 2024
0a34ec8
tls: added alpn fetch functionality
leonardo-albertovich Aug 24, 2024
b104708
build: added http client and compatible signv4 module
leonardo-albertovich Aug 24, 2024
309d41a
signv4: added a new version compatible with the new http client
leonardo-albertovich Aug 24, 2024
6d8f650
in_elasticsearch: fixed http constants
leonardo-albertovich Aug 24, 2024
103d07a
in_opentelemetry: fixed http constants
leonardo-albertovich Aug 24, 2024
67ff471
in_prometheus_remote_write: fixed http constants
leonardo-albertovich Aug 24, 2024
823e5bc
in_splunk: fixed http constants
leonardo-albertovich Aug 24, 2024
3df1a9d
out_http: replaced http client with the new implementation
leonardo-albertovich Aug 24, 2024
7075137
in_http: fixed http constants
leonardo-albertovich Aug 24, 2024
65393e5
out_http: replaced compression mechanism
leonardo-albertovich Aug 26, 2024
79c8b0e
http_client: refactored compression code
leonardo-albertovich Aug 26, 2024
7f5d149
http_common: refactored compression code
leonardo-albertovich Aug 26, 2024
a025f3d
http_server: refactored compression code
leonardo-albertovich Aug 26, 2024
266d09d
http_client: refactored application interface
leonardo-albertovich Aug 27, 2024
4e96b93
http_common: relocated signv4 signature calculation routine
leonardo-albertovich Aug 27, 2024
bb4cacc
in_http: adapted the code to the new http lient api
leonardo-albertovich Aug 27, 2024
f57cc69
http_client: added concurrency support
leonardo-albertovich Aug 29, 2024
43425d4
http_common: fixed warning
leonardo-albertovich Aug 29, 2024
c7b3c9a
out_http: added missing error handling
leonardo-albertovich Aug 29, 2024
1d7b00d
out_loki: added http/2 support
leonardo-albertovich Aug 29, 2024
6c8f1f0
out_opentelemetry: added http/2 support
leonardo-albertovich Aug 29, 2024
961d46f
build: added lock component
leonardo-albertovich Aug 29, 2024
11558ce
tls: fixed warnings
leonardo-albertovich Aug 29, 2024
0e63c12
lock: added basic reusable lock component
leonardo-albertovich Aug 29, 2024
89aa1f4
http_client: added stand alone parameter setter and cleanup helper
leonardo-albertovich Aug 30, 2024
27039a3
out_loki: updated to use the proper cleanup helper
leonardo-albertovich Aug 30, 2024
ef1a6db
out_opentelemetry: updated to use the proper cleanup helper
leonardo-albertovich Aug 30, 2024
4ace0b2
out_http: updated to use the proper cleanup helper
leonardo-albertovich Aug 30, 2024
d15c2cb
out_prometheus_remote_write: updated to use the new http client
leonardo-albertovich Aug 30, 2024
13856fa
filter_ecs: updated to use the new http client
leonardo-albertovich Aug 30, 2024
f5e78b0
http_client: added URL based parameter setter and mocking capability
leonardo-albertovich Sep 2, 2024
425e9d6
filter_ecs: re-added mocking code
leonardo-albertovich Sep 2, 2024
e5fcdad
out_azure_kusto: updated to use the new http client
leonardo-albertovich Sep 2, 2024
d5c0c53
out_azure_logs_ingestion: updated to use the new http client
leonardo-albertovich Sep 2, 2024
4eafc0c
out_loki: removed legacy code
leonardo-albertovich Sep 2, 2024
99e3532
out_prometheus_remote_write: fixed wrong destructor usage
leonardo-albertovich Sep 2, 2024
525c105
out_opentelemetry: removed unused variable
leonardo-albertovich Sep 2, 2024
7686b1f
out_opensearch: updated to use the new HTTP client
leonardo-albertovich Sep 3, 2024
c4ac439
out_oracle_log_analytics: updated to use the new HTTP client
leonardo-albertovich Sep 3, 2024
b72f3b7
http_client: progress update
leonardo-albertovich Oct 15, 2024
44c5c1b
oauth: added new http client support
leonardo-albertovich Oct 15, 2024
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
210 changes: 210 additions & 0 deletions include/fluent-bit/flb_http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,20 @@
#define FLB_HTTP_CLIENT_H

#include <fluent-bit/flb_io.h>
#include <fluent-bit/flb_lock.h>
#include <fluent-bit/flb_upstream.h>
#include <fluent-bit/flb_callback.h>
#include <fluent-bit/flb_http_common.h>
#include <fluent-bit/flb_http_client_http1.h>
#include <fluent-bit/flb_http_client_http2.h>

#define HTTP_CLIENT_SUCCESS 0
#define HTTP_CLIENT_PROVIDER_ERROR -1

#define FLB_HTTP_CLIENT_FLAG_KEEPALIVE (((uint64_t) 1) << 0)
#define FLB_HTTP_CLIENT_FLAG_AUTO_DEFLATE (((uint64_t) 1) << 1)
#define FLB_HTTP_CLIENT_FLAG_AUTO_INFLATE (((uint64_t) 1) << 2)
#define FLB_HTTP_CLIENT_FLAG_STREAM_BODY (((uint64_t) 1) << 3)

/* Buffer size */
#define FLB_HTTP_BUF_SIZE 2048
Expand Down Expand Up @@ -62,6 +74,38 @@
#define FLB_HTTP_HEADER_CONNECTION "Connection"
#define FLB_HTTP_HEADER_KA "keep-alive"

#define FLB_HTTP_CLIENT_HEADER_ARRAY 0
#define FLB_HTTP_CLIENT_HEADER_LIST 1
#define FLB_HTTP_CLIENT_HEADER_CONFIG_MAP_LIST 2

#define FLB_HTTP_CLIENT_ARGUMENT_TYPE_TERMINATOR 0
#define FLB_HTTP_CLIENT_ARGUMENT_TYPE_METHOD 1
#define FLB_HTTP_CLIENT_ARGUMENT_TYPE_HOST 2
#define FLB_HTTP_CLIENT_ARGUMENT_TYPE_URI 3
#define FLB_HTTP_CLIENT_ARGUMENT_TYPE_URL 4
#define FLB_HTTP_CLIENT_ARGUMENT_TYPE_CONTENT_TYPE 5
#define FLB_HTTP_CLIENT_ARGUMENT_TYPE_BODY 6
#define FLB_HTTP_CLIENT_ARGUMENT_TYPE_HEADERS 7
#define FLB_HTTP_CLIENT_ARGUMENT_TYPE_AUTH_BASIC 8
#define FLB_HTTP_CLIENT_ARGUMENT_TYPE_AUTH_BEARER_TOKEN 9
#define FLB_HTTP_CLIENT_ARGUMENT_TYPE_AUTH_SIGNV4 10

#ifdef FLB_SYSTEM_WINDOWS
#ifdef _WIN64
typedef size_t * flb_http_client_size_t;
typedef size_t * flb_http_client_int64_t;
typedef size_t * flb_http_client_uint64_t;
#else
typedef size_t * flb_http_client_size_t;
typedef int64_t flb_http_client_int64_t;
typedef uint64_t flb_http_client_uint64_t;
#endif
#else
typedef size_t flb_http_client_size_t;
typedef int64_t flb_http_client_int64_t;
typedef uint64_t flb_http_client_uint64_t;
#endif

struct flb_http_client_response {
int status; /* HTTP response status */
int content_length; /* Content length set by headers */
Expand Down Expand Up @@ -136,6 +180,94 @@ struct flb_http_client {
void *cb_ctx;
};

struct flb_http_client_ng {
struct cfl_list sessions;

uint16_t port;
uint64_t flags;
int protocol_version;

int releasable;
void *user_data;

struct flb_upstream *upstream;
struct flb_upstream_ha *upstream_ha;

flb_lock_t lock;
};

struct flb_http_client_session {
struct flb_http1_client_session http1;
struct flb_http2_client_session http2;
struct cfl_list streams;

int protocol_version;

cfl_sds_t incoming_data;
cfl_sds_t outgoing_data;

int releasable;

struct cfl_list response_queue;

int stream_sequence_number;

struct flb_upstream_node *upstream_node;
struct flb_connection *connection;
struct flb_http_client_ng *parent;

struct cfl_list _head;
};

struct flb_aws_provider;

int flb_http_client_ng_init(struct flb_http_client_ng *client,
struct flb_upstream_ha *upstream_ha,
struct flb_upstream *upstream,
int protocol_version,
uint64_t flags);

struct flb_http_client_ng *flb_http_client_ng_create(
struct flb_upstream_ha *upstream_ha,
struct flb_upstream *upstream,
int protocol_version,
uint64_t flags);

void flb_http_client_ng_destroy(struct flb_http_client_ng *client);

int flb_http_client_session_init(struct flb_http_client_session *session,
struct flb_http_client_ng *client,
int protocol_version,
struct flb_connection *connection);

struct flb_http_client_session *flb_http_client_session_create(
struct flb_http_client_ng *client,
int protocol_version,
struct flb_connection *connection);

struct flb_http_client_session *flb_http_client_session_begin(
struct flb_http_client_ng *client);

void flb_http_client_session_destroy(struct flb_http_client_session *session);

struct flb_http_request *flb_http_client_request_begin(
struct flb_http_client_session *session);

struct flb_http_response *flb_http_client_request_execute(
struct flb_http_request *request);

struct flb_http_response *flb_http_client_request_execute_async(
struct flb_http_request *request);

void flb_http_client_request_destroy(struct flb_http_request *request,
int destroy_session);

int flb_http_client_session_ingest(struct flb_http_client_session *session,
unsigned char *buffer,
size_t length);



void flb_http_client_debug(struct flb_http_client *c,
struct flb_callback *cb_ctx);

Expand Down Expand Up @@ -163,6 +295,7 @@ int flb_http_set_callback_context(struct flb_http_client *c,

int flb_http_get_response_data(struct flb_http_client *c, size_t bytes_consumed);
int flb_http_do_request(struct flb_http_client *c, size_t *bytes);

int flb_http_do(struct flb_http_client *c, size_t *bytes);
int flb_http_client_proxy_connect(struct flb_connection *u_conn);
void flb_http_client_destroy(struct flb_http_client *c);
Expand All @@ -174,4 +307,81 @@ int flb_http_strip_port_from_host(struct flb_http_client *c);
int flb_http_allow_duplicated_headers(struct flb_http_client *c, int allow);
int flb_http_client_debug_property_is_valid(char *key, char *val);


#define FLB_HTTP_CLIENT_ARGUMENT(argument_type, ...) \
(flb_http_client_size_t) argument_type, __VA_ARGS__

#define FLB_HTTP_CLIENT_ARGUMENT_TERMINATOR() \
(flb_http_client_size_t) FLB_HTTP_CLIENT_ARGUMENT_TYPE_TERMINATOR

#define FLB_HTTP_CLIENT_ARGUMENT_METHOD(method) \
FLB_HTTP_CLIENT_ARGUMENT(FLB_HTTP_CLIENT_ARGUMENT_TYPE_METHOD, \
(flb_http_client_size_t) method)

#define FLB_HTTP_CLIENT_ARGUMENT_HOST(host) \
FLB_HTTP_CLIENT_ARGUMENT(FLB_HTTP_CLIENT_ARGUMENT_TYPE_HOST, \
host)

#define FLB_HTTP_CLIENT_ARGUMENT_URL(url) \
FLB_HTTP_CLIENT_ARGUMENT(FLB_HTTP_CLIENT_ARGUMENT_TYPE_URL, \
url)

#define FLB_HTTP_CLIENT_ARGUMENT_URI(uri) \
FLB_HTTP_CLIENT_ARGUMENT(FLB_HTTP_CLIENT_ARGUMENT_TYPE_URI, \
uri)

#define FLB_HTTP_CLIENT_ARGUMENT_CONTENT_TYPE(content_type) \
FLB_HTTP_CLIENT_ARGUMENT(FLB_HTTP_CLIENT_ARGUMENT_TYPE_CONTENT_TYPE, \
content_type)

#define FLB_HTTP_CLIENT_ARGUMENT_BODY(buffer, length, compression_algorithm) \
FLB_HTTP_CLIENT_ARGUMENT(FLB_HTTP_CLIENT_ARGUMENT_TYPE_BODY, \
buffer, \
(flb_http_client_size_t) length, \
compression_algorithm)

#define FLB_HTTP_CLIENT_ARGUMENT_HEADERS(data_type, headers) \
FLB_HTTP_CLIENT_ARGUMENT(FLB_HTTP_CLIENT_ARGUMENT_TYPE_HEADERS, \
(flb_http_client_size_t) data_type, \
headers)

#define FLB_HTTP_CLIENT_ARGUMENT_BASIC_AUTHORIZATION(username, password) \
FLB_HTTP_CLIENT_ARGUMENT(FLB_HTTP_CLIENT_ARGUMENT_TYPE_AUTH_BASIC, \
username, \
password)

#define FLB_HTTP_CLIENT_ARGUMENT_BEARER_TOKEN(token) \
FLB_HTTP_CLIENT_ARGUMENT(FLB_HTTP_CLIENT_ARGUMENT_TYPE_AUTH_BEARER_TOKEN, \
token)

#define FLB_HTTP_CLIENT_ARGUMENT_SIGNV4(aws_region, aws_service, aws_provider) \
FLB_HTTP_CLIENT_ARGUMENT(FLB_HTTP_CLIENT_ARGUMENT_TYPE_AUTH_SIGNV4, \
aws_region, \
aws_service, \
aws_provider)

int flb_http_request_set_parameters_internal(
struct flb_http_request *request,
va_list arguments);

int flb_http_request_set_parameters_unsafe(
struct flb_http_request *request,
...);

struct flb_http_request *flb_http_client_request_builder_unsafe(
struct flb_http_client_ng *client,
...);

#define flb_http_client_request_builder(client, ...) \
flb_http_client_request_builder_unsafe( \
client, \
__VA_ARGS__, \
FLB_HTTP_CLIENT_ARGUMENT_TERMINATOR());

#define flb_http_request_set_parameters(request, ...) \
flb_http_request_set_parameters_unsafe( \
request, \
__VA_ARGS__, \
FLB_HTTP_CLIENT_ARGUMENT_TERMINATOR());

#endif
46 changes: 46 additions & 0 deletions include/fluent-bit/flb_http_client_http1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2015-2024 The Fluent Bit Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef FLB_HTTP_CLIENT_HTTP1_H
#define FLB_HTTP_CLIENT_HTTP1_H

#include <fluent-bit/flb_http_common.h>

struct flb_http_client;
struct flb_http_client_session;

struct flb_http1_client_session {
struct flb_http_client *inner_session;
int initialized;
struct flb_http_client_session *parent;
};

int flb_http1_client_session_init(struct flb_http1_client_session *session);

void flb_http1_client_session_destroy(struct flb_http1_client_session *session);

int flb_http1_client_session_ingest(struct flb_http1_client_session *session,
unsigned char *buffer,
size_t length);

int flb_http1_request_begin(struct flb_http_request *request);

int flb_http1_request_commit(struct flb_http_request *request);

#endif
46 changes: 46 additions & 0 deletions include/fluent-bit/flb_http_client_http2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

/* Fluent Bit
* ==========
* Copyright (C) 2015-2024 The Fluent Bit Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef FLB_HTTP_CLIENT_HTTP2_H
#define FLB_HTTP_CLIENT_HTTP2_H

#include <fluent-bit/flb_http_common.h>
#include <nghttp2/nghttp2.h>

struct flb_http_client_session;

struct flb_http2_client_session {
nghttp2_session *inner_session;
int initialized;
struct flb_http_client_session *parent;
};

int flb_http2_client_session_init(struct flb_http2_client_session *session);

void flb_http2_client_session_destroy(struct flb_http2_client_session *session);

int flb_http2_client_session_ingest(struct flb_http2_client_session *session,
unsigned char *buffer,
size_t length);

int flb_http2_request_begin(struct flb_http_request *request);

int flb_http2_request_commit(struct flb_http_request *request);

#endif
Loading