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

updated reqs and test #447

Conversation

unclebconnor
Copy link
Contributor

@unclebconnor unclebconnor commented Sep 25, 2019

The api.Monitor.update endpoint doesn't actually require query or type so removing restrictions from the clients and updating the docs (based on a customer request).

I updated the test in test_dogshell.py but wasn't able to get the test to run based on directions. Happy to test more thoroughly but could use some guidance.

@unclebconnor unclebconnor requested a review from a team as a code owner September 25, 2019 21:29
Copy link
Contributor

@zippolyte zippolyte left a comment

Choose a reason for hiding this comment

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

Regarding the dog shell tests, we can trigger them manually in the CI. Otherwise, you'd need to provide the credentials of an org that can be used for testing only (tests are destructive, muting all monitors and such) and running tox -e integration.
Though a few tests are currently broken, I'm working on fixing them at the moment. So as long as you test manually that one command update command, we'll be good to merge.

" depending on what type of monitor you are creating")
update_parser.add_argument('--type', help="type of the monitor, e.g. "
"'metric alert' 'service check'", default=None)
update_parser.add_argument('--query', help="query to notify on with syntax varying"
Copy link
Contributor

@zippolyte zippolyte Sep 26, 2019

Choose a reason for hiding this comment

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

Unfortunately, changing the type of the parameters from positional args to named args is a breaking change. Can we just add the defaults without changing the name ? I guess not, we have to make them named arguments if we want to make them optional... Not sure how best to deal with that honestly

Copy link
Contributor

Choose a reason for hiding this comment

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

I think a possible way forward is to:

  • Add nargs="?" to both type and query to make them optional.
  • Emit a deprecation warning if any of these two is set.
  • Add --type and --query optional arguments as well.
  • Raise an error if someone specifies both --type and the value for positional type. To make sure people use one or the other, but not both at the same time.

Does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. This solution seems ideal to me, thanks for the suggestions !
Do you think you can work on that @unclebconnor ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok sounds good. Happy to work on this. Thanks for the eyes!

Copy link
Contributor Author

@unclebconnor unclebconnor Oct 3, 2019

Choose a reason for hiding this comment

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

These updates are made. Working on tests next.

["monitor", "update", "--message", updated_message])

assert "id" in out, out
assert "message" in out, out
Copy link
Contributor

Choose a reason for hiding this comment

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

let's remove the , out part here. It will prevent pytest from doing introspection.

self.assertEquals(out["message"], updated_message)
#confirming no other changes but message
self.assertEquals(out['query'], query)
self.assertEquals(out['type_alert'], type_alert)
Copy link
Contributor

Choose a reason for hiding this comment

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

let's use plain assert like above.

@unclebconnor
Copy link
Contributor Author

unclebconnor commented Oct 3, 2019

Regarding the dog shell tests, we can trigger them manually in the CI. Otherwise, you'd need to provide the credentials of an org that can be used for testing only (tests are destructive, muting all monitors and such) and running tox -e integration.
Though a few tests are currently broken, I'm working on fixing them at the moment. So as long as you test manually that one command update command, we'll be good to merge.

@zippolyte I'm getting the following when running the tox command. Reading about this error online I'm seeing that it has to do with tox config. Is this known on our end at all? Happy to research more if not

COMP10192:datadogpy brian.connor$ tox -e integration
ERROR: unknown environment 'integration'

@zippolyte
Copy link
Contributor

zippolyte commented Oct 4, 2019

@unclebconnor
Yeah make sure you are based on the latest version of master. There has been a few changes made to the test suite for integration tests. On master the integration environment is there: https://github.com/DataDog/datadogpy/blob/master/tox.ini#L7
Then in order to run just the test you want, use tox -e integration-admin -- -k test_monitors (the monitors tests mutes and unmutes everything, that's why it's marked as admin, so that you don't accidentally run them with the rest of the suite)

You'll also have to address my comment about self.assertEquals then, because it will just fail now since we're not using unittest anymore.

@unclebconnor unclebconnor force-pushed the bcon/monitor-update-non-required-fields branch from 66a24ab to e711706 Compare October 4, 2019 20:35
@unclebconnor
Copy link
Contributor Author

unclebconnor commented Oct 4, 2019

Ok I got a hand with this and I think it should be good to go. Waiting for some tests to pass but test_monitors works locally at least

@zippolyte
Copy link
Contributor

/azp run Datadog.datadogpy.integration

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Comment on lines 168 to 175
if args.type:
to_update['type'] = args.type
msg = "[DEPRECATION] `type` is no longer required to `update` and may be omitted"
warnings.warn(msg, DeprecationWarning)
if args.query:
to_update['query'] = args.query
msg = "[DEPRECATION] `query` is no longer required to `update` and may be omitted"
warnings.warn(msg, DeprecationWarning)
Copy link
Contributor

Choose a reason for hiding this comment

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

Where do you use the new optional type and query arguments ? This is only for the deprecated positional ones. I think the parser will assign to the same variables, which is why your test works I assume.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah rats. It looks like I lost my updates here when I merged w/master and didn't notice. Will go back and fix. Used a different dest for the optional ones

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zippolyte added this back and tests passed locally. I didn't add anything to explicitly test this but there are tests that either positional or optional arguments and they're both passing

Copy link
Contributor

@zippolyte zippolyte left a comment

Choose a reason for hiding this comment

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

Nice we're almost there !
I have a few more comments regarding how we print the warnings, and there seem to be syntax issues in your tests.
Also, let's test for the type update. It can be done at the same time as the query, since I guess when you change the type your query probably changes as well.

if args.type:
if args.type_opt:
msg = '[WARNING] Duplicate arguments for `type`. Using optional value --type'
print(msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

For printing, let's use the print_err utility function that you can import from datadog.dogshell.common

def print_err(msg):
if is_p3k():
print(msg + '\n', file=sys.stderr)
else:
sys.stderr.write(msg + '\n')
, and use the format "WARNING: " for consistency with how we print other warnings, as in
print_err("WARNING: {}".format(warning))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is all done and tests adjusted accordingly

out = json.loads(out)
assert updated_message == out["message"]
assert query == out['query']
assert monitor_name == out ['name']
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert monitor_name == out ['name']
assert monitor_name == out['name']

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops! updated

out = json.loads(out)
assert updated_query in out["query"]
assert updated_message in out['message'] # updated_message updated in previous step
assert monitor_name in out ['name']
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assert monitor_name in out ['name']
assert monitor_name in out['name']

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@zippolyte
Copy link
Contributor

/azp run Datadog.datadogpy.integration

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@zippolyte zippolyte left a comment

Choose a reason for hiding this comment

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

Should be good to go after those two additional changes 🙂

@@ -7,10 +7,9 @@

# datadog
from datadog import api
from datadog.dogshell.common import report_errors, report_warnings
from datadog.dogshell.common import report_errors, report_warnings, print_err
import warnings
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove this import which is now unused and add back the blank line that's making flake8 tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated


out, err, return_code = self.dogshell(
["monitor", "update", monitor_id, "--query", updated_query]
["monitor", "update", monitor_id, "--type", updated_type, "--query", updated_query]
)

out = json.loads(out)
assert updated_query in out["query"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's also add an assert on the updated type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops yep sorry I overlooked this

@unclebconnor
Copy link
Contributor Author

Should be good to go after those two additional changes 🙂

Thanks for your patience stepping through the process here!

@zippolyte
Copy link
Contributor

/azp run DataDog.datadogpy.integration

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@unclebconnor unclebconnor merged commit ac14bda into DataDog:master Oct 11, 2019
@unclebconnor unclebconnor deleted the bcon/monitor-update-non-required-fields branch October 11, 2019 16:38
dabcoder pushed a commit to dabcoder/datadogpy that referenced this pull request Oct 25, 2019
* updated reqs and test

* typo

* added deprecation messages, unbroke change

* updated asserts in test

* updated tests and fixed linting errors

* re-added handling for query_opt and type_opt

* updated printing and related tests

* flake8 test and assert type

* added line for linter
dabcoder pushed a commit to dabcoder/datadogpy that referenced this pull request Nov 28, 2019
* updated reqs and test

* typo

* added deprecation messages, unbroke change

* updated asserts in test

* updated tests and fixed linting errors

* re-added handling for query_opt and type_opt

* updated printing and related tests

* flake8 test and assert type

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

Successfully merging this pull request may close these issues.

3 participants