Skip to content

feat: add initial metric publisher - #47

Merged
tobywf merged 12 commits into
aws-cloudformation:masterfrom
wulfmann:metric
Nov 22, 2019
Merged

tobywf merged 12 commits into
aws-cloudformation:masterfrom
wulfmann:metric

Conversation

@wulfmann

Copy link
Copy Markdown
Contributor

Issue #, if available:

#22

Description of changes:

Adds an initial metrics publisher

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@wulfmann

Copy link
Copy Markdown
Contributor Author

Let me know if you'd like to go a different direction with this. It is in line with the java and go plugins.

@rjlohan
rjlohan requested review from jaymccon and tobywf November 20, 2019 04:30
@rjlohan rjlohan added the enhancement New feature or request label Nov 20, 2019
@rjlohan

rjlohan commented Nov 20, 2019

Copy link
Copy Markdown

Thanks for this contribution! Just a few test errors in the build. You can reproduce the test failures locally by running;

pytest  
    --cov-report=term \ 
    --cov-report=html \ 
    --cov="rpdk.python" \ 
    --cov="cloudformation_cli_python_lib" \
    "tests/"

Once those are passing we can look at merging this in.

@wulfmann

Copy link
Copy Markdown
Contributor Author

Yea I forgot to install the precommit. I’m working through the errors now and I’ll circle back when I get them fixed.

Thanks!

@wulfmann

Copy link
Copy Markdown
Contributor Author

@rjlohan i've pushed updates here and the tests should pass now. I updated the .gitignore as it was disallowing new tests being added, and i added a test for the metric publisher.

Let me know if you like this approach for the publisher. I haven't added in any of the calls to actual handler yet, this is just the class. If we like this direction then i can add the calls into the actual handler.

@tobywf

tobywf commented Nov 20, 2019

Copy link
Copy Markdown
Contributor

Hey, thanks for the PR, it's nice and clean! We're working pretty hard getting some more stuff ready and wanted to get the Python stuff out there to let people know we're working on it and it's a priority. Apologies if it takes me a bit to get to this!

@wulfmann

Copy link
Copy Markdown
Contributor Author

@tobywf take your time no worries!

@jaymccon

Copy link
Copy Markdown
Contributor

looks good 😄 Is the intent to wire this up to Resource.__call__ in a future pr ?

@wulfmann

Copy link
Copy Markdown
Contributor Author

@jaymccon that was my thinking yes. I originally had it on this pr, but removed it as it changed a lot of function signatures in the other tests. I think it'll be a quicker pr in that case.

Comment thread src/cloudformation_cli_python_lib/metrics.py Outdated

@tobywf tobywf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome work. Great adaptation of the Java one. I'm not super familiar with CloudWatch, but the boto docs indicate some of the types don't quite match, so maybe we can work on tightening that part up. Happy to do some investigation myself if you need it.

Comment thread src/cloudformation_cli_python_lib/metrics.py Outdated
Comment thread src/cloudformation_cli_python_lib/metrics.py Outdated
Comment thread src/cloudformation_cli_python_lib/metrics.py Outdated
Comment thread tests/lib/metrics_test.py Outdated
Comment thread src/cloudformation_cli_python_lib/metrics.py Outdated
@wulfmann

Copy link
Copy Markdown
Contributor Author

I could use some feedback on the first test that should make sure that an exception during the put_metric_data call is logged. I attempted to mock the LOG variable for awhile and don’t have a ton of luck. Do you see anything obvious that would make that easy to check? Currently the test does nothing. That’s the last main TODO here.

@jaymccon

Copy link
Copy Markdown
Contributor

I attempted to mock the LOG variable for awhile and don’t have a ton of luck.

patching LOG should work, something like:

@patch("cloudformation_cli_python_lib.metrics.LOG", autospec=True)
def test_put_metric_catches_error(mock_log):
    ...
    mock_log.error.assert_called_once()

@wulfmann

Copy link
Copy Markdown
Contributor Author

I had tried that and don't know what I was doing wrong, but it works now. This PR should be up to date now with requested changes.

Comment thread tests/lib/metrics_test.py Outdated

@tobywf tobywf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is great. Currently on-call, so a bit short on time to test it fully. Let's merge it and iterate! 🚢

@tobywf
tobywf merged commit 9eda207 into aws-cloudformation:master Nov 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants