DRM FAQ
This topic answers common questions about using Dynamic Resource Management (DRM) and provides solutions.
How to dynamically set log levels using DRM?
Applications developed with SOFABoot have the following default log configurations:
application.properties
# log level for current application with groupid com.hula.sofa
logging.level.com.hula.sofa=INFOlogback-spring.xml
<springProperty scope="context" name="logging.level" source="logging.level.com.hula.sofa"/>To dynamically update the log level using DRM, follow these steps:
Define the dynamic configuration class in your SOFABoot project.
The following code provides an example:
import com.alipay.drm.client.DRMClient; import com.alipay.drm.client.api.annotation.DAttribute; import com.alipay.drm.client.api.annotation.DObject; import com.alipay.drm.client.api.model.DependencyLevel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.logging.LogLevel; import org.springframework.boot.logging.LoggingSystem; @DObject(region="hula", appName ="dynamic-log-level", id ="com.hula.sofa.config.DynamicConfig") public class DynamicConfig{ // Use the value from application.properties as the default value. @DAttribute @Value("${logging.level.com.hula.sofa}") private String loglevel; @Autowired LoggingSystem loggingSystem; public void init(){ DRMClient.getInstance().register(this); } public String getLoglevel(){ return loglevel; } public void setLoglevel(String loglevel){ this.loglevel = loglevel; LogLevel level =LogLevel.valueOf(loglevel.toUpperCase()); // Use Spring Boot's LoggingSystem to set the log level for the target logger. loggingSystem.setLogLevel("com.hula.sofa", level); } }Add the following dynamic configuration on the SOFA microservice platform.
For more information, see Add a dynamic configuration.
NoteThe client does not display the new value after a successful configuration push.
Why does a property get the pushed value instead of the default value after a service restart?
By default, when a client starts, it synchronizes configuration values from the server-side. To disable this behavior, set @DAttribute(dependency = DependencyLevel.NONE).
The dependency levels are described as follows:
Dependency level | Description |
|---|---|
NONE | No dependency. The server-side value is not loaded at startup. With this level, the client only accepts configuration pushes from the server-side during runtime. |
ASYNC | Asynchronous update. The server-side value is loaded asynchronously at startup. The loading result is ignored. |
WEAK | Weak dependency. The server-side value is loaded synchronously at startup.
|
STRONG | Strong dependency. The server-side value is loaded synchronously at startup.
|
EAGER | Eager dependency. The server-side value must be pulled at startup. If the server-side has not pushed a value, an exception is thrown and the application fails to start. |
How to assign an initial value to a property?
You can assign a value to a property in one of the following ways:
Assign the value directly in the definition. For example:
private String loglevel = "info".Retrieve the value from
application.properties. The following code shows examples:@DAttribute private String loglevel ="info"; // The initial value is info.Or
@Value("${logging.level.com.hula.sofa}") @DAttributeprivate String loglevel;ImportantDo not assign the value in the `init` method. Otherwise, the pushed value is overwritten by the default value when the client restarts, which causes subsequent pushes to fail. The following code provides an example:
public void init(){ DRMClient.getInstance().register(this); setLoglevel("info"); }
Deployment gets stuck during the service deployment step and fails due to a timeout
Symptom:
The deployment process stalls at the service deployment step and fails after an 8-minute timeout.
Cause:
You set RefreshCacheDRM.refreshCacheType = GEOHASH in DRM. After receiving this update, the application code takes more than 10 minutes to process the business logic.
Solution:
Workaround: Set
RefreshCacheDRM.refreshCacheType = null. This temporarily prevents the business logic from being triggered.Long-term solution: Optimize your application code. After receiving a property update from DRM, use an asynchronous thread to process the business logic. Then, promptly send a success signal back to DRM.