Skip to content

Commit

Permalink
in_prometheus_remote_write: Use abbriviated names for promethues remo…
Browse files Browse the repository at this point in the history
…te write

Signed-off-by: Hiroshi Hatake <[email protected]>
  • Loading branch information
cosmo0920 committed May 1, 2024
1 parent 7f024a4 commit 336cc0b
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 160 deletions.
8 changes: 4 additions & 4 deletions plugins/in_prometheus_remote_write/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ if(NOT FLB_METRICS)
endif()

set(src
in_prometheus_remote_write.c
in_prometheus_remote_write_prot.c
in_prometheus_remote_write_conn.c
in_prometheus_remote_write_config.c
prom_rw.c
prom_rw_prot.c
prom_rw_conn.c
prom_rw_config.c
)

FLB_PLUGIN(in_prometheus_remote_write "${src}" "monkey-core-static")

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
#include <fluent-bit/flb_network.h>
#include <fluent-bit/flb_config.h>

#include "in_prometheus_remote_write.h"
#include "in_prometheus_remote_write_conn.h"
#include "in_prometheus_remote_write_prot.h"
#include "in_prometheus_remote_write_config.h"
#include "prom_rw.h"
#include "prom_rw_conn.h"
#include "prom_rw_prot.h"
#include "prom_rw_config.h"

/*
* For a server event, the collection event means a new client have arrived, we
* accept the connection and create a new TCP instance which will wait for
* JSON map messages.
*/
static int in_prometheus_remote_write_collect(struct flb_input_instance *ins,
struct flb_config *config, void *in_context)
static int prom_rw_collect(struct flb_input_instance *ins,
struct flb_config *config, void *in_context)
{
struct flb_connection *connection;
struct in_prometheus_remote_write_conn *conn;
struct flb_in_prometheus_remote_write *ctx;
struct prom_remote_write_conn *conn;
struct flb_prom_remote_write *ctx;

ctx = in_context;

Expand All @@ -52,7 +52,7 @@ static int in_prometheus_remote_write_collect(struct flb_input_instance *ins,

flb_plg_trace(ctx->ins, "new TCP connection arrived FD=%i", connection->fd);

conn = in_prometheus_remote_write_conn_add(connection, ctx);
conn = prom_rw_conn_add(connection, ctx);

if (conn == NULL) {
return -1;
Expand All @@ -61,17 +61,17 @@ static int in_prometheus_remote_write_collect(struct flb_input_instance *ins,
return 0;
}

static int in_prometheus_remote_write_init(struct flb_input_instance *ins,
struct flb_config *config, void *data)
static int prom_rw_init(struct flb_input_instance *ins,
struct flb_config *config, void *data)
{
unsigned short int port;
int ret;
struct flb_in_prometheus_remote_write *ctx;
struct flb_prom_remote_write *ctx;

(void) data;

/* Create context and basic conf */
ctx = in_prometheus_remote_write_config_create(ins);
ctx = prom_rw_config_create(ins);
if (!ctx) {
return -1;
}
Expand All @@ -81,7 +81,7 @@ static int in_prometheus_remote_write_init(struct flb_input_instance *ins,
ret = flb_input_config_map_set(ins, (void *) ctx);
if (ret == -1) {
flb_plg_error(ctx->ins, "configuration error");
in_prometheus_remote_write_config_destroy(ctx);
prom_rw_config_destroy(ctx);
return -1;
}

Expand All @@ -93,7 +93,7 @@ static int in_prometheus_remote_write_init(struct flb_input_instance *ins,
if (ctx->enable_http2) {
ret = flb_http_server_init(&ctx->http_server,
HTTP_PROTOCOL_AUTODETECT,
FLB_HTTP_SERVER_FLAG_AUTO_INFLATE,
(FLB_HTTP_SERVER_FLAG_KEEPALIVE | FLB_HTTP_SERVER_FLAG_AUTO_INFLATE),
NULL,
ins->host.listen,
ins->host.port,
Expand All @@ -109,7 +109,7 @@ static int in_prometheus_remote_write_init(struct flb_input_instance *ins,
"could not initialize http server on %s:%u. Aborting",
ins->host.listen, ins->host.port);

in_prometheus_remote_write_config_destroy(ctx);
prom_rw_config_destroy(ctx);

return -1;
}
Expand All @@ -121,12 +121,12 @@ static int in_prometheus_remote_write_init(struct flb_input_instance *ins,
"could not start http server on %s:%u. Aborting",
ins->host.listen, ins->host.port);

in_prometheus_remote_write_config_destroy(ctx);
prom_rw_config_destroy(ctx);

return -1;
}

ctx->http_server.request_callback = in_prometheus_remote_write_prot_handle_ng;
ctx->http_server.request_callback = prom_rw_prot_handle_ng;

flb_input_downstream_set(ctx->http_server.downstream, ctx->ins);
}
Expand All @@ -144,7 +144,7 @@ static int in_prometheus_remote_write_init(struct flb_input_instance *ins,
"could not initialize downstream on %s:%s. Aborting",
ctx->listen, ctx->tcp_port);

in_prometheus_remote_write_config_destroy(ctx);
prom_rw_config_destroy(ctx);

return -1;
}
Expand All @@ -153,12 +153,12 @@ static int in_prometheus_remote_write_init(struct flb_input_instance *ins,

/* Collect upon data available on the standard input */
ret = flb_input_set_collector_socket(ins,
in_prometheus_remote_write_collect,
ctx->downstream->server_fd,
config);
prom_rw_collect,
ctx->downstream->server_fd,
config);
if (ret == -1) {
flb_plg_error(ctx->ins, "Could not set collector for IN_TCP input plugin");
in_prometheus_remote_write_config_destroy(ctx);
prom_rw_config_destroy(ctx);
return -1;
}

Expand All @@ -178,16 +178,16 @@ static int in_prometheus_remote_write_init(struct flb_input_instance *ins,
return 0;
}

static int in_prometheus_remote_write_exit(void *data, struct flb_config *config)
static int prom_rw_exit(void *data, struct flb_config *config)
{
struct flb_in_prometheus_remote_write *ctx;
struct flb_prom_remote_write *ctx;

(void) config;

ctx = data;

if (ctx != NULL) {
in_prometheus_remote_write_config_destroy(ctx);
prom_rw_config_destroy(ctx);
}

return 0;
Expand All @@ -197,36 +197,36 @@ static int in_prometheus_remote_write_exit(void *data, struct flb_config *config
static struct flb_config_map config_map[] = {
{
FLB_CONFIG_MAP_BOOL, "http2", "true",
0, FLB_TRUE, offsetof(struct flb_in_prometheus_remote_write, enable_http2),
0, FLB_TRUE, offsetof(struct flb_prom_remote_write, enable_http2),
NULL
},

{
FLB_CONFIG_MAP_SIZE, "buffer_max_size", HTTP_BUFFER_MAX_SIZE,
0, FLB_TRUE, offsetof(struct flb_in_prometheus_remote_write, buffer_max_size),
0, FLB_TRUE, offsetof(struct flb_prom_remote_write, buffer_max_size),
""
},

{
FLB_CONFIG_MAP_SIZE, "buffer_chunk_size", HTTP_BUFFER_CHUNK_SIZE,
0, FLB_TRUE, offsetof(struct flb_in_prometheus_remote_write, buffer_chunk_size),
0, FLB_TRUE, offsetof(struct flb_prom_remote_write, buffer_chunk_size),
""
},

{
FLB_CONFIG_MAP_STR, "uri", NULL,
0, FLB_TRUE, offsetof(struct flb_in_prometheus_remote_write, uri),
0, FLB_TRUE, offsetof(struct flb_prom_remote_write, uri),
"Specify an optional HTTP URI for the target web server, e.g: /something"
},

{
FLB_CONFIG_MAP_BOOL, "tag_from_uri", "true",
0, FLB_TRUE, offsetof(struct flb_in_prometheus_remote_write, tag_from_uri),
0, FLB_TRUE, offsetof(struct flb_prom_remote_write, tag_from_uri),
"If true, tag will be created from uri. e.g. v1_metrics from /v1/metrics ."
},
{
FLB_CONFIG_MAP_INT, "successful_response_code", "201",
0, FLB_TRUE, offsetof(struct flb_in_prometheus_remote_write, successful_response_code),
0, FLB_TRUE, offsetof(struct flb_prom_remote_write, successful_response_code),
"Set successful response code. 200, 201 and 204 are supported."
},

Expand All @@ -238,13 +238,13 @@ static struct flb_config_map config_map[] = {
struct flb_input_plugin in_prometheus_remote_write_plugin = {
.name = "prometheus_remote_write",
.description = "Prometheus Remote Write input",
.cb_init = in_prometheus_remote_write_init,
.cb_init = prom_rw_init,
.cb_pre_run = NULL,
.cb_collect = in_prometheus_remote_write_collect,
.cb_collect = prom_rw_collect,
.cb_flush_buf = NULL,
.cb_pause = NULL,
.cb_resume = NULL,
.cb_exit = in_prometheus_remote_write_exit,
.cb_exit = prom_rw_exit,
.config_map = config_map,
.flags = FLB_INPUT_NET_SERVER | FLB_IO_OPT_TLS
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* limitations under the License.
*/

#ifndef FLB_IN_PROMETHEUS_REMOTE_WRITE_H
#define FLB_IN_PROMETHEUS_REMOTE_WRITE_H
#ifndef FLB_IN_PROM_RW_H
#define FLB_IN_PROM_RW_H

#include <fluent-bit/flb_config.h>
#include <fluent-bit/flb_input.h>
Expand All @@ -30,7 +30,7 @@
#define HTTP_BUFFER_MAX_SIZE "4M"
#define HTTP_BUFFER_CHUNK_SIZE "512K"

struct flb_in_prometheus_remote_write {
struct flb_prom_remote_write {
int successful_response_code;
flb_sds_t listen;
flb_sds_t tcp_port;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
#include <fluent-bit/flb_input_plugin.h>
#include <fluent-bit/flb_downstream.h>

#include "in_prometheus_remote_write.h"
#include "in_prometheus_remote_write_conn.h"
#include "prom_rw.h"
#include "prom_rw_conn.h"

/* default HTTP port for prometheus remote write */
#define PROMETHEUS_REMOTE_WRITE_HTTP_PORT 80
#define PROMETHEUS_REMOTE_WRITE_HTTP_PORT 8080

struct flb_in_prometheus_remote_write *in_prometheus_remote_write_config_create(struct flb_input_instance *ins)
struct flb_prom_remote_write *prom_rw_config_create(struct flb_input_instance *ins)
{
int ret;
char port[8];
struct flb_in_prometheus_remote_write *ctx;
struct flb_prom_remote_write *ctx;

ctx = flb_calloc(1, sizeof(struct flb_in_prometheus_remote_write));
ctx = flb_calloc(1, sizeof(struct flb_prom_remote_write));
if (!ctx) {
flb_errno();
return NULL;
Expand Down Expand Up @@ -65,10 +65,10 @@ struct flb_in_prometheus_remote_write *in_prometheus_remote_write_config_create(
return ctx;
}

int in_prometheus_remote_write_config_destroy(struct flb_in_prometheus_remote_write *ctx)
int prom_rw_config_destroy(struct flb_prom_remote_write *ctx)
{
/* release all connections */
in_prometheus_remote_write_conn_release_all(ctx);
prom_rw_conn_release_all(ctx);

if (ctx->collector_id != -1) {
flb_input_collector_delete(ctx->collector_id, ctx->ins);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* limitations under the License.
*/

#ifndef FLB_IN_PROMETHEUS_REMOTE_WRITE_CONFIG_H
#define FLB_IN_PROMETHEUS_REMOTE_WRITE_CONFIG_H
#ifndef FLB_IN_PROM_RW_CONFIG_H
#define FLB_IN_PROM_RW_CONFIG_H

#include <fluent-bit/flb_input_plugin.h>
#include "in_prometheus_remote_write.h"
#include "prom_rw.h"

struct flb_in_prometheus_remote_write *in_prometheus_remote_write_config_create(struct flb_input_instance *ins);
int in_prometheus_remote_write_config_destroy(struct flb_in_prometheus_remote_write *ctx);
struct flb_prom_remote_write *prom_rw_config_create(struct flb_input_instance *ins);
int prom_rw_config_destroy(struct flb_prom_remote_write *ctx);

#endif
Loading

0 comments on commit 336cc0b

Please sign in to comment.