-
-
Notifications
You must be signed in to change notification settings - Fork 745
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
ST2 Metrics Collection #4004
ST2 Metrics Collection #4004
Changes from 18 commits
ad5f44f
39f25be
5658ce3
c860cd8
a8b8880
5cdf32d
9140efb
8084bae
b278249
5b0888a
9c3b270
7cee50a
aaa7689
aaf9b02
25efdf5
963e836
a43f493
078712b
edc8dae
8abf1a3
d4dbbb5
8542b48
7d84381
d015661
52c70b3
3534663
d349335
1520db9
b7be6e9
b178753
acaeac6
006c659
6c49e6e
f4fd2f7
498ba1e
f0c9957
2323273
9349cb6
5222529
21196c5
18cdea5
9c6b0ca
e65d268
8998d43
b49f509
e61fa7f
37356cb
68dc6d5
87cefe0
398bf44
10d3aff
c322ed0
58e6199
2b9c1f0
f5b9ab5
a298423
d607b8d
ebcb7b6
73c4996
b954e7a
ceb35de
10fc25e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,5 @@ routes | |
flex | ||
webob | ||
jsonpath-rw | ||
prometheus_client | ||
statsd |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -390,6 +390,19 @@ def register_opts(ignore_errors=False): | |
cli_opts = [debug, profile, use_debugger] | ||
do_register_cli_opts(cli_opts, ignore_errors=ignore_errors) | ||
|
||
# Metrics Options stream options | ||
metrics_opts = [ | ||
cfg.BoolOpt('enable', default=False, | ||
help='Enable metrics collection.'), | ||
cfg.StrOpt('driver', default='statsd', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make the noop metrics driver as the default? |
||
help='Driver type for metrics collection.'), | ||
cfg.StrOpt('host', default='127.0.0.1', | ||
help='Destination server to connect to if driver requires connection.'), | ||
cfg.IntOpt('port', default=8125, | ||
help='Destination port to connect to if driver requires connection.'), | ||
] | ||
do_register_opts(metrics_opts, group='metrics', ignore_errors=ignore_errors) | ||
|
||
|
||
def parse_args(args=None): | ||
register_opts() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Licensed to the StackStorm, Inc ('StackStorm') under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
METRICS_COUNTER_SUFFIX = "_counter" | ||
METRICS_TIMER_SUFFIX = "_timer" | ||
|
||
PYTHON_RUNNER_EXECUTION = "python_runner_execution" | ||
PYTHON_WRAPPER_EXECUTION = "python_wrapper_execution" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics for other runners? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I like the idea of doing generic runner metrics at the runner caller as you mentioned. Also need to incorporate the feedback from community and internal on what to test. This is progressing currently. |
||
|
||
METRICS_REGISTER_RUNNER = "register_runner" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Licensed to the StackStorm, Inc ('StackStorm') under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Licensed to the StackStorm, Inc ('StackStorm') under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Licensed to the StackStorm, Inc ('StackStorm') under one or more | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe consistency in module naming? E.g. I assume you added There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree. |
||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from prometheus_client import Histogram, Gauge | ||
|
||
from st2common.metrics.metrics import BaseMetricsDriver | ||
|
||
|
||
class PrometheusDriver(BaseMetricsDriver): | ||
""" Base class for driver implementations for metric collection | ||
""" | ||
def __init__(self): | ||
pass | ||
|
||
def time(self, key, time): | ||
""" Timer metric | ||
""" | ||
prometheus_histogram = Histogram( # pylint: disable=no-value-for-parameter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious why that is needed - in theory, if prometheus_client is in PYTHONPATH, pylint should detect the properties (unless the code is doing some magic). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Their library is magic and people complain about it and they don't care. :'( |
||
key | ||
) | ||
prometheus_histogram.observe(time) | ||
|
||
def inc_counter(self, key, amount=1): | ||
""" Increment counter | ||
""" | ||
prometheus_counter = Gauge( # pylint: disable=no-value-for-parameter | ||
key | ||
) | ||
prometheus_counter.inc(amount) | ||
|
||
def dec_counter(self, key, amount=1): | ||
""" Decrement metric | ||
""" | ||
prometheus_counter = Gauge( # pylint: disable=no-value-for-parameter | ||
key | ||
) | ||
prometheus_counter.dec(amount) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Licensed to the StackStorm, Inc ('StackStorm') under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from numbers import Number | ||
from oslo_config import cfg | ||
import statsd | ||
|
||
from st2common.metrics.metrics import BaseMetricsDriver | ||
|
||
|
||
class StatsdDriver(BaseMetricsDriver): | ||
""" StatsD Implementation of the metrics driver | ||
""" | ||
def __init__(self): | ||
self._connection = statsd.StatsClient(cfg.CONF.metrics.host, cfg.CONF.metrics.port) | ||
|
||
def time(self, key, time): | ||
""" Timer metric | ||
""" | ||
assert isinstance(key, str) | ||
assert isinstance(time, Number) | ||
self._connection.timing(key, time) | ||
|
||
def inc_counter(self, key, amount=1): | ||
""" Increment counter | ||
""" | ||
assert isinstance(key, str) | ||
assert isinstance(amount, Number) | ||
self._connection.incr(key, amount) | ||
|
||
def dec_counter(self, key, amount=1): | ||
""" Decrement metric | ||
""" | ||
assert isinstance(key, str) | ||
assert isinstance(amount, Number) | ||
self._connection.decr(key, amount) |
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.
Thanks 👍