Skip to content
This repository was archived by the owner on Jan 19, 2022. It is now read-only.

Commit 32d8225

Browse files
bsamartinsmaciejwalkowiak
authored andcommitted
Set CloudWatchProperties default batch size to API max.
Fixes gh-349 Closes gh-425
1 parent f5b675d commit 32d8225

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/metrics/CloudWatchProperties.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,24 @@
2424
*
2525
* @author Jon Schneider
2626
* @author Dawid Kublik
27+
* @author Bernardo Martins
2728
* @since 2.0.0
2829
*/
2930
@ConfigurationProperties(prefix = "management.metrics.export.cloudwatch")
3031
public class CloudWatchProperties extends StepRegistryProperties {
3132

33+
private static final int DEFAULT_BATCH_SIZE = 20;
34+
3235
/**
3336
* The namespace which will be used when sending metrics to CloudWatch. This property
3437
* is needed and must not be null.
3538
*/
3639
private String namespace = "";
3740

41+
public CloudWatchProperties() {
42+
setBatchSize(DEFAULT_BATCH_SIZE);
43+
}
44+
3845
public String getNamespace() {
3946
return this.namespace;
4047
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2013-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.cloud.aws.autoconfigure.metrics;
18+
19+
import java.util.Properties;
20+
21+
import org.junit.Test;
22+
23+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
24+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
25+
import org.springframework.context.annotation.Configuration;
26+
import org.springframework.core.env.PropertiesPropertySource;
27+
28+
import static org.assertj.core.api.Assertions.assertThat;
29+
30+
/**
31+
* @author Bernardo Martins
32+
*/
33+
public class CloudWatchPropertiesTest {
34+
35+
@Test
36+
public void properties_notSet_shouldHaveDefaultValues() {
37+
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(
38+
CloudWatchPropertiesConfiguration.class);
39+
40+
CloudWatchProperties cloudWatchProperties = applicationContext
41+
.getBean(CloudWatchProperties.class);
42+
assertThat(cloudWatchProperties.getNamespace()).isEqualTo("");
43+
assertThat(cloudWatchProperties.getBatchSize()).isEqualTo(20);
44+
}
45+
46+
@Test
47+
public void properties_set_shouldOverrideValues() {
48+
Properties properties = new Properties();
49+
properties.setProperty("management.metrics.export.cloudwatch.namespace", "test");
50+
properties.setProperty("management.metrics.export.cloudwatch.batch-size", "5");
51+
52+
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
53+
applicationContext.getEnvironment().getPropertySources()
54+
.addLast(new PropertiesPropertySource("test", properties));
55+
applicationContext.register(CloudWatchPropertiesConfiguration.class);
56+
applicationContext.refresh();
57+
58+
CloudWatchProperties cloudWatchProperties = applicationContext
59+
.getBean(CloudWatchProperties.class);
60+
assertThat(cloudWatchProperties.getNamespace()).isEqualTo("test");
61+
assertThat(cloudWatchProperties.getBatchSize()).isEqualTo(5);
62+
}
63+
64+
@Configuration
65+
@EnableConfigurationProperties(CloudWatchProperties.class)
66+
protected static class CloudWatchPropertiesConfiguration {
67+
68+
}
69+
70+
}

0 commit comments

Comments
 (0)