Skip to content

Commit

Permalink
fix:using constructor injection for MeterRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
youngzil committed Oct 14, 2024
1 parent a5578fb commit f4179d1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.ctrip.framework.apollo.configservice.service.config.ConfigServiceWithCache;
import com.ctrip.framework.apollo.configservice.service.config.DefaultConfigService;
import com.ctrip.framework.apollo.configservice.util.AccessKeyUtil;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -47,15 +48,18 @@ public class ConfigServiceAutoConfiguration {
private final ReleaseService releaseService;
private final ReleaseMessageService releaseMessageService;
private final GrayReleaseRuleRepository grayReleaseRuleRepository;
private final MeterRegistry meterRegistry;

public ConfigServiceAutoConfiguration(final BizConfig bizConfig,
final ReleaseService releaseService,
final ReleaseMessageService releaseMessageService,
final GrayReleaseRuleRepository grayReleaseRuleRepository) {
final ReleaseService releaseService,
final ReleaseMessageService releaseMessageService,
final GrayReleaseRuleRepository grayReleaseRuleRepository,
final MeterRegistry meterRegistry) {
this.bizConfig = bizConfig;
this.releaseService = releaseService;
this.releaseMessageService = releaseMessageService;
this.grayReleaseRuleRepository = grayReleaseRuleRepository;
this.meterRegistry = meterRegistry;
}

@Bean
Expand All @@ -67,7 +71,7 @@ public GrayReleaseRulesHolder grayReleaseRulesHolder() {
public ConfigService configService() {
if (bizConfig.isConfigServiceCacheEnabled()) {
return new ConfigServiceWithCache(releaseService, releaseMessageService,
grayReleaseRulesHolder(), bizConfig);
grayReleaseRulesHolder(), bizConfig, meterRegistry);
}
return new DefaultConfigService(releaseService, grayReleaseRulesHolder());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ public class ConfigServiceWithCache extends AbstractConfigService {
private final ReleaseService releaseService;
private final ReleaseMessageService releaseMessageService;
private final BizConfig bizConfig;

@Autowired
private MeterRegistry meterRegistry;
private final MeterRegistry meterRegistry;

private LoadingCache<String, ConfigCacheEntry> configCache;

Expand All @@ -79,11 +77,13 @@ public class ConfigServiceWithCache extends AbstractConfigService {
public ConfigServiceWithCache(final ReleaseService releaseService,
final ReleaseMessageService releaseMessageService,
final GrayReleaseRulesHolder grayReleaseRulesHolder,
final BizConfig bizConfig) {
final BizConfig bizConfig,
final MeterRegistry meterRegistry) {
super(grayReleaseRulesHolder);
this.releaseService = releaseService;
this.releaseMessageService = releaseMessageService;
this.bizConfig = bizConfig;
this.meterRegistry = meterRegistry;
nullConfigCacheEntry = new ConfigCacheEntry(ConfigConsts.NOTIFICATION_ID_PLACEHOLDER, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.ctrip.framework.apollo.biz.utils.ReleaseMessageKeyGenerator;
import com.ctrip.framework.apollo.core.dto.ApolloNotificationMessages;
import com.google.common.collect.Lists;
import io.micrometer.core.instrument.MeterRegistry;
import java.util.regex.Pattern;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -62,6 +63,8 @@ public class ConfigServiceWithCacheAndCacheKeyIgnoreCaseTest {
@Mock
private BizConfig bizConfig;
@Mock
private MeterRegistry meterRegistry;
@Mock
private GrayReleaseRulesHolder grayReleaseRulesHolder;

private String someAppId;
Expand All @@ -75,7 +78,7 @@ public class ConfigServiceWithCacheAndCacheKeyIgnoreCaseTest {
@Before
public void setUp() throws Exception {
configServiceWithCache = new ConfigServiceWithCache(releaseService, releaseMessageService,
grayReleaseRulesHolder, bizConfig);
grayReleaseRulesHolder, bizConfig, meterRegistry);

when(bizConfig.isConfigServiceCacheKeyIgnoreCase()).thenReturn(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.ctrip.framework.apollo.biz.service.ReleaseService;
import com.ctrip.framework.apollo.biz.utils.ReleaseMessageKeyGenerator;

import io.micrometer.core.instrument.MeterRegistry;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -59,6 +60,8 @@ public class ConfigServiceWithCacheTest {
@Mock
private BizConfig bizConfig;
@Mock
private MeterRegistry meterRegistry;
@Mock
private GrayReleaseRulesHolder grayReleaseRulesHolder;

private String someAppId;
Expand All @@ -71,7 +74,7 @@ public class ConfigServiceWithCacheTest {
@Before
public void setUp() throws Exception {
configServiceWithCache = new ConfigServiceWithCache(releaseService, releaseMessageService,
grayReleaseRulesHolder, bizConfig);
grayReleaseRulesHolder, bizConfig, meterRegistry);

configServiceWithCache.initialize();

Expand Down
5 changes: 2 additions & 3 deletions docs/en/deployment/distributed-deployment-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1528,9 +1528,8 @@ This configuration takes effect when config-service.cache.enabled is set to true
> `config-service.cache.stats.enabled` The adjustment configuration must be restarted config service to take effect.
This configuration works when `config-service.cache.stats.enabled` is true, it is used to control the opening of the cache statistics function.
The default is false, that is, it will not enable the cache statistics function, when it is set to true, it will enable the cache metric statistics function, see the reference index[Monitoring related-5.2 Metrics](en/design/apollo-design#5.2-Metrics)


The default is false, that is, it will not enable the cache statistics function, when it is set to true, it will enable the cache metric statistics function.
View metric reference index[Monitoring related-5.2 Metrics](en/design/apollo-design#5.2-Metrics),such as `http://${someIp:somePort}/prometheus`

### 3.2.4 `item.key.length.limit`- Maximum length limit for configuration item key

Expand Down
3 changes: 2 additions & 1 deletion docs/zh/deployment/distributed-deployment-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,8 @@ http://5.5.5.5:8080/eureka/,http://6.6.6.6:8080/eureka/
> `config-service.cache.stats.enabled` 配置调整必须重启 config service 才能生效
该配置作用于`config-service.cache.stats.enabled`为 true 时,用于控制开启缓存统计功能。
默认为 false,即不会开启缓存统计功能,当配置为 true 时,开启缓存metric统计功能,指标查看参考[监控相关-5.2 Metrics](zh/design/apollo-design#5.2-Metrics)
默认为 false,即不会开启缓存统计功能,当配置为 true 时,开启缓存metric统计功能
指标查看参考[监控相关-5.2 Metrics](zh/design/apollo-design#5.2-Metrics),如`http://${someIp:somePort}/prometheus`

### 3.2.4 item.key.length.limit - 配置项 key 最大长度限制

Expand Down

0 comments on commit f4179d1

Please sign in to comment.