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
fc66c8ac
Commit
fc66c8ac
authored
Jun 15, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix resolution of Prometheus timestamps
parent
8c82c734
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
6 deletions
+31
-6
libcaf_core/src/telemetry/collector/prometheus.cpp
libcaf_core/src/telemetry/collector/prometheus.cpp
+27
-2
libcaf_core/test/telemetry/collector/prometheus.cpp
libcaf_core/test/telemetry/collector/prometheus.cpp
+4
-4
No files found.
libcaf_core/src/telemetry/collector/prometheus.cpp
View file @
fc66c8ac
...
...
@@ -34,6 +34,20 @@ namespace caf::telemetry::collector {
namespace
{
/// Milliseconds since epoch.
struct
ms_timestamp
{
int64_t
value
;
/// Converts seconds-since-epoch to milliseconds-since-epoch
explicit
ms_timestamp
(
time_t
from
)
:
value
(
from
*
int64_t
{
1000
})
{
// nop
}
ms_timestamp
(
const
ms_timestamp
&
)
=
default
;
ms_timestamp
&
operator
=
(
const
ms_timestamp
&
)
=
default
;
};
void
append
(
prometheus
::
char_buffer
&
)
{
// End of recursion.
}
...
...
@@ -57,6 +71,9 @@ void append(prometheus::char_buffer&, const metric_family*, Ts&&...);
template
<
class
...
Ts
>
void
append
(
prometheus
::
char_buffer
&
,
const
metric
*
,
Ts
&&
...);
template
<
class
...
Ts
>
void
append
(
prometheus
::
char_buffer
&
,
ms_timestamp
,
Ts
&&
...);
template
<
class
...
Ts
>
void
append
(
prometheus
::
char_buffer
&
buf
,
string_view
str
,
Ts
&&
...
xs
)
{
buf
.
insert
(
buf
.
end
(),
str
.
begin
(),
str
.
end
());
...
...
@@ -116,6 +133,12 @@ void append(prometheus::char_buffer& buf, const metric* instance, Ts&&... xs) {
append
(
buf
,
std
::
forward
<
Ts
>
(
xs
)...);
}
template
<
class
...
Ts
>
void
append
(
prometheus
::
char_buffer
&
buf
,
ms_timestamp
ts
,
Ts
&&
...
xs
)
{
append
(
buf
,
ts
.
value
);
append
(
buf
,
std
::
forward
<
Ts
>
(
xs
)...);
}
}
// namespace
string_view
prometheus
::
collect_from
(
const
metric_registry
&
registry
,
...
...
@@ -136,13 +159,15 @@ string_view prometheus::collect_from(const metric_registry& registry) {
void
prometheus
::
operator
()(
const
metric_family
*
family
,
const
metric
*
instance
,
const
dbl_gauge
*
gauge
)
{
set_current_family
(
family
,
"gauge"
);
append
(
buf_
,
family
,
instance
,
' '
,
gauge
->
value
(),
' '
,
now_
,
'\n'
);
append
(
buf_
,
family
,
instance
,
' '
,
gauge
->
value
(),
' '
,
ms_timestamp
{
now_
},
'\n'
);
}
void
prometheus
::
operator
()(
const
metric_family
*
family
,
const
metric
*
instance
,
const
int_gauge
*
gauge
)
{
set_current_family
(
family
,
"gauge"
);
append
(
buf_
,
family
,
instance
,
' '
,
gauge
->
value
(),
' '
,
now_
,
'\n'
);
append
(
buf_
,
family
,
instance
,
' '
,
gauge
->
value
(),
' '
,
ms_timestamp
{
now_
},
'\n'
);
}
void
prometheus
::
set_current_family
(
const
metric_family
*
family
,
...
...
libcaf_core/test/telemetry/collector/prometheus.cpp
View file @
fc66c8ac
...
...
@@ -55,13 +55,13 @@ CAF_TEST(the Prometheus collector generates text output) {
CAF_CHECK_EQUAL
(
exporter
.
collect_from
(
registry
,
42
),
R"(# HELP foo_bar_seconds Some value without labels.
# TYPE foo_bar_seconds gauge
foo_bar_seconds 123 42
foo_bar_seconds 123 42
000
# HELP some_value_total Some (total) value with two labels.
# TYPE some_value_total gauge
some_value_total{a="1",b="2"} 12 42
some_value_total{a="2",b="1"} 21 42
some_value_total{a="1",b="2"} 12 42
000
some_value_total{a="2",b="1"} 21 42
000
# TYPE other_value_seconds_total gauge
other_value_seconds_total{x="true"} 31337 42
other_value_seconds_total{x="true"} 31337 42
000
)"
_sv
);
CAF_MESSAGE
(
"multiple runs generate the same output"
);
std
::
string
res1
;
...
...
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