Skip to content

Commit

Permalink
WIP injecting component names
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonkopliku committed Sep 9, 2024
1 parent 5efe4a1 commit 8de8d36
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/trento/activity_logging/parser/activity_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Trento.ActivityLog.Parser.ActivityParser do
"""

alias Trento.ActivityLog.ActivityCatalog
alias Trento.ActivityLog.Logger.Parser.{EventParser, PhoenixConnParser}
alias Trento.ActivityLog.Logger.Parser.{EventParser, MetadataEnricher, PhoenixConnParser}

@type activity_log :: %{
type: String.t(),
Expand All @@ -17,12 +17,15 @@ defmodule Trento.ActivityLog.Parser.ActivityParser do
def to_activity_log(activity, activity_context) do
with true <- activity in ActivityCatalog.supported_activities(),
{:ok, actor} <- get_activity_info(:actor, activity, activity_context),
{:ok, metadata} <- get_activity_info(:metadata, activity, activity_context) do
{:ok, metadata} <-
get_activity_info(:metadata, activity, activity_context)
|> IO.inspect(label: "metadata"),

Check warning on line 22 in lib/trento/activity_logging/parser/activity_parser.ex

View workflow job for this annotation

GitHub Actions / Static Code Analysis

There should be no calls to `IO.inspect/1`.
{:ok, enriched_metadata} <- MetadataEnricher.enrich(metadata, activity, activity_context) do
{:ok,
%{
type: Atom.to_string(activity),
actor: actor,
metadata: metadata
metadata: enriched_metadata
}}
else
_ -> {:error, :cannot_parse_activity}
Expand Down
67 changes: 67 additions & 0 deletions lib/trento/activity_logging/parser/metadata_enricher.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
defmodule Trento.ActivityLog.Logger.Parser.MetadataEnricher do
@moduledoc """
Metadata enricher enriches metadata extracted by activity parser.
"""
alias Trento.Databases
alias Trento.Clusters.Projections.ClusterReadModel
alias Trento.Clusters
alias Trento.Hosts.Projections.HostReadModel
alias Trento.Hosts

def enrich(
%{
resource_id: resource_id,
resource_type: resource_type
} = metadata,
activity,
activity_context

Check warning on line 17 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / Test

variable "activity_context" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 17 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V1)

variable "activity_context" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 17 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V2)

variable "activity_context" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 17 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

variable "activity_context" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 17 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

variable "activity_context" is unused (if the variable is not meant to be used, prefix it with an underscore)
)
when activity in [:resource_tagging, :resource_untagging] do
IO.inspect(activity, label: "activity")

Check warning on line 20 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / Static Code Analysis

There should be no calls to `IO.inspect/1`.

resource_name =
case resource_type do
:host -> get_hostname(resource_id)
:cluster -> get_cluster_name(resource_id)
_ -> nil
end

IO.inspect(resource_name, label: "resource_name")

Check warning on line 29 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / Static Code Analysis

There should be no calls to `IO.inspect/1`.

{:ok,
case resource_name do
nil -> metadata
_ -> Map.put(metadata, :resource_name, resource_name)
end}
end

def enrich(metadata, activity, activity_context) do

Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / Test

variable "activity" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / Test

variable "activity_context" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V1)

variable "activity" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V1)

variable "activity_context" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V2)

variable "activity" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V2)

variable "activity_context" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

variable "activity" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

variable "activity_context" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

variable "activity" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 38 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

variable "activity_context" is unused (if the variable is not meant to be used, prefix it with an underscore)
metadata
end

defp get_hostname(id) do
case Hosts.by_host_id(id) do
{:ok, %HostReadModel{hostname: hostname}} -> hostname
{:error, :not_found} -> nil
end
end

defp get_cluster_name(id) do
case Clusters.by_cluster_id(id) do
{:ok, %ClusterReadModel{name: cluster_name}} -> cluster_name
{:error, :not_found} -> nil
end
end

defp get_database_sid(id) do

Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / Test

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / Test

function get_database_sid/1 is unused

Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V1)

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V1)

function get_database_sid/1 is unused

Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V2)

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V2)

function get_database_sid/1 is unused

Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

function get_database_sid/1 is unused

Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 56 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

function get_database_sid/1 is unused
end

defp get_sap_system_sid(id) do

Check warning on line 59 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / Test

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 59 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V1)

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 59 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V2)

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 59 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 59 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)
end

defp get_application_instance_number(id) do

Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / Test

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / Test

function get_application_instance_number/1 is unused

Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V1)

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V1)

function get_application_instance_number/1 is unused

Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V2)

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V2)

function get_application_instance_number/1 is unused

Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

function get_application_instance_number/1 is unused

Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 62 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

function get_application_instance_number/1 is unused
end

defp get_database_instance_number(id) do

Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / Test

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / Test

function get_database_instance_number/1 is unused

Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V1)

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V1)

function get_database_instance_number/1 is unused

Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V2)

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / API bc check (V2)

function get_database_instance_number/1 is unused

Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

function get_database_instance_number/1 is unused

Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

variable "id" is unused (if the variable is not meant to be used, prefix it with an underscore)

Check warning on line 65 in lib/trento/activity_logging/parser/metadata_enricher.ex

View workflow job for this annotation

GitHub Actions / End to end tests

function get_database_instance_number/1 is unused
end
end
9 changes: 9 additions & 0 deletions lib/trento/clusters.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ defmodule Trento.Clusters do

alias Trento.Repo

def by_cluster_id(cluster_id) do
case ClusterReadModel
|> where([c], c.id == ^cluster_id and is_nil(c.deregistered_at))
|> Repo.one() do
nil -> {:error, :not_found}
cluster -> {:ok, cluster}
end
end

@spec select_checks(String.t(), [String.t()]) :: :ok | {:error, any}
def select_checks(cluster_id, checks) do
Logger.debug("Selecting checks, cluster: #{cluster_id}")
Expand Down
9 changes: 9 additions & 0 deletions lib/trento/databases.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ defmodule Trento.Databases do

alias Trento.Repo

def by_database_id(id) do
case DatabaseReadModel
|> where([d], d.id == ^id and is_nil(d.deregistered_at))
|> Repo.one() do
nil -> {:error, :not_found}
database -> {:ok, database}
end
end

@spec get_all_databases :: [DatabaseReadModel.t()]
def get_all_databases do
DatabaseReadModel
Expand Down

0 comments on commit 8de8d36

Please sign in to comment.