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

Multiple Import Metadata actions #1178

Open
wants to merge 13 commits into
base: mvp_demo
Choose a base branch
from

Conversation

shreyabiradar07
Copy link
Contributor

@shreyabiradar07 shreyabiradar07 commented Apr 23, 2024

This PR has following changes:

  • Delete metadata by datasourceName database functionality
  • Implementation of DELETE /dsmetadata API
    curl -X DELETE http://${URL}/dsmetadata -d @./input_datasource.json

Example input_datasource.json (same as that of import dsmetadata request body)

{
    "version":"v1.0",
    "datasource_name":"prometheus-1"
}

@shreyabiradar07 shreyabiradar07 self-assigned this Apr 23, 2024
@shreyabiradar07 shreyabiradar07 added local_monitoring kruize-local Tag for mentioning all the PR's and issues raised which covers the kruize local monitoring usecase labels Apr 23, 2024
@shreyabiradar07 shreyabiradar07 marked this pull request as ready for review April 23, 2024 12:28
@rbadagandi1 rbadagandi1 added this to the Kruize 0.0.22_rm Release milestone Apr 24, 2024
@rbadagandi1 rbadagandi1 removed the kruize-local Tag for mentioning all the PR's and issues raised which covers the kruize local monitoring usecase label Apr 24, 2024
@rbadagandi1 rbadagandi1 added kruize-local Tag for mentioning all the PR's and issues raised which covers the kruize local monitoring usecase and removed kruize-local Tag for mentioning all the PR's and issues raised which covers the kruize local monitoring usecase labels Apr 24, 2024
@shreyabiradar07
Copy link
Contributor Author

@msvinaykumar can you please review the PR

@msvinaykumar
Copy link
Contributor

@shreyabiradar07 can you start MD file describe above functionality

@@ -94,4 +94,6 @@ public interface ExperimentDAO {
// Load metadata
List<KruizeDSMetadataEntry> loadMetadata() throws Exception;

// Delete metadata
public ValidationOutputData deleteKruizeDSMetadataEntryByName(String dataSourceName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps you could name it something like "removeClusterMetadataByName" or

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have followed the similar naming convention as deleteKruizeExperimentEntryByName, please confirm if this still requires renaming.

@@ -94,4 +94,6 @@ public interface ExperimentDAO {
// Load metadata
List<KruizeDSMetadataEntry> loadMetadata() throws Exception;
Copy link
Contributor

Choose a reason for hiding this comment

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

loadClusterMetaData

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently there no usages of loadMetadata function as it fetches all the records from KruizeDSMetadataEntry table (in case when there are multiple datasources will retrieve all the container data not limiting to a specific cluster), hence will remove the unused functionality.

@shreyabiradar07
Copy link
Contributor Author

@shreyabiradar07 can you start MD file describe above functionality

Documented delete metadata functionality in KruizeLocalAPI.md as part of PR 1174

Copy link
Contributor

@msvinaykumar msvinaykumar left a comment

Choose a reason for hiding this comment

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

LGTM

@msvinaykumar
Copy link
Contributor

msvinaykumar commented Jun 4, 2024

UI Flow --> First get if no data then POST and get if still no data then give up (Display error if any)
also Refresh button should be avaible

curl -X post http://${URL}/dsmetadata -d @./input_datasource.json

For above request in backend
Check if data available in db
if yes delete and fetch again from cluster and save it db
if no fetch from cluster and save it db

curl -X post http://${URL}/dsmetadata -d @./input_datasource.json

For above request in backend
Check if data available in db
if yes fetch from cluster and save it db

curl -X get http://${URL}/dsmetadata?datasource_name="abc"
Check if db having data
if yes return data
if no 404 not found

UserWorflow
By default metatdata is prefetched using this URL (This happens as part of kruize pod startup) OR fetch button at UI
curl -X post http://${URL}/dsmetadata -d @./input_datasource.json
there after user will have get operation
curl -X get http://${URL}/dsmetadata?datasource_name="abc"
if user wants to refresh then this api is called
curl -X post http://${URL}/dsmetadata -d @./input_datasource.json

      when user click on cluster -> trigger 
                          curl -X get http://${URL}/dsmetadata?datasource_name="abc"  by default

No need of refresh flag

@msvinaykumar
Copy link
Contributor

{
"version":"v1.0",
"datasource_name":"prometheus-1"
}
should have option to provide cluster_name , namespace , workload , container_name

@msvinaykumar
Copy link
Contributor

@shreyabiradar07 please set up code walk through session

Copy link
Contributor

@msvinaykumar msvinaykumar left a comment

Choose a reason for hiding this comment

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

LGTM

}
}

new DataSourceManager().importMetadataFromDataSource(datasource);
Copy link
Contributor

Choose a reason for hiding this comment

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

As mentioned in the review, this can cause DB corruption if for any reason the import fails as we would have removed the DB content. Please reverse the order and add validation to the import results

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the code flow including validation of imported DataSourceMetadataInfo object


inputData = request.getReader().lines().collect(Collectors.joining());
if (null == inputData || inputData.isEmpty()) {
throw new Exception("Request input data cannot be null or empty");
Copy link
Contributor

Choose a reason for hiding this comment

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

Move all of the strings to string constants

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

DataSourceMetadataInfo dataSourceMetadata = new ExperimentDBService().loadMetadataFromDBByName(dataSourceName, "false");
if (null != dataSourceMetadata) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Move all of the code that handles the doPost to the relevant files under datasource

@@ -110,6 +110,10 @@ public void deleteMetadataFromDataSource(DataSourceInfo dataSource) {
*/
public void saveMetadataFromDataSourceToDB(DataSourceInfo dataSourceInfo) {
try {
if (null == dataSourceInfo) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@shreyabiradar07 - As discussed, please add the negative scenario to bring down the prometheus by scaling down the statefulset and deployment between multiple imports, and validate that the second call to import metadata fails with appropriate error message and list metadata returns the metadata from the DB. This can be added in a separate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Under Review
Development

Successfully merging this pull request may close these issues.

None yet

5 participants