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

Keep env vars consistent #1197

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Keep env vars consistent #1197

wants to merge 12 commits into from

Conversation

TophrC-dd
Copy link

@TophrC-dd TophrC-dd commented Feb 15, 2024

What and why?

Currently datadog-ci currently looks between two variable for the datadog site.
DATADOG_SITE and DD_SITE except it doesn't always look at DD_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 both DATADOG_SITE and DD_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 is datadoghq.com.

I have also made updates to the commands to use this new export whereas before it would try to read either DATADOG_SITE or DD_SITE and sometimes both.

Review checklist

Because this make a change across all commands the current tests will validate that it is working properly.

  • Feature or bugfix MUST have appropriate tests (unit, integration)

@TophrC-dd TophrC-dd requested review from a team as code owners February 15, 2024 19:13
src/helpers/api.ts Outdated Show resolved Hide resolved
@datadog-datadog-prod-us1
Copy link

datadog-datadog-prod-us1 bot commented Feb 16, 2024

Datadog Report

Branch report: keep-envvars-consistent
Commit report: 1524fb2
Test service: datadog-ci-tests

✅ 0 Failed, 1972 Passed, 0 Skipped, 2m 18.08s Total duration (37.75s time saved)

src/commands/dora/api.ts Outdated Show resolved Hide resolved
src/commands/gate/utils.ts Outdated Show resolved Hide resolved
src/helpers/api.ts Outdated Show resolved Hide resolved
@Drarig29 Drarig29 changed the title Keep envvars consistent Keep env vars consistent Feb 16, 2024
@TophrC-dd TophrC-dd requested a review from a team as a code owner February 16, 2024 16:28
@TophrC-dd TophrC-dd requested a review from dastrong February 16, 2024 16:28
src/commands/git-metadata/upload.ts Outdated Show resolved Hide resolved
src/helpers/api.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@Drarig29 Drarig29 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@louiszawadzki louiszawadzki left a 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,
Copy link
Contributor

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):

Suggested change
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,
Copy link
Contributor

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):

Suggested change
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,
Copy link
Contributor

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):

Suggested change
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()}`,
Copy link
Contributor

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

Suggested change
baseUrl: `https://api.${getDatadogSite()}`,
baseUrl: `https://api.${this.config.datadogSite}`,

Could you also update the line 225 below to use this.config.datadogSite instead ? 🙏

Copy link
Contributor

@dastrong dastrong left a 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?

Copy link
Member

@BenoitZugmeyer BenoitZugmeyer left a comment

Choose a reason for hiding this comment

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

PR looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants