Skip to content
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

[Backport 2.x] JSON Catalog Reader for Integrations #1392

Merged
merged 1 commit into from
Jan 31, 2024

Conversation

opensearch-trigger-bot[bot]
Copy link
Contributor

Backport 6bd872c from #1288.

* Add full statics scan method

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add sample data to serialization method

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Finish integration serialization

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Rename integration reader and add stub json adaptor

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add JsonCatalogDataAdaptor directory type checking

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add integration version filtering to json_data_adaptor

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Remove unviable serialization implementation

The existing serialization implementation was not able to recover all data, as mapping information associating file names with the content was lost in appending the file content at the end of the JSON object.
In order to work around this, a new serialization method needs to add this association.
The most viable solution I see is to add encoded file data right next to the file names within the config, which will make it slightly harder to read if word wrap is enabled, but otherwise solves the issue.

Going to clear this method out entirely for now and restore old functionality with TDD.

Alternative solution: We can make a loose association by making heavy assumptions about array ordering and with complicated parsing logic, but I'm not sure it's worth it.
Better to just go back to the drawing board and make a serialization method that's more flexible.

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add new static serialization

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add component and sample data serialization

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Fix serialization test for new serialization approach

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add new asset serialization

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Fix broken compareVersions comparison and version sorting

When I noticed that adaptors had to handle version sorting, I started writing a test to verify the versions were being sorted.
While verifying the test, I noticed a weird result where 2.0.0 was being sorted after both 1.0.0 and 2.1.0.
After moving the comparison function over to integration_reader where it should be and writing tests,
I saw the method was falsely saying 2.0.0 and 2.1.0 were equal.

Debugging the comparison, I found that the version '1.2.3' was being parsed as [1, NaN, NaN].
Several more minutes of banging my head against my desk, and I realized that the suspect was this line:
`a.split('.').map(Number.parseInt)`.
Because parseInt takes two arguments (number and radix), map was giving it the part *and the index*.

The error went away after fixing the method to use only the part.

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add ability to read config file from json integration

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add rudimentary integration search to JSONAdaptor

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Create readRawConfig method to avoid data pruning

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add localized config parsing to getAssets

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Convert getSampleData to use localized config

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Move localized reader logic to helper method

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Convert getSchemas to use new data retrieval

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add localized config handling for getStatic

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add basic validation test for JSON reader

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add static validation to integration reader

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add more tests for deepCheck on JSON catalog

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add tests for json adaptor edge cases

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add reserialization tests

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add tests and remove redundant error checks for 90% coverage

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Fix lints in repository.test.ts

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Fix lints for integrations_builder.ts

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Update snapshots

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Revert "Update snapshots"

This reverts commit 62b238d.

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Use semver library for comparison

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Switch to upstream NDJson parser

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add inline documentation for IntegrationPart

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Move deepCheck to utils

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Add further utility methods to utils

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

* Refactor repository tests to not rely on result.ok == false

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>

---------

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
(cherry picked from commit 6bd872c)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Copy link

codecov bot commented Jan 30, 2024

Codecov Report

Attention: 16 lines in your changes are missing coverage. Please review.

Comparison is base (305e037) 53.53% compared to head (7873e9f) 54.19%.

Files Patch % Lines
...tors/integrations/repository/integration_reader.ts 91.35% 16 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              2.x    #1392      +/-   ##
==========================================
+ Coverage   53.53%   54.19%   +0.66%     
==========================================
  Files         312      314       +2     
  Lines       10962    11114     +152     
  Branches     2879     2921      +42     
==========================================
+ Hits         5868     6023     +155     
+ Misses       5046     5043       -3     
  Partials       48       48              
Flag Coverage Δ
dashboards-observability 54.19% <94.20%> (+0.66%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Swiddis Swiddis merged commit 216aa92 into 2.x Jan 31, 2024
21 of 34 checks passed
@Swiddis Swiddis deleted the backport/backport-1288-to-2.x branch January 31, 2024 19:51
amsiglan pushed a commit to amsiglan/dashboards-observability that referenced this pull request Jun 7, 2024
…ct#1392)

* Add full statics scan method

* Add sample data to serialization method

* Finish integration serialization

* Rename integration reader and add stub json adaptor

* Add JsonCatalogDataAdaptor directory type checking

* Add integration version filtering to json_data_adaptor

* Remove unviable serialization implementation

The existing serialization implementation was not able to recover all data, as mapping information associating file names with the content was lost in appending the file content at the end of the JSON object.
In order to work around this, a new serialization method needs to add this association.
The most viable solution I see is to add encoded file data right next to the file names within the config, which will make it slightly harder to read if word wrap is enabled, but otherwise solves the issue.

Going to clear this method out entirely for now and restore old functionality with TDD.

Alternative solution: We can make a loose association by making heavy assumptions about array ordering and with complicated parsing logic, but I'm not sure it's worth it.
Better to just go back to the drawing board and make a serialization method that's more flexible.

* Add new static serialization

* Add component and sample data serialization

* Fix serialization test for new serialization approach

* Add new asset serialization

* Fix broken compareVersions comparison and version sorting

When I noticed that adaptors had to handle version sorting, I started writing a test to verify the versions were being sorted.
While verifying the test, I noticed a weird result where 2.0.0 was being sorted after both 1.0.0 and 2.1.0.
After moving the comparison function over to integration_reader where it should be and writing tests,
I saw the method was falsely saying 2.0.0 and 2.1.0 were equal.

Debugging the comparison, I found that the version '1.2.3' was being parsed as [1, NaN, NaN].
Several more minutes of banging my head against my desk, and I realized that the suspect was this line:
`a.split('.').map(Number.parseInt)`.
Because parseInt takes two arguments (number and radix), map was giving it the part *and the index*.

The error went away after fixing the method to use only the part.

* Add ability to read config file from json integration

* Add rudimentary integration search to JSONAdaptor

* Create readRawConfig method to avoid data pruning

* Add localized config parsing to getAssets

* Convert getSampleData to use localized config

* Move localized reader logic to helper method

* Convert getSchemas to use new data retrieval

* Add localized config handling for getStatic

* Add basic validation test for JSON reader

* Add static validation to integration reader

* Add more tests for deepCheck on JSON catalog

* Add tests for json adaptor edge cases

* Add reserialization tests

* Add tests and remove redundant error checks for 90% coverage

* Fix lints in repository.test.ts

* Fix lints for integrations_builder.ts

* Update snapshots

* Revert "Update snapshots"

This reverts commit 62b238d.

* Use semver library for comparison

* Switch to upstream NDJson parser

* Add inline documentation for IntegrationPart

* Move deepCheck to utils

* Add further utility methods to utils

* Refactor repository tests to not rely on result.ok == false

---------

(cherry picked from commit 6bd872c)

Signed-off-by: Simeon Widdis <sawiddis@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
(cherry picked from commit 216aa92)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants