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

Add a dogshell option to change Datadog site to call API #691

Merged
merged 4 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion datadog/dogshell/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def main():
"-v", "--version", help="Dog API version", action="version", version="%(prog)s {0}".format(__version__)
)

parser.add_argument(
"--site",
help="Datadog site to send data, us (datadoghq.com), eu (datadoghq.eu) or us3 (us3.datadoghq.com), default: us",
dest="site",
default=os.environ.get("DD_SITE", os.environ.get("DATADOG_HOST")),
Copy link
Contributor

Choose a reason for hiding this comment

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

Site and host have different semantic, I don't think we should use the same env var for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, I will change it to api_host

choices=["datadoghq.com", "us", "datadoghq.eu", "eu", "us3.datadoghq.com", "us3"],
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure we want support us and eu ? That could be confusing with other datacenters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought we can be aligned with https://github.com/DataDog/datadogpy/blob/master/datadog/dogshell/wrap.py#L289
What do you think? Should we remove us, eu, us3?

Copy link
Contributor

Choose a reason for hiding this comment

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

OK fair enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks I will leave it.

)

config = DogshellConfig()

# Set up subparsers for each service
Expand All @@ -93,7 +101,8 @@ def main():
ServiceLevelObjectiveClient.setup_parser(subparsers)

args = parser.parse_args()
config.load(args.config, args.api_key, args.app_key)

config.load(args.config, args.api_key, args.app_key, args.site)

# Initialize datadog.api package
initialize(**config)
Expand Down
10 changes: 9 additions & 1 deletion datadog/dogshell/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,16 @@ def report_warnings(res):


class DogshellConfig(IterableUserDict):
def load(self, config_file, api_key, app_key):
def load(self, config_file, api_key, app_key, site):
config = configparser.ConfigParser()

if site is not None:
if site in ("us" or "datadoghq.com"):
self["api_host"] = "https://datadoghq.com"
elif site in ("datadoghq.eu", "eu"):
self["api_host"] = "https://datadoghq.eu"
elif site in ("us3.datadoghq.com", "us3"):
self["api_host"] = "https://us3.datadoghq.com"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably raise an error if the value doesn't match.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Error is thrown by choices=["datadoghq.com", "us", "datadoghq.eu", "eu", "us3.datadoghq.com", "us3"]
Error message will be like
__init__.py: error: argument --api_host: invalid choice: 'us4' (choose from 'datadoghq.com', 'us', 'datadoghq.eu', 'eu', 'us3.datadoghq.com', 'us3')

Is it cool?


if api_key is not None and app_key is not None:
self["api_key"] = api_key
Expand Down