-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Persistent Activity Logger #2730
Conversation
f0105fb
to
ed215f1
Compare
16c8a8a
to
d2420f0
Compare
@login_attempt {TrentoWeb.SessionController, :create} | ||
@api_key_generation {TrentoWeb.V1.SettingsController, :update_api_key_settings} | ||
@saving_suma_settings {TrentoWeb.V1.SUMACredentialsController, :create} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe for later: Use the OpenAPI spec as a single source of truth for this purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting idea. Let's indeed keep that on top of our minds as dealing with openapispex schemas would be a beast on its own 😄
@@ -0,0 +1,127 @@ | |||
defmodule Trento.ActivityLogging.Logger.PhoenixConnParser do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this potentially be a Protocol?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not think about that, yet. I cannot firmly say yes or no at the moment.
I guess when we introduce the Commanded related activity logging we might discover what it needs to be.
5f2113b
to
4fa886d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine, for the most part. Up to you how/when you want to address the comments.
defmodule Trento.ActivityLog.ActivityCatalog do | ||
@moduledoc """ | ||
Activity logging catalog | ||
""" | ||
|
||
@type logged_activity :: {controller :: module(), activity :: atom()} | ||
|
||
@login_attempt {TrentoWeb.SessionController, :create} | ||
@api_key_generation {TrentoWeb.V1.SettingsController, :update_api_key_settings} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces a boundary issue with the Trento
name space now depending on TrentoWeb
(usually it is the other way around). One way to resolve this would be to create a top-level namespace ActivityLog
for all related modules, especially the ones with cross-cutting module dependencies. WDYT ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boundary issue with the
Trento
name space now depending onTrentoWeb
I hear you, I see what you mean and I tend to agree.
Consider we already break that dependency direction in projectors, enriching commanded middleware and in an amqp message processor (mainly views and TrentoWeb.Endpoint
in order to broadcast things via websocket) 🙈
Now, I am not saying that since we broke some rule we should ruthlessly keep doing so 😄
What I mean is that we accepted the trade-off of having access to TrentoWeb
components within Trento
in certain edgy areas (like projectors and what mentioned earlier).
All the references to TrentoWeb
controllers are kept inside the centralized Trento.ActivityLog.ActivityCatalog
(meant to be like that) and I would keep accepting this trade-off also for this feature, unless until it matures more.
I will track an item with the concern you're raising.
Solution wide, I guess you mean having a top level ./lib/activity_log
(or similar) next to ./lib/trento
and ./lib/trento_web
. It might make sense indeed, as it would be a cross-cutting concern, as you mentioned.
Gonna track this in the backlog as well.
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we just move the ActivityCatalog to the web app? It may make sense as it refers to controller operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 we'd be needing to access TrentoWeb.{WhateverNamespace}.ActivityCatalog
from within Trento
and we'd be back in the same situation.
Besides, the activity catalog does belong to activity logging better than web, imho, because it would possibly reference also non-web related activity.
defmodule Trento.ActivityLog.Parser.ActivityParser do | ||
@moduledoc """ | ||
Behavior for activity parsers. | ||
It extracts the activity relevant information from the context. | ||
""" | ||
|
||
alias Trento.ActivityLog.ActivityCatalog | ||
|
||
@callback detect_activity(activity_context :: any()) :: ActivityCatalog.logged_activity() | nil | ||
|
||
@callback get_activity_actor( | ||
activity :: ActivityCatalog.logged_activity(), | ||
activity_context :: any() | ||
) :: any() | ||
|
||
@callback get_activity_metadata( | ||
activity :: ActivityCatalog.logged_activity(), | ||
activity_context :: any() | ||
) :: map() | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defprotocol Trento.ActivityLog.ParseToActivity do
alias Trento.ActivityLog.ActivityCatalog
def detect_activity(activity_context :: any()) :: ActivityCatalog.logged_activity() | nil
def get_activity_actor(
activity :: ActivityCatalog.logged_activity(),
activity_context :: any()
) :: any()
def get_activity_metadata(
activity :: ActivityCatalog.logged_activity(),
activity_context :: any()
) :: map()
end
For reference/ consideration. I think this should work.
@@ -0,0 +1,140 @@ | |||
defmodule Trento.ActivityLog.Logger.Parser.PhoenixConnParser do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example:
defimpl Trento.ActivityLog.ParseToActivity, for: %Plug.Conn{} do
...
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tips on the protocols, might come good as we proceed further
lib/trento/infrastructure/activity_log/logger/adapter/database_writer.ex
Outdated
Show resolved
Hide resolved
4fa886d
to
5f654fe
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. LGTM.
…om an activity context
…ity logs to a destination
95cb859
to
fb1db88
Compare
@gagandeepb FYI since we currently do not need different kind of destinations where to write logs, a few abstractions have been removed and the overall implementation slightly simplified. We can add them later if and when needed. |
Description
This PR introduces the ability to track interesting activities in the system.
Initial focus in on tracking http related activities.
Notes:
PhoenixConnParserTest
but tested inActivityLogger
which covers the broader integration of the different componentsActivityLogger
. More test about the other interesting activities to follow.EDIT: Since we currently do not need different kind of destinations where to write logs, a few abstractions have been removed.
How was this tested?
automated tests.