newrelic / newrelic-diagnostics-cli

NrDiag is a command line diagnostics tool for New Relic Products that was created by and is maintained by New Relic Global Technical Support
39 stars 19 forks source link

fix: Check for actual usage endpoint #190

Closed cade-conklin closed 1 year ago

cade-conklin commented 1 year ago

Issue

Usage endpoint defaults to localhost

Goals

Use correct usage endpoint

Implementation Details

Check directly for usage endpoint

How to Test

Run

daffinito commented 1 year ago

As I was reviewing this, I realized that the root issue is an order of operations issue. Previously (before the region check PR), config.UsageEndpoint was being set by the build script, so it is set before the main function even runs. This meant that when the global variable usage.usageEndpoint was being set to config.UsageEndpoint, config.UsageEndpoint was already set to the correct endpoint.

After the region PR, config.UsageEndpoint is now being set in config.ParseFlags(), so it is being set AFTER the global variable usage.usageEndpoint has already been set, causing usage.usageEndpoint to be set to nothing.

The solution is to just not use a global variable for usage.usageEndpoint as there's no reason to use one for it. I moved the variable creation into the usage.SendUsageData and it's all being set in the correct order again.