Azure / data-api-builder

Data API builder provides modern REST and GraphQL endpoints to your Azure Databases and on-prem stores.
https://aka.ms/dab/docs
MIT License
947 stars 195 forks source link

Fix MetadataProvider initialization in Hot Reload and remove duplicate Query Executor reloading #2428

Closed aaronburtle closed 4 weeks ago

aaronburtle commented 1 month ago

Why make this change?

Closes https://github.com/Azure/data-api-builder/issues/2426 Closes https://github.com/Azure/data-api-builder/issues/2427

What is this change?

Properly create and initialize a new set of SqlMetadataProviders as part of the hot-reload process of the SqlMetadataProviderFactory, by utilizing the initiaizeAsync() function. This guarantees a correctly configured set of meta data providers for the factory.

Remove the event handling to hot-reload the QueryExecutors classes specifically, since this is already handled during the hot-reload process of the QueryManagerFactory. That process creates new and up to date QueryExecutors as part of a hot-reload.

With the correct initialization of the meta data providers, we can remove the code that saves the DefaultDataSourceName to be passed along the hot-reloaded configs. With all of the data structures we initialized on new meta data providers, we do not need to save the data source name and hot-reloading will be more resilient. This is because we will build all of the data structures which depend on this DefaultDataSourceName fresh from newly created or cleared objects, and we do not have to worry about maintaining previous configuration's DefaultDataSourceName, everything will simply use the new name generated during a hot-reload.

How was this tested?

Testing Scenario

Scenario A: Handling a change in entities in the config Objective: Verify that hot-reload correctly refreshes the MetadataProviders and QueryExecutors when we hot-reload the entities by making a REST request.

Steps:

Start with MSSQL with a valid config file that contains some valid entities. Make a REST request that targets one of the entities and observe the results to compare against later. Change the entities section by removing an entity and any entities that have a relationship with that entity. Make a REST request for that entity and observe that the entity is not found. Add the removed entities back to the config file. Make a REST request for that same entity and observe the results match the original REST request.

Sample Request(s)

For the "Book" entity with a rest path of "rest"

https://localhost:5001/rest/Book

aaronburtle commented 1 month ago

/azp run

seantleonard commented 1 month ago

/azp run