Skip to content

Commit

Permalink
Add timestamps to telemetry throttle events
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Dec 2, 2023
1 parent a0d9d42 commit ed2ce3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
14 changes: 6 additions & 8 deletions guides/telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,42 +31,40 @@ metadata: #{monotonic_time => integer(), scenario => module(), type => add | rem
### Init

Raised when a throttle mechanism is initialised.

```erlang
event_name: [amoc, throttle, init]
measurements: #{count => 1}
metadata: #{name => atom()}
metadata: #{monotonic_time => integer(), name => atom()}
```

### Rate

Raised when a throttle mechanism is initialised or its configured rate is changed.
This event is raised only on the master node.

```erlang
event_name: [amoc, throttle, rate]
measurements: #{rate => non_neg_integer()}
metadata: #{name => atom()}
metadata: #{monotonic_time => integer(), name => atom()}
```

### Request

Raised when a process client requests to be allowed pass through a throttled mechanism.

This event is raised only on the master node.
```erlang
event_name: [amoc, throttle, request]
measurements: #{count => 1}
metadata: #{name => atom()}
metadata: #{monotonic_time => integer(), name => atom()}
```

### Execute

Raised when a process client is allowed to execute after a throttled mechanism.

This event is raised only on the master node.
```erlang
event_name: [amoc, throttle, execute]
measurements: #{count => 1}
metadata: #{name => atom()}
metadata: #{monotonic_time => integer(), name => atom()}
```

## Coordinator
Expand Down
12 changes: 8 additions & 4 deletions src/amoc_throttle/amoc_throttle_controller.erl
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,14 @@ maybe_raise_event(Name, Event) ->
end.

raise_event(Name, Event) when Event =:= request; Event =:= execute; Event =:= init ->
telemetry:execute([amoc, throttle, Event], #{count => 1}, #{name => Name}).
telemetry:execute([amoc, throttle, Event],
#{count => 1},
#{monotonic_time => erlang:monotonic_time(), name => Name}).

report_rate(Name, RatePerMinute) ->
telemetry:execute([amoc, throttle, rate],
#{rate => RatePerMinute},
#{monotonic_time => erlang:monotonic_time(), name => Name}).

-spec change_rate_and_stop_plan(name(), state()) -> state().
change_rate_and_stop_plan(Name, State) ->
Expand Down Expand Up @@ -325,6 +332,3 @@ run_cmd(Pid, pause) ->
amoc_throttle_process:pause(Pid);
run_cmd(Pid, resume) ->
amoc_throttle_process:resume(Pid).

report_rate(Name, RatePerMinute) ->
telemetry:execute([amoc, throttle, rate], #{rate => RatePerMinute}, #{name => Name}).

0 comments on commit ed2ce3c

Please sign in to comment.