From e57139de0c9961bfd773fdd16b4c7976900db7a1 Mon Sep 17 00:00:00 2001 From: Pedro Ramos Date: Mon, 27 May 2024 21:05:44 +0200 Subject: [PATCH 1/3] Add env var to analytics config file's path --- src/base.ts | 2 +- src/commands/config/analytics.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/base.ts b/src/base.ts index d5d859b4001..3398df58c74 100644 --- a/src/base.ts +++ b/src/base.ts @@ -98,7 +98,7 @@ export default abstract class extends Command { async recorderFromEnv(prefix: string): Promise { let sink: Sink = new DiscardSink(); - const analyticsConfigFile = join(homedir(), '.asyncapi-analytics'); + const analyticsConfigFile = process.env.ASYNCAPI_METRICS_CONFIG_PATH || join(homedir(), '.asyncapi-analytics'); if (!existsSync(analyticsConfigFile)) { await writeFile(analyticsConfigFile, JSON.stringify({ analyticsEnabled: 'true', infoMessageShown: 'false', userID: uuidv4()}), { encoding: 'utf8' }); diff --git a/src/commands/config/analytics.ts b/src/commands/config/analytics.ts index b8cb1303fbf..62e93602fc2 100644 --- a/src/commands/config/analytics.ts +++ b/src/commands/config/analytics.ts @@ -18,7 +18,7 @@ export default class Analytics extends Command { async run() { const { flags } = await this.parse(Analytics); - const analyticsConfigFile = join(homedir(), '.asyncapi-analytics'); + const analyticsConfigFile = process.env.ASYNCAPI_METRICS_CONFIG_PATH || join(homedir(), '.asyncapi-analytics'); try { const analyticsConfigFileContent = JSON.parse(await readFile(resolve(analyticsConfigFile), { encoding: 'utf8' })); @@ -43,9 +43,11 @@ export default class Analytics extends Command { } } } catch (e: any) { + // TO DO + // Update config file location switch (e.code) { case 'ENOENT': - this.error(`Unable to access the analytics configuration file. We tried to access the ".asyncapi-analytics" file in your user's home directory ("${homedir()}") but the file could not be found.`); + this.error(`Unable to access the analytics configuration file. We tried to access the ".asyncapi-analytics" file in in the path "${analyticsConfigFile}" but the file could not be found.`); break; case 'EEXIST': this.error(`Unable to update the analytics configuration file. We tried to update your ".asyncapi-analytics" file in the path "${analyticsConfigFile}" but the file does not exist.`); From bc5e7754e512e5844371865e54e78d38cab8a2b5 Mon Sep 17 00:00:00 2001 From: Pedro Ramos Date: Mon, 27 May 2024 21:18:48 +0200 Subject: [PATCH 2/3] Remove comments --- src/commands/config/analytics.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/commands/config/analytics.ts b/src/commands/config/analytics.ts index 62e93602fc2..d3e74db19eb 100644 --- a/src/commands/config/analytics.ts +++ b/src/commands/config/analytics.ts @@ -43,8 +43,6 @@ export default class Analytics extends Command { } } } catch (e: any) { - // TO DO - // Update config file location switch (e.code) { case 'ENOENT': this.error(`Unable to access the analytics configuration file. We tried to access the ".asyncapi-analytics" file in in the path "${analyticsConfigFile}" but the file could not be found.`); From 4417d43a8a43b27849b36fdf62816ead6b8a2f73 Mon Sep 17 00:00:00 2001 From: Pedro Ramos Date: Mon, 3 Jun 2024 19:02:42 +0200 Subject: [PATCH 3/3] Update metrics_collection.md --- docs/metrics_collection.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/metrics_collection.md b/docs/metrics_collection.md index a27853f898b..3e89f6bddc6 100644 --- a/docs/metrics_collection.md +++ b/docs/metrics_collection.md @@ -39,6 +39,11 @@ We are making use of [New Relic API](https://docs.newrelic.com/docs/apis/intro-a Metrics won't be collected in CI environments, or when the "CI" env variable is set up to "true". +The analytics config file will be store by default at your home directory. In case you prefer to change the file path then you should set the `ASYNCAPI_METRICS_CONFIG_PATH` env var to any specific path value when running any command. For instance: +```` +ASYNCAPI_METRICS_CONFIG_PATH=/tmp/.asyncapi-analytics asyncapi config analytics --status +```` + ## How to disable tracking To disable tracking, please run the following command: `asyncapi config analytics --disable`