-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Update datadog downtime module with datadog API v2 (#9080) #9098
base: main
Are you sure you want to change the base?
Conversation
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.
hi @gmaOCR,
Thank you for the contribution! Please add a changelog fragment.
Also, this PR needs some TLC. See comments.
__metaclass__ = type | ||
|
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 should be kept. See https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html#creating-a-module
state=dict(required=False, choices=[ | ||
"present", "absent"], default="present"), |
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.
I would recommend removing these formatting changes and submitting them on a separate PR. It takes longer for us to analyse the request as we need to verify for each block of lines changed whether it was just reformatting or new logic.
And the max length for lines in this code is meant to be 160 (sanity tests will complain if past that).
if ka != kb: | ||
return False | ||
for k in ka: | ||
if not _equal_dicts(a[k], b[k], ignore_keys): | ||
return False | ||
return True |
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.
Woldn't it be easier to just change it to:
if ka != kb: | |
return False | |
for k in ka: | |
if not _equal_dicts(a[k], b[k], ignore_keys): | |
return False | |
return True | |
return ka == kb and all(_equal_dicts(a[k], b[k], ignore_keys) for k in ka) |
elif isinstance(a, list) and isinstance(b, list): | ||
if len(a) != len(b): | ||
return False | ||
return all(_equal_dicts(x, y, ignore_keys) for x, y in zip(a, b)) | ||
|
||
else: | ||
return a == b |
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.
Not sure about this one:
- In the entire module, it seems
_equal_dicts()
is called from only one place (other than the recursion) in line 333 and that code seems to ensure the data type isdict
rather thanlist
. Providing for other types is redundant. - The name of the function is
_equal_dicts()
- if we are comparinglist
and , the name is wrong
It seems like an unnecessary complication.
|
||
module.fail_json(msg="Failed to update downtime: %s" % (e,)) |
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.
Why moving from .format()
to %
formatting?
monitor_id: null | ||
monitor_tags: | ||
- "foo:bar" | ||
parent_id: null | ||
recurrence: null | ||
scope: | ||
- "test" | ||
start: 1607015009 | ||
timezone: "UTC" | ||
updater_id: null | ||
monitor_identifier: | ||
monitor_id: 12345 |
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.
Lines 151 and 161-162 seem to be redundant. Will monitor_identifier
bring anything else other than monitor_id
? If not, then maybe we should keep monitor_id
as top level and not add ambiguity.
monitor_id=dict(required=False, type="int"), | ||
monitor_identifier=dict(required=False, type="dict"), |
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.
Again, if monitor_identifier
only brings the information monitor_id
, then I see no point in adding that parameter (as we already have monitor_id
).
As a matter of fact, it seems this new parameter is never used. When building the data payload for the API, it uses monitor_id
directly.
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.
Thanks for your contribution!
Please note that changes to a module must be backwards compatible. Existing (successful) uses of the module must continue to work, otherwise a change will not get merged.
I know next to nothing on datadog, like whether you can have an older on-prem version or whether there's only the SaaS option; and which client versions are still supported by versions of the software that are running (usually easier to answer if there's no on-prem solution).
If the current module can still be used with an older version of the client on Python 3.6, then the module needs to keep supporting that. To drop support for something, it needs to be deprecated first for a certain amount of time (roughly ~6 months+).
elements: str | ||
- A scope to which the downtime applies. | ||
- For example, 'host:app2' or 'env:staging' | ||
type: str |
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.
Changing the type from list of strings to string is a breaking change that prevents this PR from being merged.
author: | ||
- Datadog (@Datadog) | ||
requirements: | ||
- datadog-api-client | ||
- Python 3.6+ | ||
- Python 3.7+ |
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 is also a breaking change.
SUMMARY
Global review to add the asked feature and match with the new version 2.29 of datadog API
Include "Fixes #9080 "
ISSUE TYPE
ADDITIONAL INFORMATION
Module req: python3.7+
Test for older version are skipped
@pilou-
@misc