-
Notifications
You must be signed in to change notification settings - Fork 37
Handle log context with more than 100 metrics #42
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,44 +22,39 @@ | |
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.With; | ||
|
||
/** Represents the root of the EMF schema. */ | ||
@AllArgsConstructor | ||
@JsonFilter("emptyMetricFilter") | ||
class RootNode { | ||
@Getter | ||
@With | ||
@JsonProperty("_aws") | ||
private Metadata aws = new Metadata(); | ||
private Metadata aws; | ||
|
||
private Map<String, Object> properties = new HashMap<>(); | ||
private Map<String, List<Double>> metrics = new HashMap<>(); | ||
private ObjectMapper objectMapper = new ObjectMapper(); | ||
private Map<String, Object> properties; | ||
private ObjectMapper objectMapper; | ||
|
||
RootNode() { | ||
final SimpleFilterProvider filterProvider = | ||
new SimpleFilterProvider().addFilter("emptyMetricFilter", new EmptyMetricsFilter()); | ||
aws = new Metadata(); | ||
properties = new HashMap<>(); | ||
objectMapper = new ObjectMapper(); | ||
objectMapper.setFilterProvider(filterProvider); | ||
} | ||
|
||
public void putProperty(String key, Object value) { | ||
properties.put(key, value); | ||
} | ||
|
||
/** | ||
* Add a metric measurement. Multiple calls using the same key will be stored as an array of | ||
* scalar values | ||
*/ | ||
void putMetric(String key, double value) { | ||
if (!metrics.containsKey(key)) { | ||
metrics.put(key, new ArrayList<>()); | ||
} | ||
metrics.get(key).add(value); | ||
} | ||
|
||
Map<String, Object> getProperties() { | ||
return properties; | ||
} | ||
|
@@ -70,9 +65,13 @@ Map<String, Object> getTargetMembers() { | |
Map<String, Object> targetMembers = new HashMap<>(); | ||
targetMembers.putAll(properties); | ||
targetMembers.putAll(getDimensions()); | ||
for (Map.Entry<String, List<Double>> entry : metrics.entrySet()) { | ||
List<Double> values = entry.getValue(); | ||
targetMembers.put(entry.getKey(), values.size() == 1 ? values.get(0) : values); | ||
List<MetricDefinition> metrics = | ||
aws.getCloudWatchMetrics().stream() | ||
.flatMap(metricDirective -> metricDirective.getMetrics().values().stream()) | ||
.collect(Collectors.toList()); | ||
for (MetricDefinition metric : metrics) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We’re iterating over this collection twice. Can we do this in one pass? |
||
List<Double> values = metric.getValues(); | ||
targetMembers.put(metric.getName(), values.size() == 1 ? values.get(0) : values); | ||
} | ||
return targetMembers; | ||
} | ||
|
@@ -88,6 +87,10 @@ Map<String, String> getDimensions() { | |
return dimensions; | ||
} | ||
|
||
Map<String, MetricDefinition> metrics() { | ||
return aws.getCloudWatchMetrics().get(0).getMetrics(); | ||
} | ||
|
||
String serialize() throws JsonProcessingException { | ||
return objectMapper.writeValueAsString(this); | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend adding a comment about what you’re doing here and why. Unfortunately, this bit of complexity exists because of constraints in the backend and it may not be clear to others what’s happening here.