Migrating Spring-based Application Configuration to Alibaba Cloud ACM

Recently, some of my developer friends want to migrate their Java Spring application configuration to Alibaba Cloud Application Configuration Management (ACM). During the migration process, they asked some interesting questions. This article uses a simple example to explain their concerns during the migration process and gives the corresponding solutions. I hope you will find them helpful.

What Configuration Items Are Required to Be Migrated to ACM?

This is the first question for all users who want to migrate their configuration to ACM. Let’s analyze this question in two dimensions — timeliness and security.

Image for post
Image for post

Timeliness: Comparison between Static and Dynamic Configuration Items

Static configuration items refer to those that basically do not need to be modified after the application is released. For example:

  • Software version number: The version number does not usually need to be changed after it is determined.
  • Log style: The layout of the log, for example, the timestamp, file name, and log level, typically does not need major changes.
  • Third-party software LicenseKey: Basically, it does not change. It is possible that a third-party software license is updated during use. However, such a configuration change can usually be handled by republishing the software.
  • PaaS platform connection string: For example, a database connection string contains the database name, username and password. This configuration item does not change unless the password is modified for the sake of compliance, or the database is changed.

Dynamic configuration refers to some configuration items which may change when the program is running. Such changes usually affect the running behavior of the program, for example:

  • Throttling parameters: Throttling parameters are generally not fixed. Throttling parameters, such as the response time (RT) threshold and peak transaction per second (TPS), are adjusted dynamically according to the actual workload pattern when the system is running.
  • Thresholds for monitoring and alerts: For example, the system generates an error alert when the transaction volume decreases by 20% in comparison with the previous period, and generates a critical alert when it decreases by 50%. For a monitoring system, the online service characteristics change frequently, so the thresholds are generally not fixed.
  • Log print level: For example, after something strange happens, we want to change the log print level from error to debug. We’d prefer dynamically adjusting this configuration item without restarting the application.
  • Multi-active disaster recovery: After a site suffers from a disaster, we definitely hope the service can be failed over as soon as possible. Therefore, this configuration item must take effect in seconds to minimize the asset loss.

In terms of timeliness, we recommend that users save their own copies of static configuration items, which should be as simple as possible. Dynamic configuration items need to be saved to the ACM to increase the flexibility and the timeliness of dynamic changes.

Security: Comparison between Non-Sensitive and Sensitive Configuration Items

Non-sensitive configuration items generally refer to technology-oriented configuration items. Exposing them does not cause security risks. For example:

  • Software version number: It iterates with the product and contains no business attributes. Therefore, it is not sensitive.
  • Log style: This configuration item is associated with the future diagnostics of a program, and it is not sensitive.
  • Log print level: This configuration item determines the content of a log to be printed, and it is not sensitive.
  • Throttling parameters: Throttling parameters are mainly used to maintain internal application stability, and they are not sensitive.
  • Thresholds for monitoring and alerts: They mainly specify the alert precision for the business, and they are not sensitive.
  • Multi-active disaster recovery: This configuration item is generally associated with the primary-backup configuration and service sharding. It is not sensitive.

Sensitive configuration items are often associated with business data and can cause security risks if they are disclosed to unauthorized persons, for example:

  • Third-party software LicenseKey: The disclosure of the license key may cause unauthorized use of it. It is sensitive.
  • PaaS platform connection string: For example, both internal and external users can easily log on to the business database and access sensitive business information with a database connection string. It is sensitive.

In terms security, we recommend that users save their own copies of the non-sensitive configuration items, which should be as simple as possible. Sensitive configuration items need to be saved to the ACM. For sensitive configuration items, encryption and authentication are required, and these items must be secured from unauthorized persons.

Image for post
Image for post

The summary for the timeliness and security analysis

How Can I Migrate Spring-based Java Application Configuration?

Java developers who use the Spring framework usually use the @value function to automatically insert configuration.

The Original Pure Static File Scenario

For example, this configuration contains two configuration items, the software version number and the database connection string:

Image for post
Image for post

We can automatically insert the configuration items by using the @PropertySource and @value annotations.

Operations such as the connection and initialization of the related database are omitted in the above code.

The Mixed Configuration Scenario after the Start of the Configuration Migration

For the sake of security compliance or configuration timeliness, we need to migrate our configuration to the ACM. After the analysis, we found that we’d better migrate some database configurations to ACM. These configuration items are marked in red. The red part will be migrated to the ACM.

Next, we need to make the following three modifications.

  • Add a record for the relevant configuration on the ACM console.
  • Add ACM SDK dependencies to the Java engineering package.
  • Slightly modify the code — add annotations to enable ACM to retrieve configurations.

First, directly create a configuration item on ACM with the name of myapp.dbconfig.properties, and edit the configuration content in the corresponding edit box. For detailed instructions, see the ACM Quick Start document. The operation screenshots are as follows:

Image for post
Image for post

Second, add dependencies into maven’s pom.xml file:

Third, add API annotations to the corresponding AppConfig.java code, to enable ACM to retrieve dynamic configurations. Add the red part to the code.

Now, the modification is finished. Because the ACM SDK supports Spring’s @value annotation function, we barely need to modify the code.

Notes:

In the above code example, note that:

More Information

If you are interested in Nacos, the open source version of Alibaba Cloud ACM, visit our official website at https://developer.alibabacloud.com/opensource/project/nacos?spm=a2c41.12714924.0.0.70b62201UNffuJ

Reference:https://www.alibabacloud.com/blog/migrating-spring-based-application-configuration-to-alibaba-cloud-acm_594627?spm=a2c41.12714924.0.0

Written by

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store