From bfcfd3b73dc1793f8d8c83860698350bd55cc71b Mon Sep 17 00:00:00 2001 From: Rafael Antunes Date: Fri, 3 Nov 2023 16:21:51 +0100 Subject: [PATCH 1/3] Implements telemetry for the Operator --- lib/bonny/operator.ex | 35 ++++++++++++++++++++++++----------- lib/bonny/server/watcher.ex | 4 +++- lib/bonny/sys/telemetry.ex | 3 ++- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/lib/bonny/operator.ex b/lib/bonny/operator.ex index 1823a67..cc363eb 100644 --- a/lib/bonny/operator.ex +++ b/lib/bonny/operator.ex @@ -145,18 +145,31 @@ defmodule Bonny.Operator do @doc false @spec run({atom(), Bonny.Resource.t()}, {module(), keyword()}, module(), K8s.Conn.t()) :: :ok def run({action, resource}, controller, operator, conn) do - Axn.new!( - conn: conn, - action: action, - resource: resource, + metadata = %{ + operator: operator, controller: controller, - operator: operator - ) - |> operator.call([]) - |> Bonny.Axn.emit_events() - |> Bonny.Axn.run_after_processed() - - :ok + action: action, + name: K8s.Resource.name(resource), + namespace: K8s.Resource.namespace(resource), + kind: K8s.Resource.kind(resource), + api_version: resource["apiVersion"], + library: :bonny + } + + :telemetry.span([:operator, :run], metadata, fn -> + Axn.new!( + conn: conn, + action: action, + resource: resource, + controller: controller, + operator: operator + ) + |> operator.call([]) + |> Bonny.Axn.emit_events() + |> Bonny.Axn.run_after_processed() + + {:ok, %{metadata}} + end) end @doc false diff --git a/lib/bonny/server/watcher.ex b/lib/bonny/server/watcher.ex index 4f97b8d..aa702c5 100644 --- a/lib/bonny/server/watcher.ex +++ b/lib/bonny/server/watcher.ex @@ -44,10 +44,12 @@ defmodule Bonny.Server.Watcher do ) do metadata = %{ module: controller, + type: type, name: K8s.Resource.name(resource), namespace: K8s.Resource.namespace(resource), kind: K8s.Resource.kind(resource), - api_version: resource["apiVersion"] + api_version: resource["apiVersion"], + library: :bonny } :telemetry.span([:watcher, :watch], metadata, fn -> diff --git a/lib/bonny/sys/telemetry.ex b/lib/bonny/sys/telemetry.ex index e35cb0f..6b60bed 100644 --- a/lib/bonny/sys/telemetry.ex +++ b/lib/bonny/sys/telemetry.ex @@ -7,7 +7,8 @@ defmodule Bonny.Sys.Telemetry do [:reconciler, :reconcile], [:watcher, :watch], [:scheduler, :binding], - [:task, :execution] + [:task, :execution], + [:operator, :run] ] @events Enum.flat_map(@spans, fn span -> From c91c09b6a2debb66cb83d2230b9f29ac7a0a5b10 Mon Sep 17 00:00:00 2001 From: Rafael Antunes Date: Fri, 3 Nov 2023 22:37:01 +0100 Subject: [PATCH 2/3] Fixed typo after refactor --- lib/bonny/operator.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bonny/operator.ex b/lib/bonny/operator.ex index cc363eb..50ed743 100644 --- a/lib/bonny/operator.ex +++ b/lib/bonny/operator.ex @@ -168,7 +168,7 @@ defmodule Bonny.Operator do |> Bonny.Axn.emit_events() |> Bonny.Axn.run_after_processed() - {:ok, %{metadata}} + {:ok, metadata} end) end From cd045461dacee425b468d65d294829d8ca29373d Mon Sep 17 00:00:00 2001 From: Rafael Antunes Date: Fri, 3 Nov 2023 22:37:13 +0100 Subject: [PATCH 3/3] Add changelog entry --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64f6d6d..cefe0b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 +### Added + +- Added telemetry events to the Operator module - [#244](https://github.com/coryodaniel/bonny/pull/244) + ## [1.3.0] - 2023-09-25