syslog-ng source
http-loadbalancer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Balazs Scheidler
3  * Copyright (c) 2018 Balabit
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published
7  * by the Free Software Foundation, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * As an additional exemption you are allowed to compile & link against the
19  * OpenSSL libraries as published by the OpenSSL project. See the file
20  * COPYING for details.
21  *
22  */
23 
24 #ifndef HTTP_LOADBALANCER_H_INCLUDED
25 #define HTTP_LOADBALANCER_H_INCLUDED 1
26 
27 #include "template/templates.h"
28 
29 typedef enum
30 {
34 
35 typedef struct _HTTPLoadBalancerTarget HTTPLoadBalancerTarget;
36 typedef struct _HTTPLoadBalancerClient HTTPLoadBalancerClient;
37 typedef struct _HTTPLoadBalancer HTTPLoadBalancer;
38 
39 
40 /* NOTE: this struct represents an actual HTTP target URL. The existence of
41  * this structure is ensured even in multi-threaded environments. Some of
42  * the members of the struct are read-only and are _always_ available
43  * without locking. Others are protected by the LoadBalancer's lock and
44  * should be manipulated under the protection of that lock.
45  */
47 {
48  /* read-only data, no need to lock */
49  LogTemplate *url_template;
50  gint index;
51  /* read-write data, locking must be in effect */
56  gchar formatted_index[16];
57 };
58 
59 gboolean http_lb_target_is_url_templated(HTTPLoadBalancerTarget *self);
60 const gchar *http_lb_target_get_literal_url(HTTPLoadBalancerTarget *self);
61 void http_lb_target_format_templated_url(HTTPLoadBalancerTarget *self, LogMessage *msg,
62  const LogTemplateOptions *template_options, GString *result);
63 
65 {
66  HTTPLoadBalancerTarget *target;
67 };
68 
69 void http_lb_client_init(HTTPLoadBalancerClient *, HTTPLoadBalancer *lb);
70 void http_lb_client_deinit(HTTPLoadBalancerClient *);
71 
73 {
74  GMutex lock;
75  HTTPLoadBalancerTarget *targets;
81 };
82 
83 HTTPLoadBalancerTarget *http_load_balancer_choose_target(HTTPLoadBalancer *self, HTTPLoadBalancerClient *lbc);
84 gboolean http_load_balancer_add_target(HTTPLoadBalancer *self, const gchar *url, GError **error);
85 void http_load_balancer_drop_all_targets(HTTPLoadBalancer *self);
86 void http_load_balancer_track_client(HTTPLoadBalancer *self, HTTPLoadBalancerClient *lbc);
87 void http_load_balancer_set_target_failed(HTTPLoadBalancer *self, HTTPLoadBalancerTarget *target);
88 void http_load_balancer_set_target_successful(HTTPLoadBalancer *self, HTTPLoadBalancerTarget *target);
89 gboolean http_load_balancer_is_url_templated(HTTPLoadBalancer *self);
90 
91 void http_load_balancer_set_recovery_timeout(HTTPLoadBalancer *self, gint recovery_timeout);
92 HTTPLoadBalancer *http_load_balancer_new(void);
93 void http_load_balancer_free(HTTPLoadBalancer *self);
94 
95 
96 
97 #endif
gboolean http_load_balancer_is_url_templated(HTTPLoadBalancer *self)
Definition: http-loadbalancer.c:400
void http_load_balancer_set_target_successful(HTTPLoadBalancer *self, HTTPLoadBalancerTarget *target)
Definition: http-loadbalancer.c:385
void http_lb_client_deinit(HTTPLoadBalancerClient *)
Definition: http-loadbalancer.c:193
void http_load_balancer_drop_all_targets(HTTPLoadBalancer *self)
Definition: http-loadbalancer.c:352
HTTPLoadBalancerTargetState
Definition: http-loadbalancer.h:30
@ HTTP_TARGET_FAILED
Definition: http-loadbalancer.h:32
@ HTTP_TARGET_OPERATIONAL
Definition: http-loadbalancer.h:31
void http_load_balancer_set_recovery_timeout(HTTPLoadBalancer *self, gint recovery_timeout)
Definition: http-loadbalancer.c:412
gboolean http_lb_target_is_url_templated(HTTPLoadBalancerTarget *self)
Definition: http-loadbalancer.c:149
HTTPLoadBalancerTarget * http_load_balancer_choose_target(HTTPLoadBalancer *self, HTTPLoadBalancerClient *lbc)
Definition: http-loadbalancer.c:327
gboolean http_load_balancer_add_target(HTTPLoadBalancer *self, const gchar *url, GError **error)
Definition: http-loadbalancer.c:343
void http_lb_target_format_templated_url(HTTPLoadBalancerTarget *self, LogMessage *msg, const LogTemplateOptions *template_options, GString *result)
Definition: http-loadbalancer.c:168
void http_load_balancer_set_target_failed(HTTPLoadBalancer *self, HTTPLoadBalancerTarget *target)
Definition: http-loadbalancer.c:369
void http_load_balancer_free(HTTPLoadBalancer *self)
Definition: http-loadbalancer.c:428
HTTPLoadBalancer * http_load_balancer_new(void)
Definition: http-loadbalancer.c:418
void http_lb_client_init(HTTPLoadBalancerClient *, HTTPLoadBalancer *lb)
Definition: http-loadbalancer.c:186
void http_load_balancer_track_client(HTTPLoadBalancer *self, HTTPLoadBalancerClient *lbc)
Definition: http-loadbalancer.c:360
const gchar * http_lb_target_get_literal_url(HTTPLoadBalancerTarget *self)
Definition: http-loadbalancer.c:155
Definition: http-loadbalancer.h:65
HTTPLoadBalancerTarget * target
Definition: http-loadbalancer.h:66
Definition: http-loadbalancer.h:47
LogTemplate * url_template
Definition: http-loadbalancer.h:49
gint number_of_clients
Definition: http-loadbalancer.h:53
gint max_clients
Definition: http-loadbalancer.h:54
gchar formatted_index[16]
Definition: http-loadbalancer.h:56
time_t last_failure_time
Definition: http-loadbalancer.h:55
HTTPLoadBalancerTargetState state
Definition: http-loadbalancer.h:52
gint index
Definition: http-loadbalancer.h:50
Definition: http-loadbalancer.h:73
gint num_clients
Definition: http-loadbalancer.h:77
HTTPLoadBalancerTarget * targets
Definition: http-loadbalancer.h:75
gint recovery_timeout
Definition: http-loadbalancer.h:79
gint num_targets
Definition: http-loadbalancer.h:76
GMutex lock
Definition: http-loadbalancer.h:74
gint num_failed_targets
Definition: http-loadbalancer.h:78
time_t last_recovery_attempt
Definition: http-loadbalancer.h:80
GString * result
Definition: test_lexer_block.c:34
LogMessage * msg
Definition: test_rename.c:35
LogTemplateOptions template_options
Definition: test_value_pairs.c:65