Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit e7c5d31

Browse files
Add oc_sampler_period_or_count (#129)
1 parent c1ca3e9 commit e7c5d31

13 files changed

+704
-12
lines changed

doc/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ $ rebar3 protobuf compile
178178

179179

180180
<table width="100%" border="0" summary="list of modules">
181+
<tr><td><a href="oc_producer.md" class="module">oc_producer</a></td></tr>
182+
<tr><td><a href="oc_producer_registry.md" class="module">oc_producer_registry</a></td></tr>
181183
<tr><td><a href="oc_reporter.md" class="module">oc_reporter</a></td></tr>
182184
<tr><td><a href="oc_reporter_noop.md" class="module">oc_reporter_noop</a></td></tr>
183185
<tr><td><a href="oc_reporter_sequential.md" class="module">oc_reporter_sequential</a></td></tr>
@@ -187,7 +189,9 @@ $ rebar3 protobuf compile
187189
<tr><td><a href="oc_sampler_always.md" class="module">oc_sampler_always</a></td></tr>
188190
<tr><td><a href="oc_sampler_impl.md" class="module">oc_sampler_impl</a></td></tr>
189191
<tr><td><a href="oc_sampler_never.md" class="module">oc_sampler_never</a></td></tr>
192+
<tr><td><a href="oc_sampler_period_or_count.md" class="module">oc_sampler_period_or_count</a></td></tr>
190193
<tr><td><a href="oc_sampler_probability.md" class="module">oc_sampler_probability</a></td></tr>
194+
<tr><td><a href="oc_self_producer.md" class="module">oc_self_producer</a></td></tr>
191195
<tr><td><a href="oc_server.md" class="module">oc_server</a></td></tr>
192196
<tr><td><a href="oc_span.md" class="module">oc_span</a></td></tr>
193197
<tr><td><a href="oc_span_ctx_binary.md" class="module">oc_span_ctx_binary</a></td></tr>

doc/edoc-info

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
%% encoding: UTF-8
22
{application,opencensus}.
3-
{modules,[oc_reporter,oc_reporter_noop,oc_reporter_sequential,
4-
oc_reporter_stdout,oc_reporter_zipkin,oc_sampler,oc_sampler_always,
5-
oc_sampler_impl,oc_sampler_never,oc_sampler_probability,oc_server,
6-
oc_span,oc_span_ctx_binary,oc_span_ctx_header,oc_span_sweeper,
7-
oc_span_transform,oc_stat,oc_stat_aggregation,
3+
{modules,[oc_producer,oc_producer_registry,oc_reporter,oc_reporter_noop,
4+
oc_reporter_sequential,oc_reporter_stdout,oc_reporter_zipkin,
5+
oc_sampler,oc_sampler_always,oc_sampler_impl,oc_sampler_never,
6+
oc_sampler_period_or_count,oc_sampler_probability,oc_self_producer,
7+
oc_server,oc_span,oc_span_ctx_binary,oc_span_ctx_header,
8+
oc_span_sweeper,oc_span_transform,oc_stat,oc_stat_aggregation,
89
oc_stat_aggregation_count,oc_stat_aggregation_distribution,
910
oc_stat_aggregation_latest,oc_stat_aggregation_sum,oc_stat_config,
1011
oc_stat_exporter,oc_stat_exporter_stdout,oc_stat_measure,

doc/oc_producer.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
3+
# Module oc_producer #
4+
* [Description](#description)
5+
6+
Producer is a source of metrics.
7+
8+
__This module defines the `oc_producer` behaviour.__<br /> Required callback functions: `read/2`.
9+
10+
<a name="description"></a>
11+
12+
## Description ##
13+
14+
Callbacks:
15+
16+
- `read(Registry, Callback) -> ok` - called by exporters.
17+
Read should call `Callback` with the current values of all metrics
18+
supported by this metric provider.
19+
The metrics should be unique for each combination of name and resource.
20+
21+
- `cleanup(Registry) -> ok` - optional.
22+
Called when producer removed from `Registry`

doc/oc_producer_registry.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
3+
# Module oc_producer_registry #
4+
* [Description](#description)
5+
* [Function Index](#index)
6+
* [Function Details](#functions)
7+
8+
Registry maintains a set of metric producers for exporting.
9+
10+
<a name="description"></a>
11+
12+
## Description ##
13+
Most users will rely on the DefaultRegistry.<a name="index"></a>
14+
15+
## Function Index ##
16+
17+
18+
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#add_producer-1">add_producer/1</a></td><td></td></tr><tr><td valign="top"><a href="#add_producer-2">add_producer/2</a></td><td>
19+
Adds <code>Producer</code> to the <code>Registry</code>.</td></tr><tr><td valign="top"><a href="#read_all-1">read_all/1</a></td><td>Equivalent to <a href="#read_all-1"><tt>read_all(default)</tt></a>.</td></tr><tr><td valign="top"><a href="#read_all-2">read_all/2</a></td><td>
20+
Calls <code>Callback</code> for each metric produced by the metric producers in the <code>Registry</code>.</td></tr><tr><td valign="top"><a href="#read_to_list-0">read_to_list/0</a></td><td></td></tr><tr><td valign="top"><a href="#read_to_list-1">read_to_list/1</a></td><td></td></tr><tr><td valign="top"><a href="#remove_producer-1">remove_producer/1</a></td><td>Equivalent to <a href="#remove_producer-2"><tt>remove_producer(default, Producer)</tt></a>.</td></tr><tr><td valign="top"><a href="#remove_producer-2">remove_producer/2</a></td><td></td></tr></table>
21+
22+
23+
<a name="functions"></a>
24+
25+
## Function Details ##
26+
27+
<a name="add_producer-1"></a>
28+
29+
### add_producer/1 ###
30+
31+
`add_producer(Producer) -> any()`
32+
33+
<a name="add_producer-2"></a>
34+
35+
### add_producer/2 ###
36+
37+
`add_producer(Registry, Producer) -> any()`
38+
39+
Adds `Producer` to the `Registry`.
40+
41+
<a name="read_all-1"></a>
42+
43+
### read_all/1 ###
44+
45+
`read_all(Callback) -> any()`
46+
47+
Equivalent to [`read_all(default)`](#read_all-1).
48+
49+
<a name="read_all-2"></a>
50+
51+
### read_all/2 ###
52+
53+
`read_all(Registry, Callback) -> any()`
54+
55+
Calls `Callback` for each metric produced by the metric producers in the `Registry`.
56+
57+
<a name="read_to_list-0"></a>
58+
59+
### read_to_list/0 ###
60+
61+
`read_to_list() -> any()`
62+
63+
<a name="read_to_list-1"></a>
64+
65+
### read_to_list/1 ###
66+
67+
`read_to_list(Registry) -> any()`
68+
69+
<a name="remove_producer-1"></a>
70+
71+
### remove_producer/1 ###
72+
73+
`remove_producer(Producer) -> any()`
74+
75+
Equivalent to [`remove_producer(default, Producer)`](#remove_producer-2).
76+
77+
<a name="remove_producer-2"></a>
78+
79+
### remove_producer/2 ###
80+
81+
`remove_producer(Registry, Producer) -> any()`
82+

doc/oc_sampler_period_or_count.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
3+
# Module oc_sampler_period_or_count #
4+
* [Description](#description)
5+
* [Function Index](#index)
6+
* [Function Details](#functions)
7+
8+
This sampler makes sure you will have at least 1 sample during `period`
9+
or `1/count` samples otherwise.
10+
11+
__Behaviours:__ [`oc_sampler`](oc_sampler.md).
12+
13+
<a name="index"></a>
14+
15+
## Function Index ##
16+
17+
18+
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#init-1">init/1</a></td><td></td></tr><tr><td valign="top"><a href="#should_sample-4">should_sample/4</a></td><td></td></tr></table>
19+
20+
21+
<a name="functions"></a>
22+
23+
## Function Details ##
24+
25+
<a name="init-1"></a>
26+
27+
### init/1 ###
28+
29+
`init(Opts) -> any()`
30+
31+
<a name="should_sample-4"></a>
32+
33+
### should_sample/4 ###
34+
35+
`should_sample(TraceId, X2, X3, X4) -> any()`
36+

doc/oc_self_producer.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
3+
# Module oc_self_producer #
4+
* [Description](#description)
5+
* [Function Index](#index)
6+
* [Function Details](#functions)
7+
8+
Produces metrics for internal state like spans queue size, views count, etc.
9+
10+
<a name="index"></a>
11+
12+
## Function Index ##
13+
14+
15+
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#read-2">read/2</a></td><td></td></tr></table>
16+
17+
18+
<a name="functions"></a>
19+
20+
## Function Details ##
21+
22+
<a name="read-2"></a>
23+
24+
### read/2 ###
25+
26+
`read(Registry, Callback) -> any()`
27+

doc/oc_span_sweeper.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ __Behaviours:__ [`gen_statem`](gen_statem.md).
1111
## Function Index ##
1212

1313

14-
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#callback_mode-0">callback_mode/0</a></td><td></td></tr><tr><td valign="top"><a href="#code_change-4">code_change/4</a></td><td></td></tr><tr><td valign="top"><a href="#handle_event-4">handle_event/4</a></td><td></td></tr><tr><td valign="top"><a href="#init-1">init/1</a></td><td></td></tr><tr><td valign="top"><a href="#start_link-0">start_link/0</a></td><td></td></tr><tr><td valign="top"><a href="#terminate-3">terminate/3</a></td><td></td></tr></table>
14+
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#callback_mode-0">callback_mode/0</a></td><td></td></tr><tr><td valign="top"><a href="#code_change-4">code_change/4</a></td><td></td></tr><tr><td valign="top"><a href="#handle_event-4">handle_event/4</a></td><td></td></tr><tr><td valign="top"><a href="#init-1">init/1</a></td><td></td></tr><tr><td valign="top"><a href="#start_link-0">start_link/0</a></td><td></td></tr><tr><td valign="top"><a href="#storage_size-0">storage_size/0</a></td><td></td></tr><tr><td valign="top"><a href="#terminate-3">terminate/3</a></td><td></td></tr></table>
1515

1616

1717
<a name="functions"></a>
@@ -48,6 +48,12 @@ __Behaviours:__ [`gen_statem`](gen_statem.md).
4848

4949
`start_link() -> any()`
5050

51+
<a name="storage_size-0"></a>
52+
53+
### storage_size/0 ###
54+
55+
`storage_size() -> any()`
56+
5157
<a name="terminate-3"></a>
5258

5359
### terminate/3 ###

elvis.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
rules => [{elvis_style, god_modules, #{ignore => [egithub]}},
3030
{elvis_style, dont_repeat_yourself, #{min_complexity => 30}},
3131
{elvis_style, line_length, #{limit => 120}},
32+
{elvis_style, no_if_expression, disable},
3233
%% be a bit more lax on naming for tests
3334
{elvis_style, variable_naming_convention, #{regex => "^_{0,2}([A-Z][0-9a-zA-Z]*)$"}},
3435
{elvis_style, state_record_and_type, disable}],

rebar.config

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
{project_plugins, [covertool,
1212
{rebar3_gpb_plugin, "~> 2.6.1"},
1313
rebar3_lint]}.
14+
15+
{plugins, [rebar3_proper]}.
16+
1417
{gpb_opts, [
1518
{i, "priv/opencensus-proto/src/opencensus/proto/trace"},
1619
{module_name_suffix, "_pb"},
@@ -28,7 +31,8 @@
2831

2932
{profiles, [
3033
{test, [{erl_opts, [nowarn_export_all]},
31-
{deps, [{meck, "0.8.11"}]}]},
34+
{deps, [{meck, "0.8.11"},
35+
{proper, "1.3.0"}]}]},
3236
{docs, [{deps, [{edown, "0.8.1"}]},
3337
{edoc_opts,
3438
[{doclet, edown_doclet},

src/oc_producer.erl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
%% @doc
22
%% Producer is a source of metrics.
3+
%%
4+
%% Callbacks:
5+
%%
6+
%% - `read(Registry, Callback) -> ok' - called by exporters.
7+
%% Read should call `Callback' with the current values of all metrics
8+
%% supported by this metric provider.
9+
%% The metrics should be unique for each combination of name and resource.
10+
%%
11+
%% - `cleanup(Registry) -> ok' - optional.
12+
%% Called when producer removed from `Registry'
13+
%%
314
%% @end
415
-module(oc_producer).
516

617
-include("oc_metrics.hrl").
718

8-
%% @doc
9-
%% Read should call `Callback' with the current values of all metrics
10-
%% supported by this metric provider.
11-
%% The metrics should be unique for each combination of name and resource.
12-
%% @end
1319
-callback read(Registry, Callback) -> ok when
1420
Registry :: oc_producer_registry:registry(),
1521
Callback :: metric_callback().

0 commit comments

Comments
 (0)