Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit e51be40

Browse files
committed
remove exposure logging from Feature
1 parent e121816 commit e51be40

2 files changed

Lines changed: 2 additions & 130 deletions

File tree

shared/rollouts/__init__.py

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@
77
import mmh3
88
from asgiref.sync import sync_to_async
99
from cachetools.func import lru_cache, ttl_cache
10-
from django.utils import timezone
1110

1211
from shared.config import get_config
1312
from shared.django_apps.rollouts.models import (
14-
FeatureExposure,
1513
FeatureFlag,
1614
FeatureFlagVariant,
17-
Platform,
18-
RolloutUniverse,
1915
)
2016
from shared.django_apps.utils.rollout_utils import rollout_universe_to_override_string
2117

@@ -309,10 +305,9 @@ def _check_value_no_lru(self, identifier, default):
309305
the `Feature` class on every request.
310306
"""
311307

312-
# don't log exposures for flag evaluations from the endpoint
313-
return self._check_value_impl(identifier, default, log_exposures=False)
308+
return self._check_value_impl(identifier, default)
314309

315-
def _check_value_impl(self, identifier, default, log_exposures=True):
310+
def _check_value_impl(self, identifier, default):
316311
"""
317312
This is the core logic of how a feature flag variant is assigned to a user based on some identifier, and
318313
returns the variant's value.
@@ -338,11 +333,6 @@ def _check_value_impl(self, identifier, default, log_exposures=True):
338333
)
339334
for bucket_start, bucket_end, variant in self._buckets:
340335
if bucket_start <= key and key < bucket_end:
341-
# only log exposures for backend flags because frontend has no SQL metrics and
342-
# flag evaluations should be cached client-side anyways
343-
if self.feature_flag.platform == Platform.BACKEND and log_exposures:
344-
self.create_exposure(variant, identifier)
345-
346336
return variant.value
347337

348338
return default
@@ -357,22 +347,3 @@ def _is_different(self, inst1, inst2):
357347
return False
358348

359349
return True
360-
361-
def create_exposure(self, variant, identifier):
362-
"""
363-
Creates an exposure record indicating that a feature variant has been applied to
364-
an entity (repo or owner) at a current point in time. This method should only
365-
be used for backend feature flags, as we're only collecting `telemetry_simple`
366-
SQL metrics for backend services.
367-
"""
368-
args = {
369-
"feature_flag": self.feature_flag,
370-
"feature_flag_variant": variant,
371-
"timestamp": timezone.now(),
372-
}
373-
if self.feature_flag.rollout_universe == RolloutUniverse.OWNER_ID:
374-
args["owner"] = identifier
375-
elif self.feature_flag.rollout_universe == RolloutUniverse.REPO_ID:
376-
args["repo"] = identifier
377-
378-
FeatureExposure.objects.create(**args)

tests/unit/test_rollouts.py

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
from django.test import TestCase
66

77
from shared.django_apps.rollouts.models import (
8-
FeatureExposure,
98
FeatureFlag,
109
FeatureFlagVariant,
11-
Platform,
1210
RolloutUniverse,
1311
)
1412
from shared.rollouts import Feature
@@ -384,100 +382,3 @@ def test_check_value_with_env_disable_and_env_override(self):
384382
assert feature.check_value(identifier=1, default=100) == 100
385383
fetch_fn.assert_not_called()
386384
assert not hasattr(feature.__dict__, "_buckets")
387-
388-
389-
class TestFeatureExposures(TestCase):
390-
def test_exposure_created(self):
391-
complex = FeatureFlag.objects.create(
392-
name="my_feature", proportion=1.0, salt="random_salt"
393-
)
394-
enabled = FeatureFlagVariant.objects.create(
395-
name="enabled", feature_flag=complex, proportion=1.0, value=True
396-
)
397-
FeatureFlagVariant.objects.create(
398-
name="disabled", feature_flag=complex, proportion=0, value=False
399-
)
400-
401-
owner_id = 123123123
402-
403-
my_feature = Feature("my_feature")
404-
my_feature.check_value(identifier=owner_id)
405-
406-
exposure = FeatureExposure.objects.all().first()
407-
408-
assert exposure is not None
409-
assert exposure.owner == owner_id
410-
assert exposure.feature_flag == complex
411-
assert exposure.feature_flag_variant == enabled
412-
413-
def test_exposure_not_created(self):
414-
complex = FeatureFlag.objects.create(
415-
name="my_feature", proportion=1.0, salt="random_salt"
416-
)
417-
FeatureFlagVariant.objects.create(
418-
name="enabled", feature_flag=complex, proportion=0, value=True
419-
)
420-
421-
with patch.object(Feature, "create_exposure") as create_exposure:
422-
owner_id = 123123123
423-
424-
my_feature = Feature("my_feature")
425-
my_feature.check_value(identifier=owner_id)
426-
427-
exposure = FeatureExposure.objects.first()
428-
429-
# Should not create an exposure because the owner was not exposed to any
430-
# explicit variant, it was assigned the default behaviour
431-
assert exposure is None
432-
create_exposure.assert_not_called()
433-
434-
def test_frontend_flag_does_not_log_exposures(self):
435-
complex = FeatureFlag.objects.create(
436-
name="my_feature",
437-
proportion=1.0,
438-
salt="random_salt",
439-
platform=Platform.FRONTEND,
440-
)
441-
FeatureFlagVariant.objects.create(
442-
name="enabled", feature_flag=complex, proportion=1.0, value=True
443-
)
444-
FeatureFlagVariant.objects.create(
445-
name="disabled", feature_flag=complex, proportion=0, value=False
446-
)
447-
448-
with patch.object(Feature, "create_exposure") as create_exposure:
449-
owner_id = 123123123
450-
451-
my_feature = Feature("my_feature")
452-
my_feature.check_value(identifier=owner_id)
453-
454-
exposure = FeatureExposure.objects.all().first()
455-
456-
assert exposure is None
457-
create_exposure.assert_not_called()
458-
459-
def test_backend_flag_does_log_exposures(self):
460-
complex = FeatureFlag.objects.create(
461-
name="my_feature",
462-
proportion=1.0,
463-
salt="random_salt",
464-
platform=Platform.BACKEND,
465-
)
466-
enabled = FeatureFlagVariant.objects.create(
467-
name="enabled", feature_flag=complex, proportion=1.0, value=True
468-
)
469-
FeatureFlagVariant.objects.create(
470-
name="disabled", feature_flag=complex, proportion=0, value=False
471-
)
472-
473-
owner_id = 123123123
474-
475-
my_feature = Feature("my_feature")
476-
my_feature.check_value(identifier=owner_id)
477-
478-
exposure = FeatureExposure.objects.all().first()
479-
480-
assert exposure is not None
481-
assert exposure.owner == owner_id
482-
assert exposure.feature_flag == complex
483-
assert exposure.feature_flag_variant == enabled

0 commit comments

Comments
 (0)