Skip to content

[Cherry pick] Fix for Config File Path not found#1693

Merged
Aniruddh25 merged 5 commits intorelease/0.8from
cherryPickDockerBug
Sep 7, 2023
Merged

[Cherry pick] Fix for Config File Path not found#1693
Aniruddh25 merged 5 commits intorelease/0.8from
cherryPickDockerBug

Conversation

@Aniruddh25
Copy link
Copy Markdown
Collaborator

Aniruddh25 and others added 5 commits August 29, 2023 09:38
## Why make this change?

- With the overhaul of the config system using our own Write method
while serializing objects, the config that is generated is misaligned
with respect to indentation for all the keys under each entity name.
For e.g.:
In the following picture, the entity name `Todo` is indented with 4
leading spaces, subsequently its child key `source` should have been
indented with 6 leading spaces, however its currently indented with only
2 spaces.


![image](https://github.com/Azure/data-api-builder/assets/3513779/4c4a926f-ae22-444e-bc86-23f207b3cf22)

- This is a regression in 0.8.44-rc.

## What is this change?

- Use the same writer to serialize the subkeys under the entity name so
that the depth of indentation is maintained.

## How does this change fix the issue?
- `WriteRawValue` writes the json string argument provided as is without
doing any additional formatting on it. It doesn't utilize the
`_currentDepth` private member of the writer to determine how to indent.

- Prior to this change, we were generating the inner json string first
then writing the generated inner json "as is". While generating that
json on line 29


https://github.com/Azure/data-api-builder/blob/31b754251832ffebf4c4ce36ffcbead9baff6355/src/Config/Converters/RuntimeEntitiesConverter.cs#L29

Line 29 in
[31b7542](31b7542)

a new writer is being used by the `JsonSerializer.Serialize()` function,
effectively resetting the `_currentDepth`. The `_currentDepth` of the
writer in context was not getting honored.

## How was this tested?

- Manual test, building solution and using `dab add` to simulate
automatic writing of an entity to the config file. With the change, the
indentation is fixed.


![image](https://github.com/Azure/data-api-builder/assets/3513779/bf708ecc-4fa2-4711-ba88-844c24922b81)
## Why make this change?

- Closes #1674 ConfigFile was not found when running in the Azure
Container Apps.

## What is this change?

- Because of the way we used to fetch the cofigFileName, the path was
lost, due to which using config file present in a different directory
was giving `file not found` error.
- So we updated the method to fetch the configFileNamewihoutExtension to
keep the original path.
- To run Azure Container Apps `--ConfigFileName` is provided with the
full path name to the mounted config file.

NOTE:
* This issue might be caught in Az Container apps but this is not
specifically related to Containers, because the current file name
generation process was itself incorrect in 0.8.* release.
* When we try to get the `fileNameWithoutExtension` in the method
`GetFileNameForEnvironment`, we used to lose directory information, for
example: if baseConfigFile is`dab/configs/dab-config.json`, then
`configFileNameWithoutExtension` was coming as `dab-config`, which is
incorrect.
* This issue started happening from 0.8.* because in the earlier release
(0.7.6), if config file name is provided by user, we directly used it
without searching for overrides and environments, unlike 0.8.*. And the
precedence check used to happen for cases where config file is not
provided by user.
* Now, since 0.8.*, we started using the method
`GetFileNameWithoutExtension`, which is incorrect causing File not found
issue whenever the config file is not in current directory.
* The method `DoesFileExistInCurrentDirectory()` checks if the file
exists by combining the current directory with the fileName. Now if file
is existing in some other directory inside current directory, then for
proper searching the file should contain complete info about the
directory. So, if current dicrectory is `C:/dab`, and file is in
`C:/dab/configs/dab-config.json`, then the file name should either be
full path or `/configs/dab-configs.json` for it to be searched.

## Additional Change
1. Fixing name of variables and function name to correctly reflect their
behavior.
2. Fixing issue with not honoring the user provided config file, (caused
after 0.8 release). (Putting in this PR, because this PR aims at fixing
how we are using the config files and not just a bug fix.)

## How was this tested?

- [X] Running In Azure Container Apps
BEFORE:

![image](https://github.com/Azure/data-api-builder/assets/102276754/183d9399-9822-4435-8322-e7bfc5016e1e)

AFTER:

![image](https://github.com/Azure/data-api-builder/assets/102276754/fb7010c9-4410-48cf-9146-9cc757f209a0)

- [X] Local Testing
BEFORE:

![image](https://github.com/Azure/data-api-builder/assets/102276754/742cfd03-ee54-4f0c-8ea4-9e1d2303bbf8)

AFTER:

![image](https://github.com/Azure/data-api-builder/assets/102276754/bef4d153-9f5a-470b-8fbb-27ed7219fac6)

- [X] Unit Tests

---------

Co-authored-by: Aniruddh Munde <[email protected]>
Copy link
Copy Markdown
Contributor

@aaronburtle aaronburtle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Aniruddh25 Aniruddh25 merged commit 69f4535 into release/0.8 Sep 7, 2023
@Aniruddh25 Aniruddh25 deleted the cherryPickDockerBug branch September 7, 2023 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants