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

ApolloConfigChangeListener interestedKeyPrefixes don't filter keys #3664

Closed
3 tasks done
Anilople opened this issue May 7, 2021 · 1 comment · Fixed by #3666
Closed
3 tasks done

ApolloConfigChangeListener interestedKeyPrefixes don't filter keys #3664

Anilople opened this issue May 7, 2021 · 1 comment · Fixed by #3666
Labels
area/client apollo-client kind/question Categorizes issue when someone want to know answer of a question kind/report-problem Categorizes issue when someone report the problem he/she meeted

Comments

@Anilople
Copy link
Contributor

Anilople commented May 7, 2021

  • I have checked the discussions
  • I have searched the issues of this repository and believe that this is not a duplicate.
  • I have checked the FAQ of this repository and believe that this is not a duplicate.

Describe the bug

In a spring boot application.

When user write

@ApolloConfigChangeListener(interestedKeyPrefixes = "logging.level.")
public void onChange(ConfigChangeEvent configChangeEvent) {
    // some code
}

Sometimes
configChangeEvent.changedKeys() will get keys which not start with logging.level.

A clear and concise description of what the bug is.

To Reproduce

1.Use a spring boot application with apollo

2. Write a configuration

@Configuration
public class ConfigChangeListenerConfiguration {

	private final Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@ApolloConfigChangeListener(interestedKeyPrefixes = "logging.level.")
	public void onChange(ConfigChangeEvent configChangeEvent) {
		Set<String> keys = configChangeEvent.changedKeys();
		logger.info("keys = {}", keys);
		for (String key : keys) {
			ConfigChange configChange = configChangeEvent.getChange(key);
			String oldValue = configChange.getOldValue();
			String newValue = configChange.getNewValue();
			logger.info("key = [{}], value from [{}] to [{}]", key, oldValue, newValue);
		}
	}
}

3. change config in by apollo portal

Add

a = 1
logging.level.root = DEBUG

to namespace application, release it.

4. watch out the log output

key = [a], value from [null] to [1]
key = [logging.level.root], value from [null] to [DEBUG]

The key a show in it.

Expected behavior

A clear and concise description of what you expected to happen.

Only keys start with logging.level. returned when user call configChangeEvent.changedKeys()

Additional Details & Logs

  • apollo client version 1.8.0

More details about log

2021-05-07 21:25:30.321  INFO 3920 --- [Apollo-Config-2] uration$$EnhancerBySpringCGLIB$$29b99271 : keys = [a, logging.level.root]
2021-05-07 21:25:30.321  INFO 3920 --- [Apollo-Config-2] uration$$EnhancerBySpringCGLIB$$29b99271 : key = [a], value from [null] to [1]
2021-05-07 21:25:30.321  INFO 3920 --- [Apollo-Config-2] uration$$EnhancerBySpringCGLIB$$29b99271 : key = [logging.level.root], value from [null] to [DEBUG]

If user want to delete the prefix of key by

key.substring("logging.level.".length());

without check, an exception will be throwed like follow

2021-05-07 21:28:08.609 ERROR 1364 --- [Apollo-Config-2] c.c.f.apollo.internals.AbstractConfig    : Failed to invoke config change listener com.ctrip.framework.apollo.spring.annotation.ApolloAnnotationProcessor$1

java.lang.StringIndexOutOfBoundsException: begin 14, end 1, length 1
	at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3734) ~[na:na]
	at java.base/java.lang.String.substring(String.java:1903) ~[na:na]
	at java.base/java.lang.String.substring(String.java:1876) ~[na:na]

Should user check it by self

if (key.startsWith("logging.level.")) {
    key.substring("logging.level.".length());
}

or apollo client help them to filter keys, only prefix matched keys will be keeped?

@Anilople Anilople added area/client apollo-client kind/question Categorizes issue when someone want to know answer of a question kind/report-problem Categorizes issue when someone report the problem he/she meeted labels May 7, 2021
@nobodyiam
Copy link
Member

This is the expected behavior with the current implementation. However, I'm not sure whether we could simply change the current behavior of configChangeEvent.changedKeys() since if we do so, it might cause problems in some user cases.
Yet, I think it sounds reasonable to only retrieve the interested keys, maybe we could add a new api? e.g. configChangeEvent.interestedChangedKeys()?

https://github.com/ctripcorp/apollo/blob/6deedb3e3f0eb981c66297091a230ffc64d1605b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfig.java#L441-L495

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/client apollo-client kind/question Categorizes issue when someone want to know answer of a question kind/report-problem Categorizes issue when someone report the problem he/she meeted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants