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

Update datadog downtime module with datadog API v2 (#9080) #9098

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gmaOCR
Copy link

@gmaOCR gmaOCR commented Nov 3, 2024

SUMMARY

Global review to add the asked feature and match with the new version 2.29 of datadog API
Include "Fixes #9080 "
ISSUE TYPE

Feature Pull Request
Refactoring Pull Request

ADDITIONAL INFORMATION

Module req: python3.7+
Test for older version are skipped

@pilou-
@misc

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added WIP Work in progress feature This issue/PR relates to a feature request module module new_contributor Help guide this first time contributor plugins plugin (any type) tests tests unit tests/unit labels Nov 3, 2024
@gmaOCR gmaOCR marked this pull request as ready for review November 3, 2024 19:06
@ansibullbot ansibullbot removed the WIP Work in progress label Nov 3, 2024
@felixfontein felixfontein added the check-before-release PR will be looked at again shortly before release and merged if possible. label Nov 3, 2024
Copy link
Collaborator

@russoz russoz left a 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.

Comment on lines -10 to -11
__metaclass__ = type

Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment on lines +204 to +205
state=dict(required=False, choices=[
"present", "absent"], default="present"),
Copy link
Collaborator

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

Comment on lines +314 to +319
if ka != kb:
return False
for k in ka:
if not _equal_dicts(a[k], b[k], ignore_keys):
return False
return True
Copy link
Collaborator

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:

Suggested change
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)

Comment on lines +321 to +327
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
Copy link
Collaborator

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:

  1. 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 is dict rather than list. Providing for other types is redundant.
  2. The name of the function is _equal_dicts() - if we are comparing list and , the name is wrong

It seems like an unnecessary complication.


module.fail_json(msg="Failed to update downtime: %s" % (e,))
Copy link
Collaborator

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?

Comment on lines +151 to +162
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
Copy link
Collaborator

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.

Comment on lines 208 to +209
monitor_id=dict(required=False, type="int"),
monitor_identifier=dict(required=False, type="dict"),
Copy link
Collaborator

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.

@ansibullbot ansibullbot added the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Nov 3, 2024
@felixfontein felixfontein added the backport-10 Automatically create a backport for the stable-10 branch label Nov 4, 2024
Copy link
Collaborator

@felixfontein felixfontein left a 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
Copy link
Collaborator

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+
Copy link
Collaborator

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.

@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-10 Automatically create a backport for the stable-10 branch check-before-release PR will be looked at again shortly before release and merged if possible. feature This issue/PR relates to a feature request module module needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR new_contributor Help guide this first time contributor plugins plugin (any type) stale_ci CI is older than 7 days, rerun before merging tests tests unit tests/unit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for mute_first_recovery_notification to datadog_downtime module
4 participants