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: HTTP/2 client addition #9541

Merged
merged 21 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a42793e
http_client: initial commit of the new http client component
leonardo-albertovich Oct 29, 2024
bdc40db
tls: client side alpn support addition
leonardo-albertovich Oct 29, 2024
563a447
oauth2: new http client support added
leonardo-albertovich Oct 29, 2024
f4f2de1
signv4: new http client support added
leonardo-albertovich Oct 29, 2024
3e9e4f4
lock: locking layer previously used by the processor stack generalized
leonardo-albertovich Oct 29, 2024
494b84f
http_common: client side specific request and response additions
leonardo-albertovich Oct 29, 2024
99d1b34
http_server: deduplicated code and updated constant names
leonardo-albertovich Oct 29, 2024
d2e613a
build: added lock and http client related files
leonardo-albertovich Oct 29, 2024
7f95b0d
out_opentelemetry: added http/2 and grpc support
leonardo-albertovich Oct 29, 2024
fd0815c
out_splunk: updated constant names
leonardo-albertovich Oct 29, 2024
b0774c9
in_opensearch: updated constant names
leonardo-albertovich Oct 29, 2024
bcd65ac
in_http: updated constant names
leonardo-albertovich Oct 29, 2024
af8cf80
in_opentelemetry: updated constant names
leonardo-albertovich Oct 29, 2024
a283666
in_prometheus_remote_write: updated constant names
leonardo-albertovich Oct 29, 2024
e06f401
tests: runtime: in_http : added leftover directory handling
leonardo-albertovich Oct 30, 2024
44db629
http_common: fixed operation order when converting names to lowercase
leonardo-albertovich Oct 30, 2024
259a7be
http_server: fixed version detection when initializing sessions
leonardo-albertovich Oct 30, 2024
25c3ec1
lock: added missing header
leonardo-albertovich Oct 30, 2024
43b5b47
signv4: added type cast to fix msvc compilation issue
leonardo-albertovich Oct 30, 2024
0cd7286
tls: fixed macos compilation error
leonardo-albertovich Oct 30, 2024
fd40f7b
tls: fixed centos compilation error
leonardo-albertovich Oct 30, 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
215 changes: 215 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 @@ -63,6 +75,39 @@
#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_USER_AGENT 5
#define FLB_HTTP_CLIENT_ARGUMENT_TYPE_CONTENT_TYPE 6
#define FLB_HTTP_CLIENT_ARGUMENT_TYPE_BODY 7
#define FLB_HTTP_CLIENT_ARGUMENT_TYPE_HEADERS 8
#define FLB_HTTP_CLIENT_ARGUMENT_TYPE_AUTH_BASIC 9
#define FLB_HTTP_CLIENT_ARGUMENT_TYPE_AUTH_BEARER_TOKEN 10
#define FLB_HTTP_CLIENT_ARGUMENT_TYPE_AUTH_SIGNV4 11

#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 @@ -137,6 +182,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_step(
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 @@ -164,6 +297,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 @@ -175,4 +309,85 @@ 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_USER_AGENT(user_agent) \
FLB_HTTP_CLIENT_ARGUMENT(FLB_HTTP_CLIENT_ARGUMENT_TYPE_USER_AGENT, \
user_agent)

#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
Loading