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

fix(postgres/feature-analytics): use feature filter #3091

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions api/app_analytics/analytics_db_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def get_feature_evaluation_data_from_local_db(
FeatureEvaluationBucket.objects.filter(
environment_id=environment_id,
bucket_size=ANALYTICS_READ_BUCKET_SIZE,
feature_name=feature.name,
created_at__date__lte=timezone.now(),
created_at__date__gt=timezone.now() - timedelta(days=period),
)
Expand Down
3 changes: 2 additions & 1 deletion api/app_analytics/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ def check_overlapping_buckets(self, filters):

if overlapping_buckets.exists():
raise ValidationError(
"Cannot create bucket starting at {self.created_at} with size {self.bucket_size} minutes,"
"Cannot create bucket starting at %s with size %s minutes,"
"because it overlaps with existing buckets"
% (self.created_at, self.bucket_size),
)


Expand Down
17 changes: 16 additions & 1 deletion api/tests/unit/app_analytics/test_analytics_db_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
)
from django.conf import settings
from django.utils import timezone
from pytest_django.fixtures import SettingsWrapper

from environments.models import Environment
from features.models import Feature


@pytest.mark.skipif(
Expand Down Expand Up @@ -138,7 +142,9 @@ def test_get_total_events_count(organisation, environment, settings):
reason="Skip test if analytics database is configured",
)
@pytest.mark.django_db(databases=["analytics", "default"])
def test_get_feature_evaluation_data_from_local_db(feature, environment, settings):
def test_get_feature_evaluation_data_from_local_db(
feature: Feature, environment: Environment, settings: SettingsWrapper
):
environment_id = environment.id
feature_name = feature.name
now = timezone.now()
Expand Down Expand Up @@ -181,6 +187,15 @@ def test_get_feature_evaluation_data_from_local_db(feature, environment, setting
created_at=now - timedelta(days=i),
)

# some data for different feature
FeatureEvaluationBucket.objects.create(
environment_id=environment_id,
feature_name="some_other_feature",
total_count=10,
bucket_size=read_bucket_size,
created_at=now - timedelta(days=i),
)

# When
usage_data_list = get_feature_evaluation_data_from_local_db(feature, environment_id)

Expand Down