Skip to content

Commit fac9acc

Browse files
authored
Do not use kinto.plugins.statsd by default (#3504)
* Do not use 'kinto.plugins.statsd' by default * make format * Include statsd plugin in tests * Drop statsd initialization step * Move test for non initialization
1 parent e660bbd commit fac9acc

File tree

4 files changed

+10
-39
lines changed

4 files changed

+10
-39
lines changed

kinto/core/initialization.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -334,16 +334,6 @@ def on_app_created(event):
334334
config.add_subscriber(on_app_created, ApplicationCreated)
335335

336336

337-
def setup_statsd(config):
338-
# It would be pretty rare to find users that have a custom ``kinto.initialization_sequence`` setting.
339-
# But just in case, warn that it will be removed in next major.
340-
warnings.warn(
341-
"``setup_statsd()`` is now deprecated. Use ``kinto.core.initialization.setup_metrics()`` instead.",
342-
DeprecationWarning,
343-
)
344-
setup_metrics(config)
345-
346-
347337
def install_middlewares(app, settings):
348338
"Install a set of middlewares defined in the ini file on the given app."
349339
# Setup new-relic.
@@ -544,10 +534,6 @@ def on_new_response(event):
544534

545535
config.add_subscriber(on_new_response, NewResponse)
546536

547-
# While statsd is deprecated, we include its plugin by default for retro-compability.
548-
if settings["statsd_url"]:
549-
config.include("kinto.plugins.statsd")
550-
551537

552538
class EventActionFilter:
553539
def __init__(self, actions, config):

tests/core/resource/test_events.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ def get_app_settings(cls, *args, **kwargs):
499499
if not statsd.statsd_module:
500500
return settings
501501

502+
settings["includes"] = "kinto.plugins.statsd"
502503
settings["statsd_url"] = "udp://localhost:8125"
503504
this_module = "tests.core.resource.test_events"
504505
settings["event_listeners"] = "test"

tests/core/test_initialization.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ def test_environment_values_override_configuration(self):
129129
prefix_used = config.registry.settings["settings_prefix"]
130130
self.assertEqual(prefix_used, "abc")
131131

132+
def test_statsd_plugin_isnt_included_by_default(self):
133+
config = Configurator()
134+
with mock.patch("kinto.plugins.statsd.StatsDService") as mocked:
135+
kinto.core.initialize(config, "0.0.1", "prefix")
136+
mocked.assert_not_called()
137+
132138

133139
class ProjectSettingsTest(unittest.TestCase):
134140
def settings(self, provided):
@@ -304,6 +310,7 @@ def unexpected_exceptions_are_reported(self):
304310
class MetricsConfigurationTest(unittest.TestCase):
305311
settings = {
306312
**kinto.core.DEFAULT_SETTINGS,
313+
"includes": "kinto.plugins.statsd",
307314
"statsd_url": "udp://host:8080",
308315
"multiauth.policies": "basicauth",
309316
}
@@ -322,26 +329,6 @@ def setUp(self):
322329
self.config.registry.cache = {}
323330
self.config.registry.permission = {}
324331

325-
def test_setup_statsd_step_is_still_supported(self):
326-
with mock.patch("warnings.warn") as mocked_warnings:
327-
initialization.setup_statsd(self.config)
328-
mocked_warnings.assert_called_with(
329-
"``setup_statsd()`` is now deprecated. Use ``kinto.core.initialization.setup_metrics()`` instead.",
330-
DeprecationWarning,
331-
)
332-
self.mocked.assert_called_with("host", 8080, "kinto.core")
333-
334-
def test_statsd_is_included_by_default(self):
335-
kinto.core.initialize(self.config, "0.0.1", "name")
336-
337-
self.mocked.assert_called_with("host", 8080, "kinto.core")
338-
339-
def test_statsd_isnt_included_if_statsd_url_is_not_set(self):
340-
self.config.add_settings({"statsd_url": None})
341-
kinto.core.initialize(self.config, "0.0.1", "name")
342-
343-
self.mocked.assert_not_called()
344-
345332
#
346333
# Backends.
347334
#

tests/plugins/test_history.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ class MetricsTest(HistoryWebTest):
3131
@classmethod
3232
def get_app_settings(cls, extras=None):
3333
settings = super().get_app_settings(extras)
34-
settings.update(
35-
**{
36-
"statsd_url": "udp://127.0.0.1:8125",
37-
}
38-
)
34+
settings["includes"] += " kinto.plugins.statsd"
35+
settings["statsd_url"] = "udp://127.0.0.1:8125"
3936
return settings
4037

4138
def test_a_statsd_timer_is_used_for_history_if_configured(self):

0 commit comments

Comments
 (0)