Fix downsampling with disabled subobjects#138715
Conversation
|
Pinging @elastic/es-storage-engine (Team:StorageEngine) |
|
Hi @gmarouli, I've created a changelog YAML for you. |
server/src/test/java/org/elasticsearch/action/admin/cluster/stats/MappingVisitorTests.java
Outdated
Show resolved
Hide resolved
...n/downsample/src/main/java/org/elasticsearch/xpack/downsample/TransportDownsampleAction.java
Show resolved
Hide resolved
| Map<String, Object> downsampledMapping = new HashMap<>(); | ||
| for (Map.Entry<String, Object> entry : sourceIndexMappings.entrySet()) { | ||
| if (entry.getKey().equals(PROPERTIES) == false) { | ||
| downsampledMapping.put(entry.getKey(), entry.getValue()); |
There was a problem hiding this comment.
Why do we need this? Maybe add a comment?
There was a problem hiding this comment.
Added a comment and a test to ensure this will not be accidentally removed.
| ); | ||
|
|
||
| HashMap<String, Object> result = new HashMap<>(); | ||
| MappingVisitor.visitAndCopyMapping(expectedProperties, result, (ignored, source, dest) -> { |
There was a problem hiding this comment.
Shall we also add a test that creates random mappings and checks that the copied one is a clone of the source?
There was a problem hiding this comment.
Let's add this separately.
…ats/MappingVisitorTests.java Co-authored-by: Kostas Krikellas <131142368+kkrik-es@users.noreply.github.com>
|
Update: I am currently working on the ci failures. The problem is that we need to be able to distringuish and handle differently a multi field from a subobjects false field :) Working on it. |
|
Waiting for #138869 |
| @SuppressWarnings("unchecked") | ||
| public void testVisitAndCopy() { | ||
| DataGeneratorSpecification specification = DataGeneratorSpecification.buildDefault(); | ||
| var template = new TemplateGenerator(specification).generate(); | ||
| MappingGenerator mappingGenerator = new MappingGenerator(specification); | ||
| for (int i = 0; i < MAPPING_GENERATION_ROUNDS; i++) { | ||
| var mapping = mappingGenerator.generate(template).raw(); | ||
| var properties = (Map<String, Object>) mapping.get("_doc"); | ||
| var updatedMapping = new HashMap<String, Object>(); | ||
| MappingVisitor.visitPropertiesAndCopyMapping(properties, updatedMapping, (f, source, dest) -> dest.put(f, source)); | ||
| assertThat(updatedMapping, equalTo(updatedMapping)); | ||
| } | ||
| } |
There was a problem hiding this comment.
@kkrik-es oh I did add this one, is this not what you had in mind?
💔 Backport failed
You can use sqren/backport to manually backport by running |
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation |
We change the way the downsampled mapping gets created. Instead of creating a new mapping with the metric fields and then merging it with the original, we use a visitor to copy and change the original. (cherry picked from commit c2e6a67) # Conflicts: # x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/TransportDownsampleAction.java # x-pack/plugin/downsample/src/test/java/org/elasticsearch/xpack/downsample/TransportDownsampleActionTests.java
We change the way the downsampled mapping gets created. Instead of creating a new mapping with the metric fields and then merging it with the original, we use a visitor to copy and change the original.
We change the way the downsampled mapping gets created. Instead of creating a new mapping with the metric fields and then merging it with the original, we use a visitor to copy and change the original. (cherry picked from commit c2e6a67) # Conflicts: # x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/TransportDownsampleAction.java # x-pack/plugin/downsample/src/test/java/org/elasticsearch/xpack/downsample/TransportDownsampleActionTests.java
The downsampling operation is editing the source mapping to replace gauge metrics with an aggregate type which contains the pre-aggregated data.
However, the process does not respect the disabled subobjects configured by parent fields, for example, a passthrough field and gets conflicts as it tried to reconstruct the updated mapping.
For example, the following valid mapping section:
gets converted to:
Which is not valid because the disabled subobjects is not set anymore.
This PR (re)proposes to use the visitor pattern to update the source mapping in place. Last time we proposed that there was a better solution; however, now we see that the original structure of the mapping is important for inherited properties.
Fixes: #138572