-
Notifications
You must be signed in to change notification settings - Fork 55
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
Keep env vars consistent #1197
base: master
Are you sure you want to change the base?
Keep env vars consistent #1197
Conversation
Datadog ReportBranch report: ✅ 0 Failed, 1972 Passed, 0 Skipped, 2m 18.08s Total duration (37.75s time saved) |
Co-authored-by: Corentin Girard <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces a tiny regression for mobile rum upload commands since we can either get the site from env variables or a configuration file.
More importantly it introduces different behaviours for different env variables.
@@ -132,7 +133,6 @@ export class UploadCommand extends Command { | |||
this.config, | |||
{ | |||
apiKey: process.env.DATADOG_API_KEY, | |||
datadogSite: process.env.DATADOG_SITE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a small regression in the case where the site is both specified in the environment and the datadog-ci.json
file with different values.
Before the order of priority used to be: env > config file > default value ('datadoghq.com')
Now since the site from env is put in the default value it will just be: config file > env.
It's only a tiny case but that also introduces a different logic for api key and site variables, which can make debugging harder.
I would suggest the following change here (we can either keep or remove the change above):
datadogSite: process.env.DATADOG_SITE, | |
datadogSite: process.env.DATADOG_SITE || process.env.DD_SITE, |
@@ -139,7 +140,6 @@ export class UploadCommand extends Command { | |||
this.config, | |||
{ | |||
apiKey: process.env.DATADOG_API_KEY, | |||
datadogSite: process.env.DATADOG_SITE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a small regression in the case where the site is both specified in the environment and the datadog-ci.json
file with different values.
Before the order of priority used to be: env > config file > default value ('datadoghq.com')
Now since the site from env is put in the default value it will just be: config file > env.
It's only a tiny case but that also introduces a different logic for api key and site variables, which can make debugging harder.
I would suggest the following change here (we can either keep or remove the change above):
datadogSite: process.env.DATADOG_SITE, | |
datadogSite: process.env.DATADOG_SITE || process.env.DD_SITE, |
@@ -77,7 +78,6 @@ export class UploadCommand extends Command { | |||
this.config, | |||
{ | |||
apiKey: process.env.DATADOG_API_KEY, | |||
datadogSite: process.env.DATADOG_SITE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a small regression in the case where the site is both specified in the environment and the datadog-ci.json
file with different values.
Before the order of priority used to be: env > config file > default value ('datadoghq.com')
Now since the site from env is put in the default value it will just be: config file > env.
It's only a tiny case but that also introduces a different logic for api key and site variables, which can make debugging harder.
I would suggest the following change here (we can either keep or remove the change above):
datadogSite: process.env.DATADOG_SITE, | |
datadogSite: process.env.DATADOG_SITE || process.env.DD_SITE, |
@@ -216,7 +217,7 @@ export class UploadCommand extends Command { | |||
private getApiRequestBuilder(apiKey: string): RequestBuilder { | |||
return getRequestBuilder({ | |||
apiKey, | |||
baseUrl: 'https://' + apiHost, | |||
baseUrl: `https://api.${getDatadogSite()}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Small suggestion for consistency
baseUrl: `https://api.${getDatadogSite()}`, | |
baseUrl: `https://api.${this.config.datadogSite}`, |
Could you also update the line 225 below to use this.config.datadogSite
instead ? 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistency nit, could we update src/commands/sarif/utils.ts
to use this util?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR looks good
What and why?
Currently
datadog-ci
currently looks between two variable for the datadog site.DATADOG_SITE
andDD_SITE
except it doesn't always look atDD_SITE
for some commands.This can be frustrating especially where most documentation states to use
DD_SITE
which is heavily documented on the serverless documentation.This PR is an attempt to be consistent in configuring the site so no matter which variable is used it will work across every command.
How?
I have made modifications to the helper api module that implements a new exported constant function called
getDatadogSite
which check bothDATADOG_SITE
andDD_SITE
.I also ensured that this order is kept if a customer preferred
DATADOG_SITE
that would be the first variable used.However If neither environment variables are set then the default shall be
DATADOG_SITE_US1
which isdatadoghq.com
.I have also made updates to the commands to use this new export whereas before it would try to read either
DATADOG_SITE
orDD_SITE
and sometimes both.Review checklist
Because this make a change across all commands the current tests will validate that it is working properly.