-
Notifications
You must be signed in to change notification settings - Fork 1.7k
#2248 Ensure correct mapping of RouteKeysConfig arrays in aggregates
#2328
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
base: develop
Are you sure you want to change the base?
#2248 Ensure correct mapping of RouteKeysConfig arrays in aggregates
#2328
Conversation
RouteKeysConfig arrays in aggregates
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.
@NandanDevHub Hi Nandan!
Thanks for your interest in Ocelot! 🐯
I noticed several fictitious changes stemming from the EOL Gotchas issue. I'll help you resolve them a bit later, as I know the best way to fix them. To be fair, reviewing the actual code is challenging with the fictitious changes, so I'll revisit the PR later as well.
The current CI build 268 is green, which means nothing was broken. However, since no tests were attached and there are only one or two tests related to complex aggregation, we definitely need more thorough tests. A must-have is writing bug #2248 repro acceptance tests to confirm that the fix resolves the original issue. While manual testing in Postman is a useful part of development, it's not enough for final delivery.
FYI, I won't mark this PR as draft because I believe it should be straightforward for you to handle the required testing given our development process. It's very likely this PR will be included in the next release for version 25.0, allowing this bug fix to be rolled out.
P.S. The current CI status is red due to a failed Coveralls check that says, "Please write more unit tests." 😉 Additionally, Coveralls provided this status update.
|
@ggnaegi Guil, would you mind taking the lead and pair-programming on this PR? |
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.
Avoid using AI tools to generate code❗
I noticed that the code in commit 19668d4 appears to have been generated by AI 😠
Code created this way will not be merged, and it won't help you understand the Ocelot codebase or successfully complete and deliver features or bug fixes. Moreover, the test is failing, dude 🙄
The test is currently failing❗
- Check the failed build here
|
Something unusual is happening after I reverted the
If it's alright with you, I'll rebase the branch onto the upstream develop. This should help clean up any fictitious changes from the commit history... So, going to rebase... |
bb83253 to
48363bd
Compare
48363bd to
3395986
Compare
|
@NandanDevHub Now the changes look good. The test has been moved to the |
Ready for Code Review@NandanDevHub After you complete the test and demonstrate that it effectively covers the bug's scenario, I will review this PR again. |
|
@raman-m sorry man for the trouble, especially fixing the EOL issues, cleaning up the branch, and rebasing everything. thanks man appreciate the effort you put in to make it right, and will add the test in same tests for test to cover the bug scenario. |
…regate route behavior
|
@raman-m The new test I ran the test locally twice once all and again with the two 2248 related tests do passes |
| { | ||
| var processing = new List<Task<HttpContext>>(); | ||
| var values = jObject.SelectTokens(matchAdvancedAgg.JsonPath).Select(s => s.ToString()).Distinct(); | ||
| var values = jObject.SelectTokens(matchAdvancedAgg.JsonPath).Select(s => s.ToString()).Distinct().ToList(); |
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.
| var values = jObject.SelectTokens(matchAdvancedAgg.JsonPath).Select(s => s.ToString()).Distinct().ToList(); | |
| var values = jObject.SelectTokens(matchAdvancedAgg.JsonPath).Select(s => s.ToString()).Distinct().ToArray(); |
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.
To be fair, creating a list or another collection isn't necessary since the foreach operator already processes IEnumerable object 🤣 LoL →
Ocelot/src/Ocelot/Multiplexer/MultiplexingMiddleware.cs
Lines 169 to 170 in f758ba7
| var values = jObject.SelectTokens(matchAdvancedAgg.JsonPath).Select(s => s.ToString()).Distinct(); | |
| foreach (var value in values) |
@NandanDevHub Please avoid using
ToList() to create the list, as it consumes a small amount of heap and adds unnecessary pressure on the garbage collector!FYI,
Distinct() is essentially a wrapper algorithm applied to a collection generated by multiple Select() operations.
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.
My suggestion:
- var values = jObject.SelectTokens(matchAdvancedAgg.JsonPath).Select(s => s.ToString()).Distinct();
+ var values = jObject.SelectTokens(matchAdvancedAgg.JsonPath).Select(ToString).Distinct();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.
@raman-m I've kept the explicit lambda here since SelectTokens() returns JToken items, i felt this way each tokens value is safely converted to string.
Also in below cmmit i confirmed the EOL formatting is fine now.
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.
OK, fair enough!
Could the code line be like this?
My suggestion:
var values = jObject.SelectTokens(matchAdvancedAgg.JsonPath).Distinct().Select(s => s.ToString());The idea is to skip creating the collection and applying the Distinct algorithm afterward. Instead, it's more efficient to search for distinct objects directly and then perform the casting to strings.
I'm not sure about the correctness because Distinct might return all J-tokens.
25d8ea8 to
378ce02
Compare
Lack of Unit Testing ❗@NandanDevHub I can't approve this PR because there are no unit tests. This issue is highlighted by the failed Coveralls build, which shows no unit tests and a decrease in the coverage factor. Please focus on adding unit tests for MultiplexingMiddleware. |
|
@ggnaegi Are you planning to manage this PR and assist the contributor in delivering it for the current release? |
2f06dda to
46252ad
Compare
|
@raman-m I have added a new unit test inside MultiplexingMiddlewareTests that exercises the |
|
Sorry, I’m tied up with a hot release and can’t assist right now. Please avoid mentioning me directly, as you already have an assigned mentor. Reach out to Guillaume for further help. FYIThanks for adding the commit 4dc2d1f, but which lines did you actually cover? |


Fixes #2248
Aggregated route failing to resolve nested
userIdparameter during downstream callsThis PR fixes an issue where aggregated routes failed to correctly resolve nested route parameters when the downstream route expected a placeholder (for example,
user/{id}) derived from the first service response.Previously, the aggregator was not correctly substituting the
JsonPathparameter value into the downstream request, resulting in empty or incorrect downstream calls during multi-service aggregation.Root Cause
JsonPathextracted value to the downstream route template.Proposed Changes
AggregatesCreatorto correctly propagate extracted route parameters (JsonPath→Parameter) into the downstream template.MultiplexingMiddlewareto ensure each downstream request uses the resolved parameter before invocation.Verified via
{ "comments": [ { "id": 1, "userId": 1 }, { "id": 2, "userId": 2 } ], "user": [ { "id": 1, "name": "Artem" }, { "id": 2, "name": "Ivan" } ] }