Skip to content

Commit

Permalink
Added event tag to watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
coryodaniel committed Apr 17, 2019
1 parent ea0ac48 commit 02b6413
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,20 @@ config :bonny,
}
```

When configuring bonny to run *in your cluster* the `mix bonny.gen.manifest` command will generate a service account for you. To use that service account configure the `k8s` library like the following:

```elixir
config :k8s,
clusters: %{
default: %{}
}
```

This will add a cluster named `default`. When no configuration information is provided, the `k8s` library will use the service account of the pod.

## Example Operators built with Bonny

- [Hello Operator](https://github.com/coryodaniel/hello_operator)
- [Hello Operator](https://github.com/coryodaniel/hello_operator) - this was built with bonny v 0.2, there have been significant changes since.

## Bonny Generators

Expand Down
2 changes: 1 addition & 1 deletion lib/bonny/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ defmodule Bonny.Telemetry.DebugLogger do

def handle_event(event, measurements, metadata, _config) do
Logger.debug(fn ->
event_name = Enum.join(event, ":")
event_name = Enum.join(event, "_")
"[#{event_name}] #{inspect(measurements)} #{inspect(metadata)}"
end)
end
Expand Down
11 changes: 6 additions & 5 deletions lib/bonny/watcher/impl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,15 @@ defmodule Bonny.Watcher.Impl do
defp do_dispatch(controller, event, object) do
Task.start(fn ->
{time, result} = Telemetry.measure(fn -> apply(controller, event, [object]) end)
metadata = %{event: event}
measurements = %{duration: time}

case result do
:ok ->
emit_telemetry_measurement(:dispatch_succeeded, measurements, controller)
emit_telemetry_measurement(:dispatch_succeeded, measurements, controller, metadata)

{:error, msg} ->
emit_telemetry_measurement(:dispatch_failed, measurements, controller)
emit_telemetry_measurement(:dispatch_failed, measurements, controller, metadata)
Logger.error("Error dispatching watch event: #{msg}")
end
end)
Expand All @@ -116,9 +117,9 @@ defmodule Bonny.Watcher.Impl do
@spec fetch_resource_version(Impl.t()) :: {:ok, binary} | {:error, binary}
defp fetch_resource_version(state = %Impl{}) do
operation = list_operation(state)
response = @client.run(operation, Config.cluster_name(), params: %{limit: 1})
result = @client.run(operation, Config.cluster_name(), params: %{limit: 1})

case response do
case result do
{:ok, response} ->
{:ok, extract_rv(response)}

Expand Down Expand Up @@ -160,7 +161,7 @@ defmodule Bonny.Watcher.Impl do
def extract_rv(%{"message" => message}), do: {:gone, message}

@spec emit_telemetry_measurement(atom, map, module, map | nil) :: :ok
defp emit_telemetry_measurement(name, measurement, controller, extra \\ %{}) do
defp emit_telemetry_measurement(name, measurement, controller, extra) do
metadata = CRD.telemetry_metadata(controller.crd_spec, extra)
Telemetry.emit([:watcher, name], measurement, metadata)
end
Expand Down

0 comments on commit 02b6413

Please sign in to comment.