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

Add list and delete commands in policy recommendation CLI #56

Merged
merged 2 commits into from
Jul 28, 2022

Conversation

dreamtalen
Copy link
Contributor

Fix #49

Signed-off-by: Yongming Ding dyongming@vmware.com

Copy link
Contributor

@heanlan heanlan left a comment

Choose a reason for hiding this comment

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

LGTM

test/e2e/policyrecommendation_test.go Outdated Show resolved Hide resolved
pkg/theia/commands/policy_recommendation_delete.go Outdated Show resolved Hide resolved
pkg/theia/commands/policy_recommendation_list.go Outdated Show resolved Hide resolved
Comment on lines 156 to 161
policyRecommendationListCmd.Flags().Bool(
"use-cluster-ip",
false,
`Enable this option will use Service ClusterIP instead of port forwarding when connecting to the ClickHouse service.
It can only be used when running theia in cluster.`,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure whether it would be better to put this into global flags, as I think up to now all commands requires this flag.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think both clickhouse-endpoint and use-cluster-ip might be added to glabal flags?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Yanjun and Yuntang, yes there are some duplicates here, but status command uses use-cluster-ip only and is used for Spark Monitoring Service instead of ClickHouse Service in other commands.
Ultimately, I think the connection to Spark Monitoring Service and ClickHouse Service should be handled by the middle layer app theia manager. We could remove these flags then imo.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think for ClickHouse service, we also need these two flags in order to setup clickhouse connection? Currently, I add these two flags when using theia clickhouse status in PR #59

Copy link
Contributor Author

@dreamtalen dreamtalen Jun 24, 2022

Choose a reason for hiding this comment

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

For our theia pr status command, we're fetching status from k8s api server and spark monitoring service, that's why it doesn't need to connect with clickhouse for now.

But I also realize that we could improve the status command to let it can check completed jobs inside clickhouse only. In that case, all commands needs connection with clickhouse, I plan to create a separate PR for this improvement of status command first.

Comment on lines 159 to 160
The `theia policy-recommendation delete` command is used to delete a policy
recommendation job. To delete the policy recommendation job created above, run:
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice there is a rare case that if users try to delete a job before the driver pod is created, the job may still keep running till completion. And users will receive a message saying the job is successfully deleted. Not sure if we should deal with this case by returning another message or doc it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Yanjun, I have seen this corner case too during e2e test. In that case, the sparkapplication cr has been deleted successfully but the deriver/exec pods will still be created later, maybe I should create an issue in the spark operator repo to hear their solutions.

@yanjunz97
Copy link
Contributor

Not introduced by this PR, I just recall previously there is a discussion on replacing the empty state string when we get a NewState by running theia pr status xxx. Maybe we can fix it here or in a new PR?

@dreamtalen
Copy link
Contributor Author

Not introduced by this PR, I just recall previously there is a discussion on replacing the empty state string when we get a NewState by running theia pr status xxx. Maybe we can fix it here or in a new PR?

No problem, I will take care of it.

@dreamtalen dreamtalen force-pushed the pr-ls-del branch 3 times, most recently from a4220e6 to 9fe60a8 Compare June 27, 2022 20:16
Signed-off-by: Yongming Ding <dyongming@vmware.com>
@dreamtalen dreamtalen force-pushed the pr-ls-del branch 2 times, most recently from 11671a6 to 5bb4129 Compare June 29, 2022 17:01
docs/networkpolicy-recommendation.md Outdated Show resolved Hide resolved
docs/networkpolicy-recommendation.md Outdated Show resolved Hide resolved
Copy link
Contributor

@ziyouw ziyouw left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@dreamtalen
Copy link
Contributor Author

/theia-test-e2e

@@ -36,17 +38,21 @@ CLI. `theia` is the command-line tool which provides access to Theia network
flow visibility capabilities. To get more information about `theia`, please
refer to its [user guide](theia-cli.md).

There are 3 `theia` commands for the NetworkPolicy Recommendation feature:
There are 5 `theia` commands for the NetworkPolicy Recommendation feature:
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it's easier if we stop numbering them...
Something like
The following theia commands for .... are available

}
_, err = uuid.Parse(recoID)
if err != nil {
return fmt.Errorf("failed to decode input id %s into a UUID, err: %v", recoID, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider: "Input id ... does not seem a valid uuid, parsing error: ..."

if endpoint != "" {
_, err := url.ParseRequestURI(endpoint)
if err != nil {
return fmt.Errorf("failed to decode input endpoint %s into a url, err: %v", endpoint, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

(as above)
Consider: "Input endpoint ... does not seem a valid URL, parsing error: ...."

if endpoint != "" {
_, err := url.ParseRequestURI(endpoint)
if err != nil {
return fmt.Errorf("failed to decode input endpoint %s into a url, err: %v", endpoint, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as above about endpoint parsing (not sure if we can have some utility functions to avoid code duplication for parsing parameters which are used by multiple commands)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, add two utility functions for parsing ID and endpoint.

}

sparkApplicationTable := [][]string{
{"CreateTime", "CompleteTime", "ID", "Status"},
Copy link
Contributor

Choose a reason for hiding this comment

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

consider using "CompletionTime" instead of "CompleteTime"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, to be consistent, I'm changing to use CreationTime and CompletionTime.

if err != nil {
return err
}
query := "ALTER TABLE recommendations DELETE WHERE id = (?);"
Copy link
Contributor

Choose a reason for hiding this comment

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

is it a clickhouse peculiarity that we need to use ALTER TABLE for deleting records?
Does DELETE FROM

WHERE not work for Clickhouse?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, Clickhouse doesn't have Update/Delete commands like Mysql database, reference doc: https://clickhouse.com/docs/en/sql-reference/statements/alter/delete/

Signed-off-by: Yongming Ding <dyongming@vmware.com>
@dreamtalen
Copy link
Contributor Author

/theia-test-e2e

@dreamtalen dreamtalen merged commit 0e0c7c6 into antrea-io:main Jul 28, 2022
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.

List and delete policy recommendation jobs
7 participants