Add code formatting guidelines
Add 'eclipse' folder containing Eclipse code formatter configuration and instructions how to use it. Update rule for join_wrapped_lines - Set to `false` Resolves #930 Update README Address review comments
This commit is contained in:
committed by
Marius Bogoevici
parent
9632546f03
commit
bd002e4aaf
@@ -35,7 +35,7 @@ public class ApplicationMetrics {
|
||||
private final Date createdTime;
|
||||
|
||||
private String name;
|
||||
|
||||
|
||||
private Collection<Metric<?>> metrics;
|
||||
|
||||
private Map<String, Object> properties;
|
||||
|
||||
@@ -44,6 +44,8 @@ import org.springframework.util.PatternMatchUtils;
|
||||
public class ApplicationMetricsProperties
|
||||
implements ApplicationListener<ContextRefreshedEvent> {
|
||||
|
||||
private final MetricExportProperties metricExportProperties;
|
||||
|
||||
private String prefix = "";
|
||||
|
||||
@Value("${spring.application.name:${vcap.application.name:${spring.config.name:application}}}")
|
||||
@@ -53,17 +55,23 @@ public class ApplicationMetricsProperties
|
||||
|
||||
private String[] properties;
|
||||
|
||||
private final MetricExportProperties metricExportProperties;
|
||||
|
||||
public TriggerProperties getTrigger() {
|
||||
return metricExportProperties.findTrigger(BinderMetricsAutoConfiguration.APPLICATION_METRICS_EXPORTER_TRIGGER_NAME);
|
||||
}
|
||||
/**
|
||||
* List of properties that are going to be appended to each message. This gets
|
||||
* populate by onApplicationEvent, once the context refreshes to avoid overhead of
|
||||
* doing per message basis.
|
||||
*/
|
||||
private Map<String, Object> exportProperties = new HashMap<>();
|
||||
|
||||
public ApplicationMetricsProperties(MetricExportProperties metricExportProperties) {
|
||||
Assert.notNull(metricExportProperties, "'metricsExportProperties' cannot be null");
|
||||
this.metricExportProperties = metricExportProperties;
|
||||
}
|
||||
|
||||
public TriggerProperties getTrigger() {
|
||||
return metricExportProperties
|
||||
.findTrigger(BinderMetricsAutoConfiguration.APPLICATION_METRICS_EXPORTER_TRIGGER_NAME);
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
@@ -91,13 +99,6 @@ public class ApplicationMetricsProperties
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* List of properties that are going to be appended to each message. This gets
|
||||
* populate by onApplicationEvent, once the context refreshes to avoid overhead of
|
||||
* doing per message basis.
|
||||
*/
|
||||
private Map<String, Object> exportProperties = new HashMap<>();
|
||||
|
||||
public Map<String, Object> getExportProperties() {
|
||||
return exportProperties;
|
||||
}
|
||||
@@ -137,7 +138,7 @@ public class ApplicationMetricsProperties
|
||||
relaxedLoop: for (String relaxedPropertyName : relaxedNames) {
|
||||
if (isMatch(relaxedPropertyName, this.properties, null)) {
|
||||
Object value = source.getProperty(propertyName);
|
||||
String stringValue = ObjectUtils.nullSafeToString(value);
|
||||
String stringValue = ObjectUtils.nullSafeToString(value);
|
||||
Object exportedValue = null;
|
||||
if (value != null) {
|
||||
exportedValue = stringValue.startsWith("#{")
|
||||
|
||||
@@ -40,8 +40,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
||||
/**
|
||||
* Autoconfiguration registering an {@link Exporter} that publishes application metrics over
|
||||
* the {@link Emitter#applicationMetrics()} channel.
|
||||
* Autoconfiguration registering an {@link Exporter} that publishes application metrics
|
||||
* over the {@link Emitter#applicationMetrics()} channel.
|
||||
*
|
||||
* @author Vinicius Carvalho
|
||||
* @author Marius Bogoevici
|
||||
@@ -56,19 +56,15 @@ import org.springframework.context.annotation.Lazy;
|
||||
+ ".destination")
|
||||
public class BinderMetricsAutoConfiguration {
|
||||
|
||||
public static Log log = LogFactory.getLog(BinderMetricsAutoConfiguration.class);
|
||||
|
||||
public static final String APPLICATION_METRICS_EXPORTER_TRIGGER_NAME = "application";
|
||||
|
||||
@Bean
|
||||
public MetricJsonSerializer metricJsonSerializer() {
|
||||
return new MetricJsonSerializer();
|
||||
}
|
||||
public static Log log = LogFactory.getLog(BinderMetricsAutoConfiguration.class);
|
||||
|
||||
/**
|
||||
* Postprocessor for installing the {@link ApplicationMetricsExporter} as an
|
||||
* exporter under the name {@code application}.
|
||||
* @param endpoint the metrics endpoint (lazy reference to prevent early initialization)
|
||||
* Postprocessor for installing the {@link ApplicationMetricsExporter} as an exporter
|
||||
* under the name {@code application}.
|
||||
* @param endpoint the metrics endpoint (lazy reference to prevent early
|
||||
* initialization)
|
||||
* @param emitter the emitter bound interface
|
||||
* @param properties application metrics properties
|
||||
* @return
|
||||
@@ -101,4 +97,9 @@ public class BinderMetricsAutoConfiguration {
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MetricJsonSerializer metricJsonSerializer() {
|
||||
return new MetricJsonSerializer();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,6 +46,12 @@ public class MetricJsonSerializer {
|
||||
|
||||
private static final BlockingQueue<DateFormat> formatters = new LinkedBlockingQueue<DateFormat>();
|
||||
|
||||
private static DateFormat defaultDateFormat() {
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
|
||||
df.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
return df;
|
||||
}
|
||||
|
||||
public static class Serializer extends JsonSerializer<Metric<?>> {
|
||||
|
||||
@Override
|
||||
@@ -95,10 +101,4 @@ public class MetricJsonSerializer {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static DateFormat defaultDateFormat() {
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX");
|
||||
df.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
return df;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,8 @@ public class ApplicationMetricsExporterTests {
|
||||
.poll(10, TimeUnit.SECONDS);
|
||||
Assert.assertNotNull(message);
|
||||
ObjectMapper mapper = applicationContext.getBean(ObjectMapper.class);
|
||||
ApplicationMetrics applicationMetrics = mapper.readValue((String) message.getPayload(), ApplicationMetrics.class);
|
||||
ApplicationMetrics applicationMetrics = mapper.readValue((String) message.getPayload(),
|
||||
ApplicationMetrics.class);
|
||||
Assert.assertTrue(contains("integration.channel.errorChannel.errorRate.mean",
|
||||
applicationMetrics.getMetrics()));
|
||||
Assert.assertTrue(contains("mem", applicationMetrics.getMetrics()));
|
||||
@@ -171,7 +172,8 @@ public class ApplicationMetricsExporterTests {
|
||||
.poll(10, TimeUnit.SECONDS);
|
||||
Assert.assertNotNull(message);
|
||||
ObjectMapper mapper = applicationContext.getBean(ObjectMapper.class);
|
||||
ApplicationMetrics applicationMetrics = mapper.readValue((String) message.getPayload(), ApplicationMetrics.class);
|
||||
ApplicationMetrics applicationMetrics = mapper.readValue((String) message.getPayload(),
|
||||
ApplicationMetrics.class);
|
||||
Assert.assertFalse(contains("integration.channel.errorChannel.errorRate.mean",
|
||||
applicationMetrics.getMetrics()));
|
||||
Assert.assertTrue(contains("mem", applicationMetrics.getMetrics()));
|
||||
@@ -193,7 +195,8 @@ public class ApplicationMetricsExporterTests {
|
||||
.poll(10, TimeUnit.SECONDS);
|
||||
Assert.assertNotNull(message);
|
||||
ObjectMapper mapper = applicationContext.getBean(ObjectMapper.class);
|
||||
ApplicationMetrics applicationMetrics = mapper.readValue((String) message.getPayload(), ApplicationMetrics.class);
|
||||
ApplicationMetrics applicationMetrics = mapper.readValue((String) message.getPayload(),
|
||||
ApplicationMetrics.class);
|
||||
Assert.assertFalse(contains("mem", applicationMetrics.getMetrics()));
|
||||
Assert.assertTrue(contains("integration.channel.errorChannel.errorRate.mean",
|
||||
applicationMetrics.getMetrics()));
|
||||
@@ -225,7 +228,8 @@ public class ApplicationMetricsExporterTests {
|
||||
.poll(10, TimeUnit.SECONDS);
|
||||
Assert.assertNotNull(message);
|
||||
ObjectMapper mapper = applicationContext.getBean(ObjectMapper.class);
|
||||
ApplicationMetrics applicationMetrics = mapper.readValue((String) message.getPayload(), ApplicationMetrics.class);
|
||||
ApplicationMetrics applicationMetrics = mapper.readValue((String) message.getPayload(),
|
||||
ApplicationMetrics.class);
|
||||
Assert.assertTrue(contains("integration.channel.errorChannel.errorRate.mean",
|
||||
applicationMetrics.getMetrics()));
|
||||
Assertions.assertThat(applicationMetrics.getProperties().get("spring.cloud.application.guid"))
|
||||
@@ -260,13 +264,15 @@ public class ApplicationMetricsExporterTests {
|
||||
.poll(10, TimeUnit.SECONDS);
|
||||
Assert.assertNotNull(message);
|
||||
ObjectMapper mapper = applicationContext.getBean(ObjectMapper.class);
|
||||
ApplicationMetrics applicationMetrics = mapper.readValue((String) message.getPayload(), ApplicationMetrics.class);
|
||||
ApplicationMetrics applicationMetrics = mapper.readValue((String) message.getPayload(),
|
||||
ApplicationMetrics.class);
|
||||
Assert.assertTrue(contains("integration.channel.errorChannel.errorRate.mean",
|
||||
applicationMetrics.getMetrics()));
|
||||
Assertions.assertThat(applicationMetrics.getProperties().get("spring.cloud.application.guid.test.metrics"))
|
||||
.isEqualTo("highPriority");
|
||||
applicationContext.close();
|
||||
} finally {
|
||||
}
|
||||
finally {
|
||||
System.clearProperty("spring.cloud.application.guid.test.metrics");
|
||||
}
|
||||
}
|
||||
@@ -285,7 +291,8 @@ public class ApplicationMetricsExporterTests {
|
||||
.poll(10, TimeUnit.SECONDS);
|
||||
Assert.assertNotNull(message);
|
||||
ObjectMapper mapper = applicationContext.getBean(ObjectMapper.class);
|
||||
ApplicationMetrics applicationMetrics = mapper.readValue((String) message.getPayload(), ApplicationMetrics.class);
|
||||
ApplicationMetrics applicationMetrics = mapper.readValue((String) message.getPayload(),
|
||||
ApplicationMetrics.class);
|
||||
Assert.assertTrue(contains("integration.channel.errorChannel.errorRate.mean",
|
||||
applicationMetrics.getMetrics()));
|
||||
Assert.assertTrue(contains("mem", applicationMetrics.getMetrics()));
|
||||
|
||||
@@ -33,8 +33,10 @@ public class RelaxedPropertiesUtilsTests {
|
||||
RelaxedNames springEnv = new RelaxedNames("SPRING_APPLICATION_NAME");
|
||||
RelaxedNames springDot = new RelaxedNames("spring.application.name");
|
||||
RelaxedNames springCamel = new RelaxedNames("springApplicationName");
|
||||
RelaxedNames contentType = new RelaxedNames("spring.cloud.stream.bindings.applicationMetricsChannel.contentType");
|
||||
RelaxedNames contentTypeEnv = new RelaxedNames("SPRING_CLOUD_STREAM_BINDINGS_APPLICATION-METRICS-CHANNEL_CONTENT-TYPE");
|
||||
RelaxedNames contentType = new RelaxedNames(
|
||||
"spring.cloud.stream.bindings.applicationMetricsChannel.contentType");
|
||||
RelaxedNames contentTypeEnv = new RelaxedNames(
|
||||
"SPRING_CLOUD_STREAM_BINDINGS_APPLICATION-METRICS-CHANNEL_CONTENT-TYPE");
|
||||
RelaxedNames xyz = new RelaxedNames("My.X.Is");
|
||||
RelaxedNames springMetrics = new RelaxedNames("spring.cloud.stream.applicationMetricsChannel");
|
||||
RelaxedNames springMetricsEnv = new RelaxedNames("spring.cloud.stream.application-metrics-channel");
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -36,17 +35,17 @@ import static org.junit.Assert.assertEquals;
|
||||
public class MetricJsonSerializerTests {
|
||||
|
||||
@Test
|
||||
public void validateAlwaysGMTDateAndFormat() throws Exception {
|
||||
public void validateAlwaysGMTDateAndFormat() throws Exception {
|
||||
Date date = new Date(1493060197188L); // Mon Apr 24 14:56:37 EDT 2017
|
||||
Metric<Number> metric = new Metric<Number>("Hello", 123, date);
|
||||
|
||||
Metric<Number> metric = new Metric<Number>("Hello", 123, date);
|
||||
|
||||
JsonFactory factory = new JsonFactory();
|
||||
StringWriter writer = new StringWriter();
|
||||
StringWriter writer = new StringWriter();
|
||||
JsonGenerator jsonGenerator = factory.createGenerator(writer);
|
||||
Serializer ser = new Serializer();
|
||||
Serializer ser = new Serializer();
|
||||
ser.serialize(metric, jsonGenerator, null);
|
||||
jsonGenerator.flush();
|
||||
|
||||
|
||||
JSONObject json = new JSONObject(writer.toString());
|
||||
String serializedTimestamp = json.getString("timestamp");
|
||||
assertEquals("2017-04-24T18:56:37.188Z", serializedTimestamp);
|
||||
|
||||
Reference in New Issue
Block a user