Skip to content

Move keyspace translations to public functions in query files#1130

Merged
davidebriani merged 1 commit intoastarte-platform:release-1.2from
eddbbt:keyspace_translation_rationalize
Mar 11, 2025
Merged

Move keyspace translations to public functions in query files#1130
davidebriani merged 1 commit intoastarte-platform:release-1.2from
eddbbt:keyspace_translation_rationalize

Conversation

@eddbbt
Copy link
Copy Markdown
Contributor

@eddbbt eddbbt commented Mar 7, 2025

Fix astarte keyspace encoding, check and fix for functions that used to require a plain or encoded realm name in order to generally have:
def functions -> accepts plain realm name, encode into keyspace and then use that
defp -> accepts only keyspaces

There are actually one or two occurrences that require a rework to match the above case(s), but this would affect the entire application logic (maybe in another PR?)

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.78%. Comparing base (0e0452e) to head (db3982f).
Report is 8 commits behind head on release-1.2.

Additional details and impacted files
@@               Coverage Diff               @@
##           release-1.2    #1130      +/-   ##
===============================================
- Coverage        70.73%   68.78%   -1.96%     
===============================================
  Files              176      327     +151     
  Lines             5184     7505    +2321     
===============================================
+ Hits              3667     5162    +1495     
- Misses            1517     2343     +826     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@eddbbt eddbbt force-pushed the keyspace_translation_rationalize branch from 59b4dbe to 28dca1b Compare March 10, 2025 14:30
@eddbbt eddbbt marked this pull request as ready for review March 10, 2025 14:41
keyspace_name =
CQLUtils.realm_name_to_keyspace_name(realm_name, Config.astarte_instance_id!())

with {:valid, true} <- {:valid, Realm.valid_name?(realm_name)},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this makes me think: are we actually not checking for valid realm names anymore? Are we allowing the user to query on the system keyspace?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is actually a good point, let me fix this asap

astarte_keyspace = Realm.keyspace_name("astarte")

case Queries.check_astarte_health(astarte_keyspace, :quorum) do
# TODO shall we check for an encoded astarte realm or it's fine to use the generic "astarte one"?
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

astarte is fine, as we're checking for astarte's health. Astarte is healthy even if there are no installed realms, but it needs the astarte realm to function

@eddbbt eddbbt force-pushed the keyspace_translation_rationalize branch 2 times, most recently from 727eed5 to 79e5575 Compare March 10, 2025 15:55
@eddbbt eddbbt requested a review from noaccOS March 10, 2025 16:00
@eddbbt eddbbt force-pushed the keyspace_translation_rationalize branch 5 times, most recently from 2ec918d to 9cc4b92 Compare March 10, 2025 16:59
Comment on lines +33 to +38
def keyspace_name("astarte") do
CQLUtils.realm_name_to_keyspace_name("astarte", Config.astarte_instance_id!())
end

def keyspace_name(realm_name) do
CQLUtils.realm_name_to_keyspace_name(realm_name, Config.astarte_instance_id!())
keyspace = CQLUtils.realm_name_to_keyspace_name(realm_name, Config.astarte_instance_id!())

with {:valid, true} <- {:valid, Realm.valid_name?(keyspace)} do
keyspace
end
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a bit all over the place:

  • the spec says the return type is a string, but it now is String.t() | {:valid, false}. I suggest we either change this function to a {:ok, keyspace_name} | {:error, :invalid_realm_name} or crash instead.
  • "astarte" is not a valid realm name, and as such you declared its own body to make sure calls to it still succeed. We do not want users querying on the astarte keyspace, I suggest we make another ad-hoc function used only for the queries actually requiring the astarte keyspace, something like Realm.astarte_keyspace_name()

@eddbbt eddbbt force-pushed the keyspace_translation_rationalize branch 3 times, most recently from b072c43 to 8f685c2 Compare March 11, 2025 10:55
@eddbbt eddbbt requested a review from noaccOS March 11, 2025 10:58
@eddbbt eddbbt force-pushed the keyspace_translation_rationalize branch from 8f685c2 to d3ebd3d Compare March 11, 2025 10:59
Signed-off-by: Eddy Babetto <eddy.babetto@secomind.com>
@eddbbt eddbbt force-pushed the keyspace_translation_rationalize branch from d3ebd3d to db3982f Compare March 11, 2025 11:01
Copy link
Copy Markdown
Collaborator

@noaccOS noaccOS left a comment

Choose a reason for hiding this comment

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

Looks good!

@davidebriani davidebriani merged commit bca5dfa into astarte-platform:release-1.2 Mar 11, 2025
29 checks passed
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.

3 participants