/src/fluent-bit/plugins/in_opentelemetry/opentelemetry_config.c
Line | Count | Source |
1 | | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* Fluent Bit |
4 | | * ========== |
5 | | * Copyright (C) 2015-2026 The Fluent Bit Authors |
6 | | * |
7 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | | * you may not use this file except in compliance with the License. |
9 | | * You may obtain a copy of the License at |
10 | | * |
11 | | * http://www.apache.org/licenses/LICENSE-2.0 |
12 | | * |
13 | | * Unless required by applicable law or agreed to in writing, software |
14 | | * distributed under the License is distributed on an "AS IS" BASIS, |
15 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | | * See the License for the specific language governing permissions and |
17 | | * limitations under the License. |
18 | | */ |
19 | | |
20 | | #include <fluent-bit/flb_input_plugin.h> |
21 | | #include <fluent-bit/flb_oauth2_jwt.h> |
22 | | #include "opentelemetry.h" |
23 | | |
24 | | /* default HTTP port for OTLP/HTTP is 4318 */ |
25 | 0 | #define OTLP_HTTP_PORT 4318 |
26 | | |
27 | | struct flb_opentelemetry *opentelemetry_config_create(struct flb_input_instance *ins) |
28 | 0 | { |
29 | 0 | int ret; |
30 | 0 | char port[8]; |
31 | 0 | struct flb_opentelemetry *ctx; |
32 | |
|
33 | 0 | ctx = flb_calloc(1, sizeof(struct flb_opentelemetry)); |
34 | 0 | if (!ctx) { |
35 | 0 | flb_errno(); |
36 | 0 | return NULL; |
37 | 0 | } |
38 | 0 | ctx->ins = ins; |
39 | 0 | ctx->oauth2_cfg.jwks_refresh_interval = 300; |
40 | 0 | ctx->oauth2_cfg.jwks_buffer_max_size = 1000000; |
41 | 0 | ctx->oauth2_cfg.jwks_response_timeout = 30; |
42 | | |
43 | | /* Load the config map */ |
44 | 0 | ret = flb_input_config_map_set(ins, (void *) ctx); |
45 | 0 | if (ret == -1) { |
46 | 0 | flb_free(ctx); |
47 | 0 | return NULL; |
48 | 0 | } |
49 | | |
50 | 0 | if (ins->oauth2_jwt_config_map && mk_list_size(&ins->oauth2_jwt_properties) > 0) { |
51 | 0 | ret = flb_config_map_set(ins->config, |
52 | 0 | &ins->oauth2_jwt_properties, |
53 | 0 | ins->oauth2_jwt_config_map, |
54 | 0 | &ctx->oauth2_cfg); |
55 | 0 | if (ret == -1) { |
56 | 0 | flb_free(ctx); |
57 | 0 | return NULL; |
58 | 0 | } |
59 | 0 | } |
60 | | |
61 | | /* Listen interface (if not set, defaults to 0.0.0.0:4318) */ |
62 | 0 | flb_input_net_default_listener("0.0.0.0", OTLP_HTTP_PORT, ins); |
63 | |
|
64 | 0 | ctx->listen = flb_strdup(ins->host.listen); |
65 | 0 | snprintf(port, sizeof(port) - 1, "%d", ins->host.port); |
66 | 0 | ctx->tcp_port = flb_strdup(port); |
67 | |
|
68 | 0 | return ctx; |
69 | 0 | } |
70 | | |
71 | | int opentelemetry_config_destroy(struct flb_opentelemetry *ctx) |
72 | 0 | { |
73 | 0 | flb_http_server_destroy(&ctx->http_server); |
74 | |
|
75 | 0 | if (ctx->oauth2_ctx) { |
76 | 0 | flb_oauth2_jwt_context_destroy(ctx->oauth2_ctx); |
77 | 0 | ctx->oauth2_ctx = NULL; |
78 | 0 | } |
79 | |
|
80 | 0 | flb_free(ctx->listen); |
81 | 0 | flb_free(ctx->tcp_port); |
82 | 0 | flb_free(ctx); |
83 | |
|
84 | 0 | return 0; |
85 | 0 | } |