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

fix: hide custom ddev pull and ddev push commands from Amplitude, fixes #6128 #6152

Merged

Conversation

stasadev
Copy link
Member

@stasadev stasadev commented May 3, 2024

The Issue

How This PR Solves The Issue

Marks the command as custom, but only if the name is not in predefined provider list (like acquia, git, lagoon, etc.)

Manual Testing Instructions

Tested:

"event_properties": {
    "Arguments": null,
    "Called As": "",
    "Command Name": "custom-command",
    "Command Path": "ddev pull custom-command"
}

Automated Testing Overview

Related Issue Link(s)

Release/Deployment Notes

@github-actions github-actions bot added the bugfix label May 3, 2024
Copy link

github-actions bot commented May 3, 2024

@rfay
Copy link
Member

rfay commented May 3, 2024

This looks fine to me, thanks. Does need manual testing. DDEV_VERBOSE=true might be good enough, but probably step-debugging it would be adequate as well. We can just rename one of the existing ones like lagoon or whatever and use it and see what happens.

@stasadev
Copy link
Member Author

stasadev commented May 6, 2024

I tested what would be sent to Amplitude after my change:

ddev pull platform123

"event_properties": {
    "Arguments": null,
    "Called As": "platform123",
    "Command Name": "custom-command",
    "Command Path": "ddev pull custom-command"
}

Command Name and Command Path are hidden, but not Called As.

I think this is unintentional and should be fixed.

cmd.CalledAs() is a getter function that has access to a non-public attribute, and we can't override it here:

// Anonymize user defined custom commands.
cmdCopy := *cmd
argsCopy := args
if IsUserDefinedCustomCommand(&cmdCopy) {
cmdCopy.Use = "custom-command"
argsCopy = []string{}
}

I tried to add IsUserDefinedCustomCommand() here, where cmd.CalledAs() is added to Amplitude:

builder := ampli.Command.Builder().
Arguments(args).
CalledAs(cmd.CalledAs()).
CommandName(cmd.Name()).
CommandPath(cmd.CommandPath())

Like this:

import (
    cmd2 "github.com/ddev/ddev/cmd/ddev/cmd"
)

// Anonymize user defined custom commands.
calledAs := cmd.CalledAs()
if cmd2.IsUserDefinedCustomCommand(cmd) {
    calledAs = "custom-command"
}

builder := ampli.Command.Builder().
    Arguments(args).
    CalledAs(calledAs).
    CommandName(cmd.Name()).
    CommandPath(cmd.CommandPath())

But without success because of import cycle not allowed.

What is the best way to add a check for custom commands in amplitude.go?

@stasadev stasadev force-pushed the 20240504_stasadev_hide_custom_pull_and_push_commands branch from 7c461ba to d9f66cc Compare May 6, 2024 19:53
@stasadev
Copy link
Member Author

stasadev commented May 6, 2024

I found the solution (assign a new command instead of reusing), now it sends it as:

"event_properties": {
    "Arguments": null,
    "Called As": "",
    "Command Name": "custom-command",
    "Command Path": "ddev pull custom-command"
}

@stasadev stasadev marked this pull request as ready for review May 6, 2024 20:00
@stasadev stasadev requested a review from a team as a code owner May 6, 2024 20:00
Copy link
Member

@rfay rfay left a comment

Choose a reason for hiding this comment

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

This is working great, thanks for the excellent work.

image

I did note with surprise that every time autocompletion happens, it comes through as a command.

image

I'll open an issue to exclude __complete

@@ -125,6 +125,13 @@ ddev pull %s --skip-files -y`, subCommandName, subCommandName, subCommandName),
appPull(providerName, app, flags["skip-confirmation"], flags["skip-import"], flags["skip-db"], flags["skip-files"], environment)
},
}
// Mark custom command
Copy link
Member

Choose a reason for hiding this comment

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

Very small nit, not worth messing with.

Suggested change
// Mark custom command
// Mark custom provider

func IsBundledCustomProvider(provider string) bool {
paths := []string{
filepath.Join("dotddev_assets", "providers", provider) + ".yaml",
filepath.Join("dotddev_assets", "providers", provider) + ".yaml.example",
Copy link
Member

Choose a reason for hiding this comment

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

This approach is fine. In reality, we probably wouldn't want to show any args to rsync or localfile, but let's just let that be.

@rfay rfay merged commit 6264493 into ddev:master May 15, 2024
24 checks passed
@stasadev stasadev deleted the 20240504_stasadev_hide_custom_pull_and_push_commands branch May 16, 2024 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants