-
Notifications
You must be signed in to change notification settings - Fork 306
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
updated reqs and test #447
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.
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.
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
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 think a possible way forward is to:
- Add
nargs="?"
to bothtype
andquery
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 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.
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 ?
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.
Ok sounds good. Happy to work on this. Thanks for the eyes!
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.
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.
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) |
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.
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.
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.
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.
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.
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
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.
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.
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
datadogpy/datadog/dogshell/common.py
Lines 11 to 16 in 9a463de
def print_err(msg): | |
if is_p3k(): | |
print(msg + '\n', file=sys.stderr) | |
else: | |
sys.stderr.write(msg + '\n') | |
"WARNING: "
for consistency with how we print other warnings, as in datadogpy/datadog/dogshell/common.py
Line 35 in 9a463de
print_err("WARNING: {}".format(warning)) |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert monitor_name == out ['name'] | |
assert monitor_name == out['name'] |
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.
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'] |
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.
assert monitor_name in out ['name'] | |
assert monitor_name in out['name'] |
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.
👍
/azp run Datadog.datadogpy.integration |
Azure Pipelines successfully started running 1 pipeline(s). |
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.
Should be good to go after those two additional changes 🙂
datadog/dogshell/monitor.py
Outdated
@@ -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 |
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.
Let's remove this import which is now unused and add back the blank line that's making flake8 tests
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.
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"] |
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.
Let's also add an assert on the updated 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.
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.update
endpoint doesn't actually requirequery
ortype
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.