Conversation
zippolyte
left a comment
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I think a possible way forward is to:
- Add
nargs="?"to bothtypeandqueryto make them optional. - Emit a deprecation warning if any of these two is set.
- Add
--typeand--queryoptional arguments as well. - Raise an error if someone specifies both
--typeand the value for positionaltype. To make sure people use one or the other, but not both at the same time.
Does that make sense?
There was a problem hiding this comment.
Makes sense. This solution seems ideal to me, thanks for the suggestions !
Do you think you can work on that @unclebconnor ?
There was a problem hiding this comment.
Ok sounds good. Happy to work on this. Thanks for the eyes!
There was a problem hiding this comment.
These updates are made. Working on tests next.
| ["monitor", "update", "--message", updated_message]) | ||
|
|
||
| assert "id" in out, out | ||
| assert "message" in out, out |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
let's use plain assert like above.
@zippolyte I'm getting the following when running the |
|
@unclebconnor You'll also have to address my comment about |
66a24ab to
e711706
Compare
|
Ok I got a hand with this and I think it should be good to go. Waiting for some tests to pass but |
|
/azp run Datadog.datadogpy.integration |
|
Azure Pipelines successfully started running 1 pipeline(s). |
datadog/dogshell/monitor.py
Outdated
| 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
@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
zippolyte
left a comment
There was a problem hiding this comment.
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.
datadog/dogshell/monitor.py
Outdated
| if args.type: | ||
| if args.type_opt: | ||
| msg = '[WARNING] Duplicate arguments for `type`. Using optional value --type' | ||
| print(msg) |
There was a problem hiding this comment.
For printing, let's use the print_err utility function that you can import from datadog.dogshell.common
datadogpy/datadog/dogshell/common.py
Lines 11 to 16 in 9a463de
"WARNING: " for consistency with how we print other warnings, as in datadogpy/datadog/dogshell/common.py
Line 35 in 9a463de
There was a problem hiding this comment.
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'] |
There was a problem hiding this comment.
| assert monitor_name == out ['name'] | |
| assert monitor_name == out['name'] |
| 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'] |
There was a problem hiding this comment.
| assert monitor_name in out ['name'] | |
| assert monitor_name in out['name'] |
|
/azp run Datadog.datadogpy.integration |
|
Azure Pipelines successfully started running 1 pipeline(s). |
zippolyte
left a comment
There was a problem hiding this comment.
Should be good to go after those two additional changes 🙂
datadog/dogshell/monitor.py
Outdated
| 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 |
There was a problem hiding this comment.
Let's remove this import which is now unused and add back the blank line that's making flake8 tests
| ) | ||
|
|
||
| out = json.loads(out) | ||
| assert updated_query in out["query"] |
There was a problem hiding this comment.
Let's also add an assert on the updated type
There was a problem hiding this comment.
oops yep sorry I overlooked this
Thanks for your patience stepping through the process here! |
|
/azp run DataDog.datadogpy.integration |
|
Azure Pipelines successfully started running 1 pipeline(s). |
* 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
* 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
The
api.Monitor.updateendpoint doesn't actually requirequeryortypeso removing restrictions from the clients and updating the docs (based on a customer request).I updated the test in
test_dogshell.pybut wasn't able to get the test to run based on directions. Happy to test more thoroughly but could use some guidance.