You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#683 Validate placeholder duplicates in path templates (#1927)
* add validation for downstream path also
* add similiar route placeholders
* Add unit tests
* Refactor unit tests
* IDE1006: Naming rule violation
* IDE0028: Collection Initialization can be simplified
* Merge into one theory
* Less `IEnumerable<T>` usage to have less `IEnumerator<T>` objects in favor of the collection one
* Refactor validation of duplicated placeholders
* Finish unit testing
* Publish hidden Service Fabric feature
* Update acceptance tests
* Update integration tests
* Update release notes
---------
The author: Aly Kafoury <@AlyHKafoury>
Co-authored-by: Raman Maksimchuk <[email protected]>
<summary><b>New features of</b>: Service Fabric and ...</summary>
9
9
10
-
- Significant refactoring and design review of the [Multiplexer](https://github.com/ThreeMammals/Ocelot/tree/develop/src/Ocelot/Multiplexer)
11
-
- Optimizing multiplexer performance: `HttpContext` is not copied when there is only one downstream route, and etc.
12
-
- Fixed [the bug](https://github.com/ThreeMammals/Ocelot/pull/1462) in the multiplexer: `HttpContext.User` information was not copied if there was more than one downstream request.
13
-
</details>
14
-
15
-
<details>
16
-
<summary><b>System routing</b>. Content streaming when <ahref="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding">Transfer-Encoding</a>: 'chunked'</summary>
17
-
18
-
- Correction of [the bug](https://github.com/ThreeMammals/Ocelot/pull/1972) when creating requests: The header [Transfer-Encoding](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding): `chunked` was present even when there was no content or the request body size was 0. These cases are now addressed.
19
-
</details>
20
-
21
-
<details>
22
-
<summary><b>Updates of the features</b>: QoS, Load Balancer and Error Status Codes</summary>
23
-
24
-
-[Quality of Service](https://ocelot.readthedocs.io/en/latest/features/qualityofservice.html): Possibility of implementation of custom Polly v8.2 providers. New `AddPolly` extension methods.
25
-
-[Load Balancer](https://ocelot.readthedocs.io/en/latest/features/loadbalancer.html): Extension of the route key format, ensuring that the key remains unique for cases of **UpstreamHost** route property and **ServiceName** vs **ServiceNamespace** properties in Consul setup.
26
-
-[Error Status Codes](https://ocelot.readthedocs.io/en/latest/features/errorcodes.html): When [413 Content Too Large](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/413), Ocelot now returns a 413 `PayloadTooLargeError` (Ocelot error code `41`).
27
-
</details>
28
-
29
-
<details>
30
-
<summary>Documentation for <b>Request Aggregation</b></summary>
-**[Service Fabric](https://ocelot.readthedocs.io/en/latest/features/servicefabric.html)**: Published old undocumented "[Placeholders in Service Name](https://ocelot.readthedocs.io/en/23.2.0/features/servicefabric.html#placeholders-in-service-name)" feature of [Service Fabric](https://ocelot.readthedocs.io/en/23.2.0/features/servicefabric.html)[service discovery provider](https://ocelot.readthedocs.io/en/23.2.0/search.html?q=ServiceDiscoveryProvider). This feature is available starting from version [13.0.0](https://github.com/ThreeMammals/Ocelot/releases/tag/13.0.0).
- See [all bugs](https://github.com/ThreeMammals/Ocelot/issues?q=is%3Aissue+is%3Aclosed+label%3Abug+milestone%3AJanuary%2724) of the [January'24](https://github.com/ThreeMammals/Ocelot/milestone/4) milestone
16
+
-[683](https://github.com/ThreeMammals/Ocelot/issues/683) by PR [1927](https://github.com/ThreeMammals/Ocelot/pull/1927)
17
+
Ocelot configuration validation logic has updated with [new rules](https://github.com/search?q=repo%3AThreeMammals%2FOcelot+IsPlaceholderNotDuplicatedIn+IsUpstreamPlaceholderDefinedInDownstream+IsDownstreamPlaceholderDefinedInUpstream&type=code) to search for placeholder duplicates in path templates.
18
+
See more in the [FileConfigurationFluentValidator](https://github.com/search?q=repo%3AThreeMammals%2FOcelot%20FileConfigurationFluentValidator&type=code) class.
19
+
- See [all bugs](https://github.com/ThreeMammals/Ocelot/issues?q=is%3Aissue+is%3Aclosed+label%3Abug+milestone%3AFebruary%2724) of the [February'24](https://github.com/ThreeMammals/Ocelot/milestone/5) milestone
Copy file name to clipboardExpand all lines: docs/features/servicefabric.rst
+58-2
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ We also need to set up the **ServiceDiscoveryProvider** in **GlobalConfiguration
9
9
The example here shows a typical configuration.
10
10
It assumes *Service Fabric* is running on ``localhost`` and that the naming service is on port ``19081``.
11
11
12
-
The example below is taken from the `samples/OcelotServiceFabric <https://github.com/ThreeMammals/Ocelot/tree/main/samples/OcelotServiceFabric>`_ folder so please check it if this doesn't make sense!
12
+
The example below is taken from the `OcelotServiceFabric <https://github.com/ThreeMammals/Ocelot/tree/main/samples/OcelotServiceFabric>`_ sample, so please check it if this doesn't make sense!
13
13
14
14
.. code-block:: json
15
15
@@ -24,6 +24,7 @@ The example below is taken from the `samples/OcelotServiceFabric <https://github
24
24
}
25
25
],
26
26
"GlobalConfiguration": {
27
+
"BaseUrl": "https://ocelot.com"
27
28
"RequestIdKey": "OcRequestId",
28
29
"ServiceDiscoveryProvider": {
29
30
"Host": "localhost",
@@ -36,6 +37,61 @@ The example below is taken from the `samples/OcelotServiceFabric <https://github
36
37
If you are using stateless / guest exe services, Ocelot will be able to proxy through the naming service without anything else.
37
38
However, if you are using statefull / actor services, you must send the **PartitionKind** and **PartitionKey** query string values with the client request e.g.
38
39
39
-
GET http://ocelot.com/EquipmentInterfaces?PartitionKind=xxx&PartitionKey=xxx
40
+
GET ``http://ocelot.com/EquipmentInterfaces?PartitionKind=xxx&PartitionKey=xxx``
40
41
41
42
There is no way for Ocelot to work these out for you.
43
+
44
+
.. _sf-placeholders:
45
+
46
+
Placeholders in Service Name [#f1]_
47
+
-----------------------------------
48
+
49
+
In Ocelot, you can insert placeholders for variables into your ``UpstreamPathTemplate`` and ``ServiceName`` using the format ``{something}``.
50
+
51
+
It's important to note that the placeholder variable must exist in both the (**DownstreamPathTemplate** vs **ServiceName**) and the **UpstreamPathTemplate**.
52
+
The **UpstreamPathTemplate** should include all placeholders from the **DownstreamPathTemplate** and **ServiceName**;
53
+
otherwise, Ocelot will not start due to validation errors, which are logged.
54
+
55
+
Once the validation stage is cleared, Ocelot will replace the placeholder values in the **UpstreamPathTemplate** with those in the **DownstreamPathTemplate** and/or **ServiceName** for each processed request.
56
+
Thus, the :ref:`sf-placeholders` behave similarly to the :ref:`routing-placeholders` feature, but with the **ServiceName** property considered during the processing.
57
+
58
+
59
+
Placeholders example
60
+
^^^^^^^^^^^^^^^^^^^^
61
+
62
+
Here is the example of variable ``version`` in *Service Fabric* service name.
.WithMessage((_,route)=>$"{nameof(route.DownstreamPathTemplate)} '{route.DownstreamPathTemplate}' has duplicated placeholder");
44
+
45
+
RuleForEach(configuration =>configuration.Routes)
46
+
.Must(IsUpstreamPlaceholderDefinedInDownstream)
47
+
.WithMessage((_,route)=>$"{nameof(route.UpstreamPathTemplate)} '{route.UpstreamPathTemplate}' doesn't contain the same placeholders in {nameof(route.DownstreamPathTemplate)} '{route.DownstreamPathTemplate}'");
48
+
RuleForEach(configuration =>configuration.Routes)
49
+
.Must(IsDownstreamPlaceholderDefinedInUpstream)
50
+
.WithMessage((_,route)=>$"{nameof(route.DownstreamPathTemplate)} '{route.DownstreamPathTemplate}' doesn't contain the same placeholders in {nameof(route.UpstreamPathTemplate)} '{route.UpstreamPathTemplate}'");
0 commit comments