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

feat: make segment condition value dynamic #3245

Merged
merged 4 commits into from
Jan 25, 2024
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
7 changes: 7 additions & 0 deletions api/app/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import pytz
import requests
from corsheaders.defaults import default_headers
from django.core.exceptions import ImproperlyConfigured
from django.core.management.utils import get_random_secret_key
from environs import Env

Expand Down Expand Up @@ -1074,5 +1075,11 @@
LDAP_SYNC_USER_USERNAME = env.str("LDAP_SYNC_USER_USERNAME", None)
LDAP_SYNC_USER_PASSWORD = env.str("LDAP_SYNC_USER_PASSWORD", None)

SEGMENT_CONDITION_VALUE_LIMIT = env.int("SEGMENT_CONDITION_VALUE_LIMIT", default=1000)
if not 0 <= SEGMENT_CONDITION_VALUE_LIMIT < 2000000:
raise ImproperlyConfigured(
"SEGMENT_CONDITION_VALUE_LIMIT must be between 0 and 2,000,000 (2MB)."
)

WEBHOOK_BACKOFF_BASE = env.int("WEBHOOK_BACKOFF_BASE", default=2)
WEBHOOK_BACKOFF_RETRIES = env.int("WEBHOOK_BACKOFF_RETRIES", default=3)
3 changes: 2 additions & 1 deletion api/segments/migrations/0004_auto_20190523_1325.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Generated by Django 1.11.20 on 2019-05-23 13:25
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion

Expand All @@ -19,7 +20,7 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('operator', models.CharField(choices=[('EQUAL', 'Exactly Equal'), ('GREATER_THAN', 'Greater than'), ('LESS_THAN', 'Less than')], max_length=500)),
('property', models.CharField(max_length=1000)),
('value', models.CharField(max_length=1000)),
('value', models.CharField(max_length=settings.SEGMENT_CONDITION_VALUE_LIMIT)),
],
),
migrations.CreateModel(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Generated by Django 3.2.15 on 2022-10-04 16:21

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('segments', '0012_alter_condition_operator'),
("segments", "0012_alter_condition_operator"),
]

operations = [
Expand All @@ -18,6 +18,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='condition',
name='value',
field=models.CharField(blank=True, max_length=1000, null=True),
field=models.CharField(blank=True, max_length=settings.SEGMENT_CONDITION_VALUE_LIMIT, null=True),
),
]
2 changes: 1 addition & 1 deletion api/segments/migrations/0019_add_audit_to_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Migration(migrations.Migration):
('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
('operator', models.CharField(choices=[('EQUAL', 'Exactly Matches'), ('GREATER_THAN', 'Greater than'), ('LESS_THAN', 'Less than'), ('CONTAINS', 'Contains'), ('GREATER_THAN_INCLUSIVE', 'Greater than or equal to'), ('LESS_THAN_INCLUSIVE', 'Less than or equal to'), ('NOT_CONTAINS', 'Does not contain'), ('NOT_EQUAL', 'Does not match'), ('REGEX', 'Matches regex'), ('PERCENTAGE_SPLIT', 'Percentage split'), ('MODULO', 'Modulo Operation'), ('IS_SET', 'Is set'), ('IS_NOT_SET', 'Is not set'), ('IN', 'In')], max_length=500)),
('property', models.CharField(blank=True, max_length=1000, null=True)),
('value', models.CharField(blank=True, max_length=1000, null=True)),
('value', models.CharField(blank=True, max_length=settings.SEGMENT_CONDITION_VALUE_LIMIT, null=True)),
('description', models.TextField(blank=True, null=True)),
('created_with_segment', models.BooleanField(default=False, help_text='Field to denote whether a condition was created along with segment or added after creation.')),
('history_id', models.AutoField(primary_key=True, serialize=False)),
Expand Down
5 changes: 4 additions & 1 deletion api/segments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
SoftDeleteExportableModel,
abstract_base_auditable_model_factory,
)
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import models
from flag_engine.segments import constants
Expand Down Expand Up @@ -151,7 +152,9 @@ class Condition(

operator = models.CharField(choices=CONDITION_TYPES, max_length=500)
property = models.CharField(blank=True, null=True, max_length=1000)
value = models.CharField(max_length=1000, blank=True, null=True)
value = models.CharField(
max_length=settings.SEGMENT_CONDITION_VALUE_LIMIT, blank=True, null=True
)
description = models.TextField(blank=True, null=True)

created_with_segment = models.BooleanField(
Expand Down
5 changes: 5 additions & 0 deletions docs/docs/deployment/hosting/locally-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ the below variables will be ignored.
ignored.
- `DISABLE_FLAGSMITH_UI`: Disable the Flagsmith UI which can be rendered by the API containers in a single container
environment. Use `True` to disable, defaults to `False`.
- `SEGMENT_CONDITION_VALUE_LIMIT`: Configure the size of the segment condition value in bytes. Default is 1000.
Minimum 0. Maximum 2000000 (2MB). Note that this environment variable changes the length of the column in the database
and hence should not be modified for already running instances of flagsmith. It should only be used for new
installations, and should not be modified. WARNING: setting this to a higher limit may prevent imports to our SaaS
platform if required in the future.

#### Security Environment Variables

Expand Down
Loading