Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
02bb479c
Commit
02bb479c
authored
Apr 30, 2022
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Spin up Prometheus from caf-net when available
parent
ab21592f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
75 additions
and
12 deletions
+75
-12
libcaf_io/src/io/middleman.cpp
libcaf_io/src/io/middleman.cpp
+11
-8
libcaf_net/caf/net/prometheus/serve.hpp
libcaf_net/caf/net/prometheus/serve.hpp
+1
-0
libcaf_net/caf/net/tcp_accept_socket.hpp
libcaf_net/caf/net/tcp_accept_socket.hpp
+14
-4
libcaf_net/src/net/middleman.cpp
libcaf_net/src/net/middleman.cpp
+41
-0
libcaf_net/src/net/tcp_accept_socket.cpp
libcaf_net/src/net/tcp_accept_socket.cpp
+8
-0
No files found.
libcaf_io/src/io/middleman.cpp
View file @
02bb479c
...
@@ -421,7 +421,9 @@ strong_actor_ptr middleman::remote_lookup(std::string name,
...
@@ -421,7 +421,9 @@ strong_actor_ptr middleman::remote_lookup(std::string name,
void
middleman
::
start
()
{
void
middleman
::
start
()
{
CAF_LOG_TRACE
(
""
);
CAF_LOG_TRACE
(
""
);
// Launch background tasks.
// Launch background tasks unless caf-net is also available. In that case, the
// net::middleman takes care of these.
if
(
!
system
().
has_network_manager
())
{
if
(
auto
prom
=
get_if
<
config_value
::
dictionary
>
(
if
(
auto
prom
=
get_if
<
config_value
::
dictionary
>
(
&
system
().
config
(),
"caf.middleman.prometheus-http"
))
{
&
system
().
config
(),
"caf.middleman.prometheus-http"
))
{
auto
ptr
=
std
::
make_unique
<
prometheus_scraping
>
(
system
());
auto
ptr
=
std
::
make_unique
<
prometheus_scraping
>
(
system
());
...
@@ -431,6 +433,7 @@ void middleman::start() {
...
@@ -431,6 +433,7 @@ void middleman::start() {
background_tasks_
.
emplace_back
(
std
::
move
(
ptr
));
background_tasks_
.
emplace_back
(
std
::
move
(
ptr
));
}
}
}
}
}
// Launch backend.
// Launch backend.
if
(
!
get_or
(
config
(),
"caf.middleman.manual-multiplexing"
,
false
))
if
(
!
get_or
(
config
(),
"caf.middleman.manual-multiplexing"
,
false
))
backend_supervisor_
=
backend
().
make_supervisor
();
backend_supervisor_
=
backend
().
make_supervisor
();
...
...
libcaf_net/caf/net/prometheus/serve.hpp
View file @
02bb479c
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
#include "caf/fwd.hpp"
#include "caf/fwd.hpp"
#include "caf/net/http/server.hpp"
#include "caf/net/http/server.hpp"
#include "caf/net/prometheus/server.hpp"
#include "caf/net/prometheus/server.hpp"
#include "caf/net/stream_transport.hpp"
namespace
caf
::
detail
{
namespace
caf
::
detail
{
...
...
libcaf_net/caf/net/tcp_accept_socket.hpp
View file @
02bb479c
...
@@ -24,8 +24,8 @@ struct CAF_NET_EXPORT tcp_accept_socket : network_socket {
...
@@ -24,8 +24,8 @@ struct CAF_NET_EXPORT tcp_accept_socket : network_socket {
/// Creates a new TCP socket to accept connections on a given port.
/// Creates a new TCP socket to accept connections on a given port.
/// @param node The endpoint to listen on and the filter for incoming addresses.
/// @param node The endpoint to listen on and the filter for incoming addresses.
///
Passing the address `0.0.0.0` will accept incoming connection from any host.
///
Passing the address `0.0.0.0` will accept incoming connection
/// Passing port 0 lets the OS choose the port.
///
from any host.
Passing port 0 lets the OS choose the port.
/// @relates tcp_accept_socket
/// @relates tcp_accept_socket
expected
<
tcp_accept_socket
>
expected
<
tcp_accept_socket
>
CAF_NET_EXPORT
make_tcp_accept_socket
(
ip_endpoint
node
,
CAF_NET_EXPORT
make_tcp_accept_socket
(
ip_endpoint
node
,
...
@@ -33,14 +33,24 @@ expected<tcp_accept_socket>
...
@@ -33,14 +33,24 @@ expected<tcp_accept_socket>
/// Creates a new TCP socket to accept connections on a given port.
/// Creates a new TCP socket to accept connections on a given port.
/// @param node The endpoint to listen on and the filter for incoming addresses.
/// @param node The endpoint to listen on and the filter for incoming addresses.
///
Passing the address `0.0.0.0` will accept incoming connection from any host.
///
Passing the address `0.0.0.0` will accept incoming connection
/// Passing port 0 lets the OS choose the port.
///
from any host.
Passing port 0 lets the OS choose the port.
/// @param reuse_addr Optionally sets the SO_REUSEADDR option on the socket.
/// @param reuse_addr Optionally sets the SO_REUSEADDR option on the socket.
/// @relates tcp_accept_socket
/// @relates tcp_accept_socket
expected
<
tcp_accept_socket
>
expected
<
tcp_accept_socket
>
CAF_NET_EXPORT
make_tcp_accept_socket
(
const
uri
::
authority_type
&
node
,
CAF_NET_EXPORT
make_tcp_accept_socket
(
const
uri
::
authority_type
&
node
,
bool
reuse_addr
=
false
);
bool
reuse_addr
=
false
);
/// Creates a new TCP socket to accept connections on a given port.
/// @param port The port for listening to incoming connection. Passing 0 lets
/// the OS choose a port.
/// @param addr The filter for incoming addresses. Passing the address `0.0.0.0`
/// will accept incoming connection from any host.
/// @param reuse_addr Optionally sets the SO_REUSEADDR option on the socket.
/// @relates tcp_accept_socket
expected
<
tcp_accept_socket
>
CAF_NET_EXPORT
make_tcp_accept_socket
(
uint16_t
port
,
std
::
string
addr
=
"0.0.0.0"
,
bool
reuse_addr
=
false
);
/// Accepts a connection on `x`.
/// Accepts a connection on `x`.
/// @param x Listening endpoint.
/// @param x Listening endpoint.
/// @returns The socket that handles the accepted connection on success, an
/// @returns The socket that handles the accepted connection on success, an
...
...
libcaf_net/src/net/middleman.cpp
View file @
02bb479c
...
@@ -7,6 +7,9 @@
...
@@ -7,6 +7,9 @@
#include "caf/actor_system_config.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/detail/set_thread_name.hpp"
#include "caf/detail/set_thread_name.hpp"
#include "caf/expected.hpp"
#include "caf/expected.hpp"
#include "caf/net/prometheus/serve.hpp"
#include "caf/net/tcp_accept_socket.hpp"
#include "caf/net/tcp_stream_socket.hpp"
#include "caf/raise_error.hpp"
#include "caf/raise_error.hpp"
#include "caf/sec.hpp"
#include "caf/sec.hpp"
#include "caf/send.hpp"
#include "caf/send.hpp"
...
@@ -14,6 +17,40 @@
...
@@ -14,6 +17,40 @@
namespace
caf
::
net
{
namespace
caf
::
net
{
namespace
{
struct
prom_config
{
uint16_t
port
;
std
::
string
address
=
"0.0.0.0"
;
bool
reuse_address
=
false
;
};
template
<
class
Inspector
>
bool
inspect
(
Inspector
&
f
,
prom_config
&
x
)
{
return
f
.
object
(
x
).
fields
(
f
.
field
(
"port"
,
x
.
port
),
f
.
field
(
"address"
,
x
.
address
).
fallback
(
"0.0.0.0"
),
f
.
field
(
"reuse-address"
,
x
.
reuse_address
).
fallback
(
false
));
}
void
launch_prom_server
(
actor_system
&
sys
,
const
prom_config
&
cfg
)
{
if
(
auto
fd
=
make_tcp_accept_socket
(
cfg
.
port
,
cfg
.
address
,
cfg
.
reuse_address
))
{
CAF_LOG_INFO
(
"start Prometheus server at port"
<<
local_port
(
*
fd
));
prometheus
::
serve
(
sys
,
std
::
move
(
*
fd
));
}
else
{
CAF_LOG_WARNING
(
"failed to start Prometheus server: "
<<
fd
.
error
());
}
}
void
launch_background_tasks
(
actor_system
&
sys
)
{
auto
&
cfg
=
sys
.
config
();
if
(
auto
pcfg
=
get_as
<
prom_config
>
(
cfg
,
"caf.middleman.prometheus-http"
))
{
launch_prom_server
(
sys
,
*
pcfg
);
}
}
}
// namespace
void
middleman
::
init_global_meta_objects
()
{
void
middleman
::
init_global_meta_objects
()
{
// nop
// nop
}
}
...
@@ -33,6 +70,7 @@ void middleman::start() {
...
@@ -33,6 +70,7 @@ void middleman::start() {
detail
::
set_thread_name
(
"caf.net.mpx"
);
detail
::
set_thread_name
(
"caf.net.mpx"
);
sys_
.
thread_started
();
sys_
.
thread_started
();
mpx_
.
set_thread_id
();
mpx_
.
set_thread_id
();
launch_background_tasks
(
sys_
);
mpx_
.
run
();
mpx_
.
run
();
sys_
.
thread_terminates
();
sys_
.
thread_terminates
();
}};
}};
...
@@ -89,6 +127,9 @@ void middleman::add_module_options(actor_system_config& cfg) {
...
@@ -89,6 +127,9 @@ void middleman::add_module_options(actor_system_config& cfg) {
"max. time between messages before declaring a node dead "
"max. time between messages before declaring a node dead "
"(disabled if 0, ignored if heartbeats are disabled)"
)
"(disabled if 0, ignored if heartbeats are disabled)"
)
.
add
<
std
::
string
>
(
"network-backend"
,
"legacy option"
);
.
add
<
std
::
string
>
(
"network-backend"
,
"legacy option"
);
config_option_adder
{
cfg
.
custom_options
(),
"caf.middleman.prometheus-http"
}
.
add
<
uint16_t
>
(
"port"
,
"listening port for incoming scrapes"
)
.
add
<
std
::
string
>
(
"address"
,
"bind address for the HTTP server socket"
);
}
}
}
// namespace caf::net
}
// namespace caf::net
libcaf_net/src/net/tcp_accept_socket.cpp
View file @
02bb479c
...
@@ -121,6 +121,14 @@ make_tcp_accept_socket(const uri::authority_type& node, bool reuse_addr) {
...
@@ -121,6 +121,14 @@ make_tcp_accept_socket(const uri::authority_type& node, bool reuse_addr) {
to_string
(
node
));
to_string
(
node
));
}
}
expected
<
tcp_accept_socket
>
make_tcp_accept_socket
(
uint16_t
port
,
std
::
string
addr
,
bool
reuse_addr
)
{
uri
::
authority_type
auth
;
auth
.
port
=
port
;
auth
.
host
=
std
::
move
(
addr
);
return
make_tcp_accept_socket
(
auth
,
reuse_addr
);
}
expected
<
tcp_stream_socket
>
accept
(
tcp_accept_socket
x
)
{
expected
<
tcp_stream_socket
>
accept
(
tcp_accept_socket
x
)
{
auto
sock
=
::
accept
(
x
.
id
,
nullptr
,
nullptr
);
auto
sock
=
::
accept
(
x
.
id
,
nullptr
,
nullptr
);
if
(
sock
==
net
::
invalid_socket_id
)
{
if
(
sock
==
net
::
invalid_socket_id
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment