POC: Simplifying un-abstracting projections and setup#70157
POC: Simplifying un-abstracting projections and setup#70157sorenlouv wants to merge 1 commit intoelastic:masterfrom
Conversation
| : []; | ||
|
|
||
| const params = mergeProjection(projection, { | ||
| const params = { |
There was a problem hiding this comment.
Moving away from mergeProjection will make the code a lot more clear - especially for reviewers when things are changed/moved around
There was a problem hiding this comment.
The reason why we have mergeProjection is two-fold:
lodash.mergemerges arrays in really weird ways- if you change a projection, its consumers do not need to update anything (usually).
The downside of spreading only means that you can miss places where the projection is being used. E.g., you'd have to manually inspect all references. Maybe that's a good thing though. Again not a defense - just want to highlight why it's there.
There was a problem hiding this comment.
if you change a projection, its consumers do not need to update anything (usually).
This makes sense. Could we achieve the same with unit tests to ensure that projections are correctly applied?
There was a problem hiding this comment.
that depends on the nature of the change. for additive changes, no. for other changes, yes (arguably already covered by snapshot testing of queries)
| }, | ||
| }) | ||
| : filter, | ||
| filter: [...projection.body.query.bool.filter, ...serviceNameFilter], |
There was a problem hiding this comment.
This is a good example of the confusion I get from the projection:
- we have a higher order function
mergeProjectionthat merges some stuff - then we have
projection.body.query.boolwhich is spreaded ontobool(is this needed if we already havemergeProjection?) - then we have a specific part of the projection being merged with the full
boolprojection + some other stuff
What takes precendence? Is ...projection.body.query.bool really needed?
In my rewrite I propose we do away with mergeProjection because it's quite opaque in it's merge behaviour. Instead I suggest we do dead-simple spread concatenations (filter: [...projection.body.query.bool.filter, ...serviceNameFilter]), or even prop assignments (index: projection.index).
There was a problem hiding this comment.
mergeProjection = mergePlainObject, e.g. it doesn't merge arrays. If you merge arrays, you can't remove items. Arguably the same applies for merging objects, but that feels more natural. If I speak for myself, in some cases I use explicit spreading so that the shape of the request (ie the result of mergeProjection) is more clear. (Not a argument for or against projections, just an explanation).
💔 Build Failed
Failed CI Steps
Test FailuresKibana Pipeline / kibana-xpack-agent / X-Pack APM API integration tests (basic).x-pack/test/apm_api_integration/basic/tests/feature_controls·ts.APM specs (basic) apm feature controls APIs can be accessed by global_all userStandard OutStack TraceKibana Pipeline / kibana-xpack-agent / X-Pack APM API integration tests (basic).x-pack/test/apm_api_integration/basic/tests/feature_controls·ts.APM specs (basic) apm feature controls APIs can be accessed by global_all userStandard OutStack TraceKibana Pipeline / x-pack-intake-agent / X-Pack Jest Tests.x-pack/plugins/apm/server/lib/services.services queries fetches the service itemsStandard OutStack Traceand 1 more failures, only showing the first 3. Build metrics
To update your PR or re-run it, just comment with: |
|
@sqren just my 2$, I like |
@dgieselaar It's just yet another thing that's opaque. For instance when |
Started with a single file where
setupis no longer passed (individual params are passed instead).