ThreeMammals / Ocelot

.NET API Gateway
https://www.nuget.org/packages/Ocelot
MIT License
8.24k stars 1.62k forks source link

On the fly `ocelot.json` configuration merging #2037

Closed SheruGaur closed 3 months ago

SheruGaur commented 3 months ago

We are trying to merge multiple ocelot.json files without restarting the application with below code. However we are successfully able to merge on starting the application, but still application restart is required to merge multiple ocelot.*.json files changes. Even we updated latest ocelot version 23.2.2.

Please guide if we are missing any reference or any mistake in below mentioned code.

webBuilder.ConfigureAppConfiguration((context, config) =>
{
    var folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory);
    var path = Path.Combine(folder, "My\\folder");
    config.AddOcelot(path, context.HostingEnvironment, MergeOcelotJson.ToFile, optional: false, reloadOnChange: true); // with folder, environment and merging type
})

Our ocelot.json file structure is like:

  1. ocelot.common.json
  2. ocelot.mfcommon.json
raman-m commented 3 months ago

Hi @SheruGaur

The Q 1

still application restart is required to merge multiple ocelot.*.json files changes.

Correct! If you have partial config files, they will be merged only during Ocelot app start. And the same configuration will be available during Docker container life time.

The Q 2

On the fly ocelot.json configuration merging

This feature is not implemented for partial config files, ocelot.*.json! Ocelot is able to track ocelot.json on the fly if you use Administration feature or copy the ocelot.json file to app folder manually. Merging partial files on the fly requires a lot of development.


I have a question for you. Why do you need to update partial config files so often ? What's your user scenario? What's your deployment environment: self-contained, IIS, Docker, K8s, cloud?

If your environment is Docker and/or K8s then why not to manage Ocelot app version and its configuration ocelot.json by Docker image version, and create/kill Docker containers? This is more easy DevOps approach than juggling multiple partial files for long living Ocelot app instance.