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

[CI-2937] CLI command logging #955

Merged
merged 3 commits into from
May 20, 2024
Merged

Conversation

tothszabi
Copy link
Contributor

Checklist

Version

Requires a MINOR version update

Context

We want to better understand how our users are using the CLI so we will be collecting what commands are executed and which flags are used.

Implementation

I have extended the existing logger with a new event.

At the moment the run command was initialising the tracker and it was the only user of it. This was not good because we need to log the command info much earlier. So I moved the tracker initialisation where the CLI execution starts. With this there was a new problem with how to share this tracker with the run command.

We are using the urfave cli package to parse and execute the tasks. This package has a Context (not the same as the Go Context one) struct which will trickle down to the commands. But you can only add strings to it. So the simplest solution seemed to put the tracker into a global variable and inject that into the execution flow.

@tothszabi tothszabi force-pushed the CI-2937-cli-command-logging branch 3 times, most recently from 8387743 to d7ee4ce Compare May 17, 2024 09:41
@@ -113,6 +124,41 @@ func Run() {
}
}

func commandExecutionInfo(args []string) (string, string, []string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have some tests for this logic? 👀

I see that it correctly filters out flag values (which could be sensitive), but we should also enforce this to prevent a future regression

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great tip. I have added tests for this part.

@tothszabi tothszabi force-pushed the CI-2937-cli-command-logging branch from d7ee4ce to 0743e37 Compare May 17, 2024 13:52
@tothszabi tothszabi merged commit 92d35bd into master May 20, 2024
5 checks passed
@tothszabi tothszabi deleted the CI-2937-cli-command-logging branch May 20, 2024 08:37
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.

2 participants