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

FMWK-278 Refactor configuration #684

Merged
merged 19 commits into from
Jan 8, 2024
Merged

Conversation

agrgr
Copy link

@agrgr agrgr commented Jan 1, 2024

No description provided.

@agrgr agrgr requested review from roimenashe and reugn January 1, 2024 18:48
@agrgr agrgr marked this pull request as ready for review January 2, 2024 13:16
return null;
}

public static String getNamespace(String prioritizedNamespace, String fallbackNamespace) {
Copy link
Member

Choose a reason for hiding this comment

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

This is because a namespace can be configured with both application.properties and @OverRide? but when a user wants to override nameSpace() he override nameSpace() (with only 1 param) right? its completely internal

Copy link
Author

@agrgr agrgr Jan 3, 2024

Choose a reason for hiding this comment

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

Yes, and it is the same mechanism we had before this change, so those who don't use application.properties (let's say, they use default settings) will not feel any change.
On the other hand, if they opt to use application.properties, it will have precedence over overridden namespace and/or hosts.

return new AerospikeTemplate(aerospikeClient, nameSpace(), mappingAerospikeConverter,
aerospikeMappingContext, aerospikeExceptionTranslator, queryEngine, indexRefresher, serverVersionSupport);
ServerVersionSupport serverVersionSupport, AerospikeSettings settings) {
return new AerospikeTemplate(aerospikeClient, getNamespace(settings.getNamespace(), nameSpace()),
Copy link
Member

Choose a reason for hiding this comment

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

The only aerospikeSettings we need in template is currently namespace but it makes sense to pass the entire aerospikeSettings to the template for more modular code flow (in case we want to use an aerospike setting in the template), WDYT?

Copy link
Author

Choose a reason for hiding this comment

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

Overall agree, but it might be more suitable to do in a separate ticket.

@@ -0,0 +1,10 @@
spring-data-aerospike.hosts=localhost:3000
spring-data-aerospike.namespace=TEST
Copy link
Member

Choose a reason for hiding this comment

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

I would use lowercase test as a default namespace

Copy link
Author

Choose a reason for hiding this comment

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

Agree, will use lowercase here (if there is any difference). However, the embedded testcontainer has its namespace configured as "TEST".

Copy link
Member

@roimenashe roimenashe Jan 3, 2024

Choose a reason for hiding this comment

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

I know, but in most aerospike documentation we use lowercase so I figure thats the go-to naming convention we should align with, will probably be more clean and less confusion for the users.

I've also made this change in the Spring Data Aerospike README and in the testers project but it got lost in the testers project since we worked on the same branch and probably overriding the change. I want to align it in the next release of starters as well (so everything will be aligned Aerospike official docs, Spring Data Aerospike, Spring Data Aerospike Starters).

@@ -13,7 +13,7 @@ public abstract class BaseIntegrationTests {
public static final String OVERRIDE_SET_NAME = "testSet1";
protected static final int MILLIS_TO_NANO = 1_000_000;

@Value("${embedded.aerospike.namespace}")
@Value("${spring-data-aerospike.namespace}")
Copy link
Member

Choose a reason for hiding this comment

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

In tests I'm not sure we want to change embedded name since we are using Playtika's embedded-aerospike

Copy link
Author

Choose a reason for hiding this comment

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

This is done for unification in the tests, we now read the same parameter from test application.properties rather than have scattered readings of embedded namespace and hosts.
Embedded Aerospike namespace and hosts are now specified only in one place - the application.properties file.

Copy link
Member

Choose a reason for hiding this comment

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

I just read embedded-aerospike documentation, it's actually produces embedded.aerospike.namespace so you can use spring-data-aerospike.namespace and its basically the same thing

@@ -42,7 +42,7 @@
@EnableAutoConfiguration
public class CommonTestConfig {

@Value("${embedded.aerospike.namespace}")
Copy link
Member

Choose a reason for hiding this comment

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

Same here, why remove embedded if it refers to embedded-aerospike namespace config?

Copy link
Author

Choose a reason for hiding this comment

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

We now have it in application.properties.

@@ -2271,7 +2267,7 @@ void findPersonsByFriendFriendAddressZipCode() {
}

@Test
// find by deeply nested String POJO field
// find by deeply nested String POJO field
Copy link
Member

Choose a reason for hiding this comment

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

Redundant tabs/spaces

Copy link
Author

Choose a reason for hiding this comment

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

Changing, was autoformatted this way.

@@ -2310,7 +2306,7 @@ void findPersonsByFriendFriendFriendFriendFriendFriendFriendFriendBestFriendFrie
}

@Test
// find by deeply nested Integer POJO field
// find by deeply nested Integer POJO field
Copy link
Member

Choose a reason for hiding this comment

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

Redundant tabs/spaces

@@ -2349,7 +2345,7 @@ void findPersonsByFriendFriendFriendFriendFriendFriendFriendFriendBestFriendAddr
}

@Test
// find by deeply nested POJO
// find by deeply nested POJO
Copy link
Member

Choose a reason for hiding this comment

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

Redundant tabs/spaces


@Setter
@Getter
public class AerospikeSettings {
Copy link
Member

Choose a reason for hiding this comment

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

If we have no default values here and we put them in application.properties, the user will have to define values for each of these in his application.properties.

I think this class must have values for each field except hosts and namespaces and only in the application.properties of the /tests we will have test namespace and localhost:3000

Copy link
Author

Choose a reason for hiding this comment

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

Agreed, bringing the defaults back.

@roimenashe
Copy link
Member

Changing aerospikeDataSettings method to aerospikeSettings bean introduces a breaking change that is very likely to impact users, need to see how to make it as smooth as possible (rethinking, 2 config options [with @deprecated?], documentation,...)

@agrgr
Copy link
Author

agrgr commented Jan 3, 2024

Changing aerospikeDataSettings method to aerospikeSettings bean introduces a breaking change that is very likely to impact users, need to see how to make it as smooth as possible (rethinking, 2 config options [with @deprecated?], documentation,...)

I think there is sense to address it via a blog post and/or an article on developer hub, along with having comments in the code. Users who don't use settings other than hosts and namespace will not feel the change because we still support overriding these values. Others will need to do some changes anyway (remove configureDataSettings() and use application.properties), which is (hopefully) straightforward.

public static Collection<Host> parseHosts(String hostsString) {
if (StringUtils.hasText(hostsString)) return Arrays.stream(hostsString.split(","))
.map(host -> host.split(":"))
.map(hostArr -> new Host(hostArr[0], Integer.parseInt(hostArr[1])))
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't support TLS.

Host can be constructed of:

  1. Host name/IP address
  2. tls name (optional)
  3. port

Previously we override getHosts() and created an Host object via code which could then be created with TLS.

I think that application.properties parsing automatically supports List instead of String which makes it easier to parse. and we should parse each String (Host) with the following logic:

  1. If it contains a single : it means no tls configured.
  2. If it contains two :'s it means TLS is configured so create an Host object with TLS.

Copy link
Author

Choose a reason for hiding this comment

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

Added using Java client's method for hosts parsing which includes reading optional TLS name.

*
* @return Collection of Host objects for Aerospike client to connect
*/
protected AerospikeDataSettings configureDataSettings() {
Copy link
Member

Choose a reason for hiding this comment

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

WDYT about renaming it to dataSettings?

Copy link
Author

@agrgr agrgr Jan 7, 2024

Choose a reason for hiding this comment

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

I am ok with it, but this is the method we have previously had. I think it is better to have the same name.

clientPolicy.writePolicyDefault.sendKey = aerospikeDataSettings().isSendKey();
clientPolicy.readPolicyDefault.sendKey = aerospikeDataSettings().isSendKey();
clientPolicy.writePolicyDefault.sendKey = true;
clientPolicy.readPolicyDefault.sendKey = true;
Copy link
Member

Choose a reason for hiding this comment

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

Add

clientPolicy.batchPolicyDefault.sendKey = true;

clientPolicy.writePolicyDefault.sendKey = aerospikeDataSettings().isSendKey();
clientPolicy.readPolicyDefault.sendKey = aerospikeDataSettings().isSendKey();
clientPolicy.writePolicyDefault.sendKey = true;
clientPolicy.readPolicyDefault.sendKey = true;
log.debug("AerospikeDataSettings.sendKey: {}", clientPolicy.writePolicyDefault.sendKey);
Copy link
Member

Choose a reason for hiding this comment

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

This log print is no longer relevant

}

// getHosts() return value has precedence over hosts parameter from application.properties
if (getHosts() != null) {
Copy link
Member

Choose a reason for hiding this comment

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

It's better to read getHosts() and nameSpace() into a variable once

import lombok.Data;

@Data
public class AerospikeSettings {
Copy link
Member

Choose a reason for hiding this comment

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

Add a brief Javadoc

// Send user defined key in addition to hash digest on both reads and writes
boolean sendKey = true;
@Builder.Default
boolean sendKey = false;
Copy link
Member

Choose a reason for hiding this comment

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

It is true by default in the properties file

@agrgr agrgr merged commit 8ef5cc0 into main Jan 8, 2024
10 checks passed
@agrgr agrgr deleted the FMWK-278-external-configuration branch January 8, 2024 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants