Add EMF config that enables adding extra properties to the EMF record#6259
Conversation
9ea2b83 to
89e7833
Compare
dlvenable
left a comment
There was a problem hiding this comment.
Thanks @mzurita-amz for this metrics improvement! I have a few comments.
| final List<MetricTagFilter> metricTagFilters, | ||
| @JsonProperty("disabled_metrics") | ||
| final List<String> disabledMetrics, | ||
| @JsonProperty("emf") |
There was a problem hiding this comment.
This is probably better to rename to emf_metrics to help make it clearer to somebody reading the config.
There was a problem hiding this comment.
Addressed in next rev
| import java.util.Map; | ||
|
|
||
| public interface EMFLoggingRegistryConfig extends StepRegistryConfig { | ||
| EMFLoggingRegistryConfig DEFAULT = k -> null; |
There was a problem hiding this comment.
ADdressed in next rev
| final List<MetricsLogger> metricsLoggers = registryWithProperties.metricsLoggers(); | ||
|
|
||
| assertThat(metricsLoggers.size(), equalTo(1)); | ||
| // Note: We can't directly verify putProperty calls without mocking the MetricsLogger |
There was a problem hiding this comment.
What other options do we have to verify this?
I see that these tests do not currently test the flush() method. But, maybe that would be ideal.
- Create a mock for
ISink. - Perform a flush.
- Extract the
MetricsContextprovided to your mock. - Assert the property exists on
getProperty - Assert there is no dimension in
getDimensions
There was a problem hiding this comment.
This works so far, though it is rough code and doesn't completely test it.
@Test
void testAdditionalPropertiesAreAddedToMetricsLogger_v2() {
final Map<String, String> additionalProperties = Map.of("key1", "value1", "key2", "value2");
final EMFLoggingRegistryConfig config = new EMFLoggingRegistryConfig() {
@Override
public String get(String key) {
return null;
}
@Override
public Map<String, String> additionalProperties() {
return additionalProperties;
}
};
Environment environment = mock(Environment.class);
ISink sink = mock(ISink.class);
when(environment.getSink()).thenReturn(sink);
final EMFLoggingMeterRegistry registryWithProperties = new EMFLoggingMeterRegistry(
config, environment, clock);
registryWithProperties.gauge("test_gauge", 1.0);
registryWithProperties.publish();
ArgumentCaptor<MetricsContext> contextArgumentCaptor = ArgumentCaptor.forClass(MetricsContext.class);
verify(sink).accept(contextArgumentCaptor.capture());
MetricsContext actualMetricsContext = contextArgumentCaptor.getValue();
assertThat(actualMetricsContext.getProperty("key1"), equalTo("value1"));
assertThat(actualMetricsContext.getProperty("key2"), equalTo("value2"));
}
There was a problem hiding this comment.
ADdressed in next rev. Made the test so it checks specific properties and its values.
|
|
||
| @Test | ||
| void testAdditionalPropertiesAreAddedToMetricsLogger() { | ||
| final Map<String, String> additionalProperties = Map.of("key1", "value1", "key2", "value2"); |
There was a problem hiding this comment.
Please use random keys and values for testing.
There was a problem hiding this comment.
Addressed next revision
|
|
||
| @Override | ||
| public Map<String, String> additionalProperties() { | ||
| return dataPrepperConfiguration.getEmfAdditionalProperties(); |
There was a problem hiding this comment.
NIT: Don't know if we want to return a copy to avoid mutating the map outside of the object.
There was a problem hiding this comment.
Or wrap in an unmodifiableMap.
return Collections.unmodifiableMap(dataPrepperConfiguration.getEmfAdditionalProperties());
| // Note: We can't directly verify putProperty calls without mocking the MetricsLogger | ||
| // This test verifies the registry can be created with additional properties config |
There was a problem hiding this comment.
Changed this test in next revision
dfd4bba to
90bae7e
Compare
|
|
||
| @Override | ||
| public Map<String, String> additionalProperties() { | ||
| return dataPrepperConfiguration.getEmfAdditionalProperties(); |
There was a problem hiding this comment.
Or wrap in an unmodifiableMap.
return Collections.unmodifiableMap(dataPrepperConfiguration.getEmfAdditionalProperties());
viquer
left a comment
There was a problem hiding this comment.
The small original comment still stands (return a copy, unmodifiable copy, of the properties), but I would not block on that for now.
| return new EMFLoggingRegistryConfig() { | ||
| @Override | ||
| public String get(String key) { | ||
| return null; |
There was a problem hiding this comment.
maybe it's better to throw an exception if we don't really expect this to be called. A new IllegalStateException("This method should never be called on normal circumstances")
There was a problem hiding this comment.
this method is used internally
ce86802 to
6f71e89
Compare
Signed-off-by: Manuel Mangas Zurita <mzurita@amazon.com>
6f71e89 to
46973a6
Compare
dlvenable
left a comment
There was a problem hiding this comment.
Thank you @mzurita-amz for this improvement!
Description
Adds EMF configuration to the DataPrepper config schema. This config supports adding additional properties to the EMF record by specifying the following in the config:
This will generate an EMF record with the following:
{ "_aws": { "Timestamp": 1762919187031, "CloudWatchMetrics": [ { "Namespace": "DataPrepper", "Metrics": [ {"Name": "test-pipeline.s3-source.s3ObjectsFailed.count", "Unit": "Count"}, // ... other metrics ], "Dimensions": [[]] } ] }, "test_property": "test_value", // ✅ OUR ADDITIONAL PROPERTY! "environment": "integration_test", // ✅ OUR ADDITIONAL PROPERTY! "test-pipeline.s3-source.s3ObjectsFailed.count": 1.0, "test-pipeline.s3-source.s3ObjectsSucceeded.count": 0.0, // ... other metric values }Issues Resolved
N/A
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.