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
cde2db78
Unverified
Commit
cde2db78
authored
Mar 17, 2021
by
Dominik Charousset
Committed by
GitHub
Mar 17, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1228
Add metric_registry::merge function
parents
3b0d4639
1c2a49a2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
1 deletion
+43
-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
+17
-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 @
cde2db78
...
...
@@ -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 @
cde2db78
...
...
@@ -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,22 @@ 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
::
defer_lock
};
std
::
unique_lock
<
std
::
mutex
>
guard2
{
other
.
families_mx_
,
std
::
defer_lock
};
std
::
lock
(
guard1
,
guard2
);
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 @
cde2db78
...
...
@@ -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