Skip to content

Commit 4eaaf84

Browse files
committed
Added tags for gunicorn
1 parent fff2d44 commit 4eaaf84

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

splitio/client/factory.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""A module for Split.io Factories."""
22
import logging
33
import threading
4-
import sys
54
from collections import Counter
65

76
from enum import Enum
@@ -419,9 +418,6 @@ def _build_in_memory_factory(api_key, cfg, sdk_url=None, events_url=None, # pyl
419418
)
420419

421420
telemetry_init_producer.record_config(cfg, extra_cfg)
422-
if int(_get_uwsgi_worker_id()) > -1:
423-
telemetry_init_producer.add_config_tag("initilization:uwsgi")
424-
telemetry_init_producer.add_config_tag("uwsgi_worker:#" + _get_uwsgi_worker_id())
425421

426422
if preforked_initialization:
427423
synchronizer.sync_all(max_retry_attempts=_MAX_RETRY_SYNC_ALL)
@@ -503,9 +499,6 @@ def _build_redis_factory(api_key, cfg):
503499
initialization_thread.start()
504500

505501
telemetry_init_producer.record_config(cfg, {})
506-
if int(_get_uwsgi_worker_id()) > -1:
507-
telemetry_init_producer.add_config_tag("initilization:uwsgi")
508-
telemetry_init_producer.add_config_tag("uwsgi_worker:#" + _get_uwsgi_worker_id())
509502

510503
split_factory = SplitFactory(
511504
api_key,
@@ -622,13 +615,4 @@ def _get_active_and_redundant_count():
622615
redundant_factory_count += _INSTANTIATED_FACTORIES[item] - 1
623616
active_factory_count += _INSTANTIATED_FACTORIES[item]
624617
_INSTANTIATED_FACTORIES_LOCK.release()
625-
return redundant_factory_count, active_factory_count
626-
627-
def _get_uwsgi_worker_id():
628-
try:
629-
import uwsgi
630-
_LOGGER.debug("uwsgi lib detected")
631-
return str(uwsgi.worker_id())
632-
except ModuleNotFoundError:
633-
pass
634-
return "-1"
618+
return redundant_factory_count, active_factory_count

splitio/engine/telemetry.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"""Telemetry engine classes."""
22
import json
3+
import os
4+
5+
import logging
6+
_LOGGER = logging.getLogger(__name__)
37

48
from splitio.storage.inmemmory import InMemoryTelemetryStorage
59
from splitio.models.telemetry import CounterConstants
@@ -35,6 +39,10 @@ def __init__(self, telemetry_storage):
3539
def record_config(self, config, extra_config):
3640
"""Record configurations."""
3741
self._telemetry_storage.record_config(config, extra_config)
42+
current_app, app_worker_id = self._get_app_worker_id()
43+
if current_app is not None:
44+
self.add_config_tag("initilization:" + current_app)
45+
self.add_config_tag("worker:#" + app_worker_id)
3846

3947
def record_ready_time(self, ready_time):
4048
"""Record ready time."""
@@ -55,6 +63,20 @@ def add_config_tag(self, tag):
5563
"""Record tag string."""
5664
self._telemetry_storage.add_config_tag(tag)
5765

66+
def _get_app_worker_id(self):
67+
try:
68+
import uwsgi
69+
return "uwsgi", str(uwsgi.worker_id())
70+
except ModuleNotFoundError:
71+
_LOGGER.debug("NO uwsgi")
72+
pass
73+
74+
if 'gunicorn' in os.environ.get("SERVER_SOFTWARE", ""):
75+
return "gunicorn", str(os.getpid())
76+
else:
77+
return None, None
78+
79+
5880
class TelemetryEvaluationProducer(object):
5981
"""Telemetry evaluation producer class."""
6082

0 commit comments

Comments
 (0)