Skip to content
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

Merged
merged 62 commits into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
ad5f44f
Hacking together PRC for metrics collection.
bigmstone Feb 16, 2018
39f25be
Merge branch 'master' of github.com:StackStorm/st2 into issue-2974/me…
bigmstone Feb 21, 2018
5658ce3
Adding context managers and moving existing metrics to it. Adding run…
bigmstone Feb 22, 2018
c860cd8
Adding constants
bigmstone Feb 22, 2018
a8b8880
Merge branch 'master' of github.com:StackStorm/st2 into issue-2974/me…
bigmstone Feb 22, 2018
5cdf32d
Adding config parse to pythonrunner tests
bigmstone Feb 23, 2018
9140efb
Updating sample config
bigmstone Feb 23, 2018
8084bae
Adding licenses and unit tests for statsd driver and base driver
bigmstone Feb 23, 2018
b278249
Changing to Gauge for prometheus driver
bigmstone Feb 23, 2018
5b0888a
reverting changes to wrapper when collecting metrics inside the wrapper.
bigmstone Feb 23, 2018
9c3b270
Adding __call__ to allow metcis context managers to be decorators.
bigmstone Feb 23, 2018
7cee50a
Finishing up tests and adding metrics test for runner loader
bigmstone Feb 27, 2018
aaa7689
Merge branch 'master' of github.com:StackStorm/st2 into issue-2974/me…
bigmstone Feb 27, 2018
aaf9b02
Fixing linting issues
bigmstone Feb 28, 2018
25efdf5
Finishing out tests
bigmstone Feb 28, 2018
963e836
Merge branch 'master' of github.com:StackStorm/st2 into issue-2974/me…
bigmstone Mar 7, 2018
a43f493
Adding changelog
bigmstone Mar 7, 2018
078712b
Merge branch 'master' of github.com:StackStorm/st2 into issue-2974/me…
bigmstone Mar 21, 2018
edc8dae
Fixing bootstrap file to parse config so metrics can be used w/ decor…
bigmstone Mar 23, 2018
8abf1a3
Merge branch 'master' of github.com:StackStorm/st2 into issue-2974/me…
bigmstone Mar 23, 2018
d4dbbb5
Reverting unneeded change
bigmstone Mar 24, 2018
8542b48
Merge branch 'master' of github.com:StackStorm/st2 into issue-2974/me…
bigmstone Apr 15, 2018
7d84381
Moving metrics drivers to contrib to prep for stevedore load
bigmstone Apr 17, 2018
d015661
Adding metrics stevedore helper functions.
bigmstone Apr 17, 2018
52c70b3
Starting metrics registrar
bigmstone Apr 18, 2018
3534663
Merge branch 'master' of github.com:StackStorm/st2 into issue-2974/me…
bigmstone Apr 18, 2018
d349335
Reverting stevedore breakout
bigmstone Apr 18, 2018
1520db9
Reverting config
bigmstone Apr 18, 2018
b7be6e9
Revert "Reverting config"
bigmstone Apr 18, 2018
b178753
Revert "Reverting stevedore breakout"
bigmstone Apr 18, 2018
acaeac6
Using stevedore in st2common
bigmstone May 1, 2018
006c659
Updaing config
bigmstone May 1, 2018
6c49e6e
Fixing metrics.py for when metrics driver isn't loaded
bigmstone May 2, 2018
f4fd2f7
Moving to UTC time
bigmstone May 2, 2018
498ba1e
Fixing tests for move to util.date function
bigmstone May 2, 2018
f0c9957
Incorportaing feedback.
bigmstone May 4, 2018
2323273
Changing how metrics constent is set/get.
bigmstone May 4, 2018
9349cb6
Updating tests.
bigmstone May 4, 2018
5222529
Merge branch 'master' of github.com:StackStorm/st2 into issue-2974/me…
bigmstone May 4, 2018
21196c5
Adding global
bigmstone May 5, 2018
18cdea5
Adding noop metrics driver
bigmstone May 7, 2018
9c6b0ca
Merge branch 'master' of github.com:StackStorm/st2 into issue-2974/me…
bigmstone May 7, 2018
e65d268
Adding st2common to virtualenv for tests. Fixing stevedore instance c…
bigmstone May 7, 2018
8998d43
Bumping webob version
bigmstone May 8, 2018
b49f509
Removing st2common from make requirements
bigmstone May 8, 2018
e61fa7f
Merge branch 'master' of github.com:StackStorm/st2 into issue-2974/me…
bigmstone May 8, 2018
37356cb
Reverting python runner test changes
bigmstone May 8, 2018
68dc6d5
Removing _ from private variable.
bigmstone May 8, 2018
87cefe0
Adding st2common to requirements. Loading noop driver by default. Fix…
bigmstone May 9, 2018
398bf44
Merge branch 'master' of github.com:StackStorm/st2 into issue-2974/me…
bigmstone May 9, 2018
10d3aff
Making requests requirement consistent
bigmstone May 10, 2018
c322ed0
Removing counter w/ timer from python_runner to address it elseware a…
bigmstone May 10, 2018
58e6199
Adding st2common to requirements for tox.
bigmstone May 10, 2018
2b9c1f0
Checking out master version of python runner and python runner tests
bigmstone May 10, 2018
f5b9ab5
Merge branch 'master' of github.com:StackStorm/st2 into issue-2974/me…
bigmstone May 10, 2018
a298423
Merge branch 'master' of github.com:StackStorm/st2 into issue-2974/me…
bigmstone May 14, 2018
d607b8d
Moving to python-statsd to avoid conflict
bigmstone May 14, 2018
ebcb7b6
Improving statsd driver
bigmstone May 14, 2018
73c4996
Fixing statsd tests
bigmstone May 15, 2018
b954e7a
Revert requirements
bigmstone May 15, 2018
ceb35de
Merge branch 'master' of github.com:StackStorm/st2 into issue-2974/me…
bigmstone May 15, 2018
10fc25e
Moving st2common install. Making requirements for st2common.
bigmstone May 15, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,6 @@ Added
deployments to override ``COMPONENTS`` and ``ST2_CONF`` in a global location
so ``st2ctl`` can start/stop/restart selected components and utilize a non-default
location for ``st2.conf``.
(new feature) #4027

Contributed by Nick Maludy (Encore Technologies).
* Add support for new optional ``content_version`` runner parameter to the Python and Local Shell
Script runner. This parameter can contain a git commit hash / tag / branch from a pack git
repository and runner will ensure this revision of the pack content (Python action / local shell
script action) is used for a particular action execution.

Keep in mind that providing this parameter only ensures a particular revision of the pack content
is used. Python runner virtual environment and dependencies are outside of this scope.

Note: To be able to utilize this functionality, git version >= 2.5.0 must be installed on the
system.
(new feature) #3997

Changed
~~~~~~~
Expand All @@ -64,6 +50,8 @@ Changed
(improvement)
* Throw a more user-friendly error when writing pack data files to disk and when an invalid file
path is provided (e.g. path is outside the pack directory, etc.). (improvement) #4039 #4046
* Added metrics for collecting performance and health information about
the various ST2 services and functions.

Fixed
~~~~~
Expand Down
10 changes: 10 additions & 0 deletions conf/st2.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ connection_retries = 10
# URL of all the nodes in a messaging service cluster.
cluster_urls = # comma separated list allowed here.

[metrics]
# Destination server to connect to if driver requires connection.
host = 127.0.0.1
# Enable metrics collection.
enable = False
# Driver type for metrics collection.
driver = statsd
# Destination port to connect to if driver requires connection.
port = 8125

[mistral]
# URL Mistral uses to talk back to the API.If not provided it defaults to public API URL. Note: This needs to be a base URL without API version (e.g. http://127.0.0.1:9101)
api_url = None
Expand Down
6 changes: 6 additions & 0 deletions conf/st2.dev.conf
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,9 @@ jitter_interval = 0

[packs]
enable_common_libs = True

[metrics]
enable = True
driver = statsd
host = 127.0.0.1
port = 8125
34 changes: 21 additions & 13 deletions contrib/runners/python_runner/python_runner/python_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
from st2common.runners.utils import make_read_and_store_stream_func

from python_runner import python_action_wrapper
from st2common.metrics.metrics import CounterWithTimer

from st2common.constants.metrics import PYTHON_RUNNER_EXECUTION, PYTHON_WRAPPER_EXECUTION


__all__ = [
'PythonRunner',
Expand Down Expand Up @@ -119,7 +123,8 @@ def pre_run(self):
if self._log_level == PYTHON_RUNNER_DEFAULT_LOG_LEVEL:
self._log_level = cfg.CONF.actionrunner.python_runner_log_level

def run(self, action_parameters):
@CounterWithTimer(PYTHON_RUNNER_EXECUTION)
Copy link
Member

Choose a reason for hiding this comment

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

Thanks 👍

def run(self, action_parameters, **kwargs):
LOG.debug('Running pythonrunner.')
LOG.debug('Getting pack name.')
pack = self.get_pack_ref()
Expand Down Expand Up @@ -249,18 +254,21 @@ def run(self, action_parameters):

LOG.debug('Running command: PATH=%s PYTHONPATH=%s %s' % (env['PATH'], env['PYTHONPATH'],
command_string))
exit_code, stdout, stderr, timed_out = run_command(cmd=args,
stdin=stdin,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False,
env=env,
timeout=self._timeout,
read_stdout_func=read_and_store_stdout,
read_stderr_func=read_and_store_stderr,
read_stdout_buffer=stdout,
read_stderr_buffer=stderr,
stdin_value=stdin_params)
with CounterWithTimer(PYTHON_WRAPPER_EXECUTION):
exit_code, stdout, stderr, timed_out = run_command(
cmd=args,
stdin=stdin,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=False,
env=env,
timeout=self._timeout,
read_stdout_func=read_and_store_stdout,
read_stderr_func=read_and_store_stderr,
read_stdout_buffer=stdout,
read_stderr_buffer=stderr,
stdin_value=stdin_params
)
LOG.debug('Returning values: %s, %s, %s, %s', exit_code, stdout, stderr, timed_out)
LOG.debug('Returning.')
return self._get_output_values(exit_code, stdout, stderr, timed_out)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import unittest2
from oslo_config import cfg

from python_runner import python_runner
from st2actions.container.base import RunnerContainer
from st2common.runners.base_action import Action
from st2common.runners.utils import get_action_class_instance
Expand All @@ -35,13 +34,17 @@
from st2common.constants.action import MAX_PARAM_LENGTH
from st2common.constants.pack import SYSTEM_PACK_NAME
from st2common.persistence.execution import ActionExecutionOutput
from st2common import config as st2common_config
from python_runner.python_action_wrapper import PythonActionWrapper
from st2tests.base import RunnerTestCase
from st2tests.base import CleanDbTestCase
from st2tests.base import blocking_eventlet_spawn
from st2tests.base import make_mock_stream_readline
import st2tests.base as tests_base

st2common_config.parse_args(args=[])

from python_runner import python_runner

PASCAL_ROW_ACTION_PATH = os.path.join(tests_base.get_resources_path(), 'packs',
'pythonactions/actions/pascal_row.py')
Expand Down
1 change: 1 addition & 0 deletions fixed-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ prompt-toolkit==1.0.15
tooz==1.60.0
zake==0.2.2
routes==2.4.1
statsd==3.2.2
flex==6.12.0
webob==1.7.4
prance==0.9.0
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ oslo.utils<=3.33.0,>=3.15.0
paramiko==2.4.0
passlib==1.7.1
prettytable
prometheus_client==0.1.1
prompt-toolkit==1.0.15
psutil
pyinotify==0.9.6
Expand All @@ -44,6 +45,7 @@ routes==2.4.1
semver==2.7.7
six==1.10.0
sseclient==0.0.18
statsd==3.2.2
stevedore==1.28.0
tooz==1.60.0
unittest2
Expand Down
2 changes: 2 additions & 0 deletions st2common/in-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ routes
flex
webob
jsonpath-rw
prometheus_client
statsd
13 changes: 13 additions & 0 deletions st2common/st2common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Copy link
Contributor

Choose a reason for hiding this comment

The 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()
Expand Down
22 changes: 22 additions & 0 deletions st2common/st2common/constants/metrics.py
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"
Copy link
Contributor

Choose a reason for hiding this comment

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

Metrics for other runners?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"
14 changes: 14 additions & 0 deletions st2common/st2common/metrics/__init__.py
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.
14 changes: 14 additions & 0 deletions st2common/st2common/metrics/drivers/__init__.py
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.
48 changes: 48 additions & 0 deletions st2common/st2common/metrics/drivers/prometheus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
Copy link
Member

Choose a reason for hiding this comment

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

Maybe consistency in module naming? E.g. statsd_driver vs prometheus.

I assume you added _driver suffix because statsd name clashes 3rd party library. I'm fine going either way - adding _driver suffix to all the driver modules, or drop it everywhere and use from __future__ import absolute_import to avoid name clashes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The 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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
47 changes: 47 additions & 0 deletions st2common/st2common/metrics/drivers/statsd_driver.py
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)
Loading