Skip to content

Commit d383b47

Browse files
committed
out_kinesis_streams: add custom port support for Kinesis output plugin
This patch adds the ability to set a custom port for the Kinesis Streams output plugin. It introduces a new configuration option 'Port' that allows users to specify a non-standard port when connecting to the Kinesis service. The implementation includes: - Using the port number set in the output instance's host structure - Falling back to the default HTTPS port (443) if no port is specified - Validating the port number to ensure it's within the valid range (1-65535) - Adding appropriate debug and error logging This feature is useful for scenarios involving proxies or custom network configurations. It has been tested with various port configurations, including the default, custom ports, and invalid inputs. Signed-off-by: Mikhail [azalio] Petrov <[email protected]>
1 parent fe43ed1 commit d383b47

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

plugins/out_kinesis_streams/kinesis.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,30 @@ static int cb_kinesis_init(struct flb_output_instance *ins,
117117
if (tmp) {
118118
ctx->sts_endpoint = (char *) tmp;
119119
}
120-
120+
/*
121+
* Sets the port number for the Kinesis output plugin.
122+
*
123+
* This function uses the port number already set in the output instance's host structure.
124+
* If the port is not set (0), the default HTTPS port is used.
125+
*
126+
* @param ins The output instance.
127+
* @param ctx The Kinesis output plugin context.
128+
*/
129+
flb_plg_debug(ins, "Retrieved port from ins->host.port: %d", ins->host.port);
130+
131+
if (ins->host.port >= FLB_KINESIS_MIN_PORT && ins->host.port <= FLB_KINESIS_MAX_PORT) {
132+
ctx->port = ins->host.port;
133+
flb_plg_debug(ins, "Setting port to: %d", ctx->port);
134+
}
135+
else if (ins->host.port == 0) {
136+
ctx->port = FLB_KINESIS_DEFAULT_HTTPS_PORT;
137+
flb_plg_debug(ins, "Port not set. Using default HTTPS port: %d", ctx->port);
138+
}
139+
else {
140+
flb_plg_error(ins, "Invalid port number: %d. Must be between %d and %d",
141+
ins->host.port, FLB_KINESIS_MIN_PORT, FLB_KINESIS_MAX_PORT);
142+
goto error;
143+
}
121144

122145
tmp = flb_output_get_property("log_key", ins);
123146
if (tmp) {
@@ -255,14 +278,14 @@ static int cb_kinesis_init(struct flb_output_instance *ins,
255278
ctx->kinesis_client->region = (char *) ctx->region;
256279
ctx->kinesis_client->retry_requests = ctx->retry_requests;
257280
ctx->kinesis_client->service = "kinesis";
258-
ctx->kinesis_client->port = 443;
281+
ctx->kinesis_client->port = ctx->port;
259282
ctx->kinesis_client->flags = 0;
260283
ctx->kinesis_client->proxy = NULL;
261284
ctx->kinesis_client->static_headers = &content_type_header;
262285
ctx->kinesis_client->static_headers_len = 1;
263286

264287
struct flb_upstream *upstream = flb_upstream_create(config, ctx->endpoint,
265-
443, FLB_IO_TLS,
288+
ctx->port, FLB_IO_TLS,
266289
ctx->client_tls);
267290
if (!upstream) {
268291
flb_plg_error(ctx->ins, "Connection initialization error");

plugins/out_kinesis_streams/kinesis.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929

3030
#define DEFAULT_TIME_KEY_FORMAT "%Y-%m-%dT%H:%M:%S"
3131

32+
#define FLB_KINESIS_DEFAULT_HTTPS_PORT 443
33+
#define FLB_KINESIS_MIN_PORT 1
34+
#define FLB_KINESIS_MAX_PORT 65535
35+
3236
/* buffers used for each flush */
3337
struct flush {
3438
/* temporary buffer for storing the serialized event messages */
@@ -92,6 +96,7 @@ struct flb_kinesis {
9296
int retry_requests;
9397
char *sts_endpoint;
9498
int custom_endpoint;
99+
int port;
95100
char *profile;
96101

97102
/* in this plugin the 'random' partition key is a uuid + fluent tag + timestamp */

0 commit comments

Comments
 (0)