asyncapi/cli

[FEATURE] Improve storage of `.asyncapi-analytics` config file

peter-rr opened this issue ยท 7 comments

Why do we need this improvement?

Main ideas taken from @asyncapi/developer_experience_wg slack discussion:
cc @smoya @fmvilas

  1. We are handling the same analytics config file for integration tests and source code, which might lead to potential conflicts.

  2. Also we are storing that analytics config file at home directory, which is not a recommended practice.

How will this change help?

  1. We can avoid potential conflicts by not mixing testing data with real user data.

  2. Not polluting the user's home directory.

Screenshots

No response

How could it be implemented/designed?

  1. Handling different config files for testing and source code.

  2. The analytics config file should have a configurable path, and also be interchangeable between the different apps (like CLI, Studio), so we can know when the user is jumping from one app to another.

๐Ÿšง Breaking changes

No

๐Ÿ‘€ Have you checked for similar open issues?

  • I checked and didn't find a similar issue

๐Ÿข Have you read the Contributing Guidelines?

Are you willing to work on this issue?

No, someone else can work on it.

@Amzani How can I add this issue to the DX working group's Kanban?

@peter-rr it's automatically added

/gfi dx

Hey @Amzani, your message doesn't follow the requirements, you can try /help.

@fmvilas @smoya I'm trying to find out a good solution for what we talked about here, but I'm kind of stuck right now ๐Ÿค”

Regarding the usage of a configurable path for the analytics config file, should we interact with the user to get the file path desired and then use the value passed as a parameter? Could you provide any suggestion or example about this topic? Thanks, folks ๐Ÿ˜„

@fmvilas @smoya I'm trying to find out a good solution for what we talked about here, but I'm kind of stuck right now ๐Ÿค”

Regarding the usage of a configurable path for the analytics config file, should we interact with the user to get the file path desired and then use the value passed as a parameter? Could you provide any suggestion or example about this topic? Thanks, folks ๐Ÿ˜„

Let the path for the config file to be defined by an environment variable, with a default value in case is missing (the home directory is the default value).
Despite the env var name (up to you), line https://github.com/asyncapi/cli/blob/master/src/base.ts#L101 could be changed to:

const analyticsConfigFile = process.env.ASYNCAPI_METRICS_CONFIG_PATH || join(homedir(), '.asyncapi-analytics'); 

Then, users could change the path by just setting such an env var. i.e.ASYNCAPI_METRICS_CONFIG_PATH=/tmp/hello/.asyncapi-analytics

Regarding tests, you can do the same: set up that env var to a known and controlled config file path instead of using the one located in ~home.
However, as I recommended in the Slack thread you shared, the best way to work with tests is to create an interface for the storage of the config, and swap it in tests (from in file, to in memory).

@Amzani We can proceed to close this issue since #1451 and #1452 are already merged ๐Ÿš€