Skip to content
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

Live pa connectivity status logs #865

Merged
merged 5 commits into from
Jan 7, 2025
Merged

Live pa connectivity status logs #865

merged 5 commits into from
Jan 7, 2025

Conversation

PaulJKim
Copy link
Collaborator

@PaulJKim PaulJKim commented Jan 6, 2025

Summary of changes

Asana Ticket: Process ARINC JSON for LivePA connectivity into Splunk

Adds handling for Live PA Connectivity statuses. Also took the opportunity to refactor and simplify some things to improve readability and extensibility.

Note: some field names were changed to make things a little more standardized. This will affect a couple Splunk alerts and so we should give Kevin a heads up before this is deployed.

Reviewer Checklist

  • Meets ticket's acceptance criteria
  • Any new or changed functions have typespecs
  • Tests were added for any new functionality (don't just rely on Codecov)
  • If signs.json was changed, there is a follow-up PR to signs_ui to update its dependency on this project
  • This branch was deployed to the staging environment and is currently running with no unexpected increase in warnings, and no errors or crashes (compare on Splunk: staging vs. prod)

Sorry, something went wrong.

- Refactor logging to be cleaner and more easily extendable
- Make sure unit tests actually run on mix test
@PaulJKim PaulJKim requested a review from a team as a code owner January 6, 2025 14:36
@digitalcora
Copy link
Contributor

digitalcora commented Jan 6, 2025

Some thoughts on the refactor:

➕ I think the change to having the device-specific functions return keyworded fields, instead of doing the logging and string formatting within each one, is a nice improvement.

➖ I'm less convinced about the change to how these functions are called. Previously the conditional on "device type" was handled as part of the pattern-matching for each function head, which puts the entire "format" of the input message in one place. With this change, we match on just the "device type" part of the message and use that value to dispatch to a device-specific function — which is essentially the same thing, but with an extra layer of indirection.

Reading between the lines a bit, it seems like you might have made this change to account for unknown device types, which are handled in a unique way. What if instead we kept the shared function approach to translate a message into fields (using pattern-matching as the conditional, as before), but had this return either {:ok, fields} or :error? Then we could have a fallback clause that returns :error, and the main function could react to that by logging the warning.

Open to others' thoughts, in case I'm the only one who saw it this way.

Copy link
Collaborator

@panentheos panentheos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Cora's thoughts above, and see comment below.

Enum.reduce(fields, base, fn {k, v}, acc ->
acc ++ [" #{Atom.to_string(k)}=", v]
end)
|> Logger.info()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach is good, but the code could be tuned up a bit:

  • Logging via lists doesn't behave well if e.g. a number slips through, so it would be safer to send everything through interpolation.
  • date_time could be prepended as a tuple to the field list, instead of being formatted separately.
  • reduce could be replaced with a slightly more expressive map and join
  • Atom.to_string is unnecessary if it's being interpolated

Copy link
Collaborator

@panentheos panentheos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice, thanks!

@PaulJKim PaulJKim merged commit ec6dae3 into main Jan 7, 2025
2 checks passed
@PaulJKim PaulJKim deleted the pk/live-pa-connectivity branch January 7, 2025 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants