-
Notifications
You must be signed in to change notification settings - Fork 3
158-simplify-cloudwatch-to-graphite-app-remove-leadbutt-dependency #14
158-simplify-cloudwatch-to-graphite-app-remove-leadbutt-dependency #14
Conversation
9fcec3a
to
e03ef5f
Compare
5e340fd
to
42d6911
Compare
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 work on this - just a few minor tweaks suggested.
README.md
Outdated
@@ -3,7 +3,8 @@ Digital Marketplace Cloudwatch to Graphite | |||
|
|||
## Purpose | |||
|
|||
Ships Cloudwatch metrics to Hosted Graphite using https://github.com/crccheck/cloudwatch-to-graphite. | |||
Ships Cloudwatch metrics to Hosted Graphite. | |||
Heavily draws on the work of https://github.com/crccheck/cloudwatch-to-graphite |
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.
Can we be more specific and say which bits we have been 'inspired by'?
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.
Done 👍
@retry(wait_fixed=60000, retry_on_result=lambda res: res is None) | ||
def call_leadbutt(): | ||
def create_hostedgraphite_base_metrics(config): | ||
"""Take a metric entry from the config format it into a base metric used to initialise the metric on hostedgraphite. |
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.
Could we simplify this to """Initialise each base metric in the config with a timestamp"""
?
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.
Almost, but we're also initialising it with a base number.
They come out like:
cloudwatch.request_time_buckets.preview.antivirus-api.request_time_bucket_0.sum 0.0 1537113600
{metric_name} {base_value} {timestamp}
Setting a starting point for the metric.
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 - Initialise each base metric in the config with a timestamp and base number
then? 😸 The current docstring is a bit hard to read.
|
||
|
||
def get_metric_from_cloudwatch(client, metric): | ||
"""Call the client once for th supplied metric.""" |
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.
Typo th
?
tests/test_app.py
Outdated
def setup_method(self): | ||
# Mock out boto3 cloudwatch client | ||
self.client = boto3.client('cloudwatch', region_name="eu-west-1") | ||
stubber = Stubber(self.client) |
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.
Interesting! Is this a better option than moto
?
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 so in so much as it prevents another dependency and should be supported for the lifetime of the boto3
lib. Pretty nifty, but it hasn't been around for that long. I expect the dependency in utils was added before this existed.
|
||
# Mock out send_to_hostedgraphite method | ||
self.send_to_hostedgraphite_mock = mock.patch('app.send_to_hostedgraphite') | ||
self.send_to_hostedgraphite_mock.start() |
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 we have an equivalent .stop()
in a teardown_method()
?
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.
Good shout 👍 Done
c6f2d27
to
dd64f14
Compare
README.md
Outdated
@@ -3,9 +3,10 @@ Digital Marketplace Cloudwatch to Graphite | |||
|
|||
## Purpose | |||
|
|||
Ships Cloudwatch metrics to Hosted Graphite using https://github.com/crccheck/cloudwatch-to-graphite. | |||
Ships Cloudwatch metrics to Hosted Graphite. | |||
Heavily on the work of https://github.com/crccheck/cloudwatch-to-graphite and the `leadbutt` script. Particularly config parsing to define metrics. |
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.
👍 (Though I think it's now missing a word: Heavily based
?)
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.
👍
dd64f14
to
2c075f3
Compare
Refactor/ simplification of the app: * Remove `pipe-watchdog.py` entirely * We're no longer using pipes to direct the output. An error should be output to the cloudwatch error logs on failure `cf logs --recent digitalmarketplace-cloudwatch-to-graphite-preview` * Remove this from the run command in `manifest.yml.example` * Add `flake8` dependency and `.flake8` file in line with GDS recommendations * Activate travis service on repo to check Flake8 rules and requirements files * Add `.travis.yml` * Add `Makefile` with shortcuts for running requirements freeze and flake8 * Update `README.md` * Change requirements handling * Add `requirements-app.txt` * Ensure `requirements.txt` contains full pinned requirements * Add `flake8` requirement for devs * Rewrite `app.py` * Add function descriptions to all functions * Remove dependency on `leadbutt`, `signal` and `subprocess` * Use `boto3` instead of `leadbutt`s `boto` (https://github.com/crccheck/cloudwatch-to-graphite/blob/master/leadbutt.py#L25) * Remove `get_timestamp` method. The same can be achieved with `time.time` * `logger.warn` is deprecated, use `logger.warning` instead * Bring string formatting in line with rest of strings in file * Rename `initialize_metrics ` to `create_hostedgraphite_base_metrics` for better description * Remove `call_leadbutt` function and replace with code calling aws ourselves. Extrapolated from (https://github.com/crccheck/cloudwatch-to-graphite/blob/master/leadbutt.py) * Change `loglevel` to `INFO` this is all that is required now we're not piping output * Move retry decorator on to wrapper method in `if __name__` block * Update `config.yaml.j2` template * `Dimensions` default = `{}` to avoid type manipulations * Remove `Auth` section from config. This can be hard coded until we have any need to specify it as a config variable * Remove `Options.Count` again, this can be hard coded. It's only used in one place and we've never needed to change it Extrapolate code out of leadbutt This code drops leadbutts retry functionality. Boto3 has the capacity to retry failed attempts. We should prefer this.
As per rholder/retrying#79 retrying is dead. Tenaciy is a community maintained fork. This also fixes a problem with retry swallowing exceptions.
2c075f3
to
20acba6
Compare
Refactor/ simplification of the app:
Remove
pipe-watchdog.py
entirelycf logs --recent digitalmarketplace-cloudwatch-to-graphite-preview
manifest.yml.example
Add
flake8
dependency and.flake8
file in line with GDS recommendationsActivate travis service on repo to check Flake8 rules and requirements files
.travis.yml
Add
Makefile
with shortcuts for running requirements freeze and flake8Update
README.md
Change requirements handling
requirements-app.txt
requirements.txt
contains full pinned requirementsflake8
requirement for devsRewrite
app.py
leadbutt
,signal
andsubprocess
boto3
instead ofleadbutt
sboto
(https://github.com/crccheck/cloudwatch-to-graphite/blob/master/leadbutt.py#L25)get_timestamp
method. The same can be achieved withtime.time
logger.warn
is deprecated, uselogger.warning
insteadinitialize_metrics
tocreate_hostedgraphite_base_metrics
for better descriptioncall_leadbutt
function and replace with code calling aws ourselves. Extrapolated from (https://github.com/crccheck/cloudwatch-to-graphite/blob/master/leadbutt.py)loglevel
toINFO
this is all that is required now we're not piping outputif __name__
blockUpdate
config.yaml.j2
templateDimensions
default ={}
to avoid type manipulationsAuth
section from config. This can be hard coded until we have any need to specify it as a config variableOptions.Count
again, this can be hard coded. It's only used in one place and we've never needed to change itReplace
retrying
withtenacity
retrying
is stale.tenacity
is a community maintained fork. ([Reminder] The project is nearly obsolete rholder/retrying#79)## TL:DR;
Extrapolate code out of leadbutt
This code drops leadbutts retry functionality. Boto3 has the capacity to retry failed attempts. We should prefer this.