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
f6ccb27c
Commit
f6ccb27c
authored
Mar 03, 2021
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add metric_registry::merge function
parent
2c696667
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
1 deletion
+42
-1
libcaf_core/caf/telemetry/metric_registry.hpp
libcaf_core/caf/telemetry/metric_registry.hpp
+6
-0
libcaf_core/src/telemetry/metric_registry.cpp
libcaf_core/src/telemetry/metric_registry.cpp
+16
-0
libcaf_core/test/telemetry/metric_registry.cpp
libcaf_core/test/telemetry/metric_registry.cpp
+20
-1
No files found.
libcaf_core/caf/telemetry/metric_registry.hpp
View file @
f6ccb27c
...
...
@@ -471,6 +471,12 @@ public:
visit_family
(
f
,
ptr
.
get
());
}
// -- modifiers --------------------------------------------------------------
/// Takes ownership of all metric families in `other`.
/// @pre `other` *must not* contain any duplicated metric family
void
merge
(
metric_registry
&
other
);
private:
/// @pre `families_mx_` is locked.
metric_family
*
fetch
(
const
string_view
&
prefix
,
const
string_view
&
name
);
...
...
libcaf_core/src/telemetry/metric_registry.cpp
View file @
f6ccb27c
...
...
@@ -6,6 +6,7 @@
#include "caf/actor_system_config.hpp"
#include "caf/config.hpp"
#include "caf/raise_error.hpp"
#include "caf/telemetry/dbl_gauge.hpp"
#include "caf/telemetry/int_gauge.hpp"
#include "caf/telemetry/metric_family_impl.hpp"
...
...
@@ -35,6 +36,21 @@ metric_registry::~metric_registry() {
// nop
}
void
metric_registry
::
merge
(
metric_registry
&
other
)
{
if
(
this
==
&
other
)
return
;
std
::
unique_lock
<
std
::
mutex
>
guard1
{
families_mx_
};
std
::
unique_lock
<
std
::
mutex
>
guard2
{
other
.
families_mx_
};
families_
.
reserve
(
families_
.
size
()
+
other
.
families_
.
size
());
for
(
auto
&
fptr
:
other
.
families_
)
if
(
fetch
(
fptr
->
prefix
(),
fptr
->
name
())
!=
nullptr
)
CAF_RAISE_ERROR
(
"failed to merge metrics: duplicated family found"
);
families_
.
insert
(
families_
.
end
(),
std
::
make_move_iterator
(
other
.
families_
.
begin
()),
std
::
make_move_iterator
(
other
.
families_
.
end
()));
other
.
families_
.
clear
();
}
metric_family
*
metric_registry
::
fetch
(
const
string_view
&
prefix
,
const
string_view
&
name
)
{
auto
eq
=
[
&
](
const
auto
&
ptr
)
{
...
...
libcaf_core/test/telemetry/metric_registry.cpp
View file @
f6ccb27c
...
...
@@ -6,7 +6,7 @@
#include "caf/telemetry/metric_registry.hpp"
#include "c
af/test/dsl
.hpp"
#include "c
ore-test
.hpp"
#include "caf/string_view.hpp"
#include "caf/telemetry/counter.hpp"
...
...
@@ -193,6 +193,25 @@ CAF_TEST(counter_instance is a shortcut for using the family manually) {
CAF_CHECK_EQUAL
(
count
,
count2
);
}
SCENARIO
(
"metric registries can merge families from other registries"
)
{
GIVEN
(
"a registry with some metrics"
)
{
metric_registry
tmp
;
auto
foo_bar
=
tmp
.
counter_singleton
(
"foo"
,
"bar"
,
"test metric"
);
auto
bar_foo
=
tmp
.
counter_singleton
(
"bar"
,
"foo"
,
"test metric"
);
WHEN
(
"merging the registry into another one"
)
{
registry
.
merge
(
tmp
);
THEN
(
"all metrics move into the new location"
)
{
CHECK_EQ
(
foo_bar
,
registry
.
counter_singleton
(
"foo"
,
"bar"
,
"test metric"
));
CHECK_EQ
(
bar_foo
,
registry
.
counter_singleton
(
"bar"
,
"foo"
,
"test metric"
));
tmp
.
collect
(
collector
);
CHECK
(
collector
.
result
.
empty
());
}
}
}
}
CAF_TEST_FIXTURE_SCOPE_END
()
#define CHECK_CONTAINS(str) \
...
...
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