Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into chore/plan-based-access-ui
Browse files Browse the repository at this point in the history
# Conflicts:
#	frontend/common/constants.ts
#	frontend/web/components/PermissionsTabs.tsx
  • Loading branch information
kyle-ssg committed Aug 14, 2024
2 parents eccbd79 + 9e25990 commit fe44e88
Show file tree
Hide file tree
Showing 146 changed files with 7,158 additions and 2,730 deletions.
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ repos:
name: isort (python)

- repo: https://github.com/psf/black
rev: 24.4.2
rev: 24.8.0
hooks:
- id: black
language_version: python3
exclude: migrations

- repo: https://github.com/pycqa/flake8
rev: 7.1.0
rev: 7.1.1
hooks:
- id: flake8
name: flake8
Expand All @@ -31,6 +31,8 @@ repos:
hooks:
- id: prettier
exclude: ^(frontend/|CHANGELOG.md|.github/docker_build_comment_template.md)
additional_dependencies:
- prettier@3.3.3 # SEE: https://github.com/pre-commit/pre-commit/issues/3133

- repo: https://github.com/python-poetry/poetry
rev: 1.8.0
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "2.134.0"
".": "2.136.0"
}
51 changes: 51 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,56 @@
# Changelog

## [2.136.0](https://github.com/Flagsmith/flagsmith/compare/v2.135.1...v2.136.0) (2024-08-13)


### Features

* Add automatic tagging for github integration ([#4028](https://github.com/Flagsmith/flagsmith/issues/4028)) ([7920e8e](https://github.com/Flagsmith/flagsmith/commit/7920e8e22e15fc2f91dbd56582679b1f3064e4a9))
* Add tags for GitHub integration FE ([#4035](https://github.com/Flagsmith/flagsmith/issues/4035)) ([3c46a31](https://github.com/Flagsmith/flagsmith/commit/3c46a31f6060f7a12206fa27409073da946130d8))
* Support Aptible deployments ([#4340](https://github.com/Flagsmith/flagsmith/issues/4340)) ([3b47ae0](https://github.com/Flagsmith/flagsmith/commit/3b47ae07848c1330210d18bd8bb4194fa5d9262e))
* Use environment feature state instead of fetching feature states ([#4188](https://github.com/Flagsmith/flagsmith/issues/4188)) ([b1d49a6](https://github.com/Flagsmith/flagsmith/commit/b1d49a63b5d7c1fe319185586f486829626840cd))


### Bug Fixes

* ensure that usage notification logic is independent of other organisations notifications ([#4480](https://github.com/Flagsmith/flagsmith/issues/4480)) ([6660af5](https://github.com/Flagsmith/flagsmith/commit/6660af56047e8d7083486b2dab20df44d0fc9303))
* Remove warning about non-unique health namespace ([#4479](https://github.com/Flagsmith/flagsmith/issues/4479)) ([6ef7a74](https://github.com/Flagsmith/flagsmith/commit/6ef7a742f0f56aef2335da380770dc7f307d53c5))


### Infrastructure (Flagsmith SaaS Only)

* reduce task retention days to 7 ([#4484](https://github.com/Flagsmith/flagsmith/issues/4484)) ([4349149](https://github.com/Flagsmith/flagsmith/commit/4349149700ad92e824c115c93f1912c7009c9aa2))

## [2.135.1](https://github.com/Flagsmith/flagsmith/compare/v2.135.0...v2.135.1) (2024-08-12)


### Infrastructure (Flagsmith SaaS Only)

* bump feature evaluation cache to 300 ([#4471](https://github.com/Flagsmith/flagsmith/issues/4471)) ([abbf24b](https://github.com/Flagsmith/flagsmith/commit/abbf24bf987e8f74cb2ecf3ec3d82456d9892654))

## [2.135.0](https://github.com/Flagsmith/flagsmith/compare/v2.134.1...v2.135.0) (2024-08-09)


### Features

* **app_analytics:** Add cache for feature evaluation ([#4418](https://github.com/Flagsmith/flagsmith/issues/4418)) ([2dfbf99](https://github.com/Flagsmith/flagsmith/commit/2dfbf99cdc8d8529aa487a4e471df46c0dbc6878))
* Support blank identifiers, assume transient ([#4449](https://github.com/Flagsmith/flagsmith/issues/4449)) ([0014a5b](https://github.com/Flagsmith/flagsmith/commit/0014a5b4312d1ee7d7dd7b914434f26408ee18b7))


### Bug Fixes

* Identity overrides are not deleted when deleting Edge identities ([#4460](https://github.com/Flagsmith/flagsmith/issues/4460)) ([2ab73ed](https://github.com/Flagsmith/flagsmith/commit/2ab73edc7352bec8324eb808ba70d6508fe5eed6))
* show correct SAML Frontend URL on edit ([#4462](https://github.com/Flagsmith/flagsmith/issues/4462)) ([13ad7ef](https://github.com/Flagsmith/flagsmith/commit/13ad7ef7e6613bdd640cdfca7ce99a892b3893be))

## [2.134.1](https://github.com/Flagsmith/flagsmith/compare/v2.134.0...v2.134.1) (2024-08-07)


### Bug Fixes

* don't allow bypassing `ALLOW_REGISTRATION_WITHOUT_INVITE` behaviour ([#4454](https://github.com/Flagsmith/flagsmith/issues/4454)) ([0e6deec](https://github.com/Flagsmith/flagsmith/commit/0e6deec6404c3e78edf5f36b36ea0f2dcef3dd06))
* protect get environment document endpoint ([#4459](https://github.com/Flagsmith/flagsmith/issues/4459)) ([bee01c7](https://github.com/Flagsmith/flagsmith/commit/bee01c7f21cae19e7665ede3284f96989d33940f))
* Set grace period to a singular event ([#4455](https://github.com/Flagsmith/flagsmith/issues/4455)) ([3225c47](https://github.com/Flagsmith/flagsmith/commit/3225c47043f9647a7426b7f05890bde29b681acc))

## [2.134.0](https://github.com/Flagsmith/flagsmith/compare/v2.133.1...v2.134.0) (2024-08-02)


Expand Down
21 changes: 21 additions & 0 deletions api/app/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@

USE_POSTGRES_FOR_ANALYTICS = env.bool("USE_POSTGRES_FOR_ANALYTICS", default=False)
USE_CACHE_FOR_USAGE_DATA = env.bool("USE_CACHE_FOR_USAGE_DATA", default=False)
PG_API_USAGE_CACHE_SECONDS = env.int("PG_API_USAGE_CACHE_SECONDS", default=60)

FEATURE_EVALUATION_CACHE_SECONDS = env.int(
"FEATURE_EVALUATION_CACHE_SECONDS", default=60
)

ENABLE_API_USAGE_TRACKING = env.bool("ENABLE_API_USAGE_TRACKING", default=True)

Expand Down Expand Up @@ -512,6 +517,10 @@
LOGOUT_URL = "/admin/logout/"

# Enable E2E tests
E2E_TEST_AUTH_TOKEN = env.str("E2E_TEST_AUTH_TOKEN", default=None)
if E2E_TEST_AUTH_TOKEN is not None:
MIDDLEWARE.append("e2etests.middleware.E2ETestMiddleware")

ENABLE_FE_E2E = env.bool("ENABLE_FE_E2E", default=False)
# Email associated with user that is used by front end for end to end testing purposes
E2E_TEST_EMAIL_DOMAIN = "flagsmithe2etestdomain.io"
Expand All @@ -521,6 +530,18 @@
E2E_CHANGE_EMAIL_USER = f"e2e_change_email@{E2E_TEST_EMAIL_DOMAIN}"
# User email address used for the rest of the E2E tests
E2E_USER = f"e2e_user@{E2E_TEST_EMAIL_DOMAIN}"
E2E_NON_ADMIN_USER_WITH_ORG_PERMISSIONS = (
f"e2e_non_admin_user_with_org_permissions@{E2E_TEST_EMAIL_DOMAIN}"
)
E2E_NON_ADMIN_USER_WITH_PROJECT_PERMISSIONS = (
f"e2e_non_admin_user_with_project_permissions@{E2E_TEST_EMAIL_DOMAIN}"
)
E2E_NON_ADMIN_USER_WITH_ENV_PERMISSIONS = (
f"e2e_non_admin_user_with_env_permissions@{E2E_TEST_EMAIL_DOMAIN}"
)
E2E_NON_ADMIN_USER_WITH_A_ROLE = (
f"e2e_non_admin_user_with_a_role@{E2E_TEST_EMAIL_DOMAIN}"
)
# Identity for E2E segment tests
E2E_IDENTITY = "test-identity"

Expand Down
3 changes: 3 additions & 0 deletions api/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
re_path(r"^api/v2/", include("api.urls.v2", namespace="api-v2")),
re_path(r"^admin/", admin.site.urls),
re_path(r"^health", include("health_check.urls", namespace="health")),
# Aptible health checks must be on /healthcheck and cannot redirect
# see https://www.aptible.com/docs/core-concepts/apps/connecting-to-apps/app-endpoints/https-endpoints/health-checks
path("healthcheck", include("health_check.urls", namespace="aptible")),
re_path(r"^version", views.version_info, name="version-info"),
re_path(
r"^sales-dashboard/",
Expand Down
29 changes: 11 additions & 18 deletions api/app_analytics/analytics_db_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ def get_usage_data(
) -> list[UsageData]:
now = timezone.now()

date_stop = date_start = None
period_starts_at = period_ends_at = None
date_start = date_stop = None

match period:
case constants.CURRENT_BILLING_PERIOD:
Expand All @@ -47,10 +46,8 @@ def get_usage_data(
days=30
)
month_delta = relativedelta(now, starts_at).months
period_starts_at = relativedelta(months=month_delta) + starts_at
period_ends_at = now
date_start = f"-{(now - period_starts_at).days}d"
date_stop = "now()"
date_start = relativedelta(months=month_delta) + starts_at
date_stop = now

case constants.PREVIOUS_BILLING_PERIOD:
if not getattr(organisation, "subscription_information_cache", None):
Expand All @@ -61,16 +58,12 @@ def get_usage_data(
)
month_delta = relativedelta(now, starts_at).months - 1
month_delta += relativedelta(now, starts_at).years * 12
period_starts_at = relativedelta(months=month_delta) + starts_at
period_ends_at = relativedelta(months=month_delta + 1) + starts_at
date_start = f"-{(now - period_starts_at).days}d"
date_stop = f"-{(now - period_ends_at).days}d"
date_start = relativedelta(months=month_delta) + starts_at
date_stop = relativedelta(months=month_delta + 1) + starts_at

case constants.NINETY_DAY_PERIOD:
period_starts_at = now - relativedelta(days=90)
period_ends_at = now
date_start = "-90d"
date_stop = "now()"
date_start = now - relativedelta(days=90)
date_stop = now

if settings.USE_POSTGRES_FOR_ANALYTICS:
kwargs = {
Expand All @@ -79,10 +72,10 @@ def get_usage_data(
"project_id": project_id,
}

if period_starts_at:
assert period_ends_at
kwargs["date_start"] = period_starts_at
kwargs["date_stop"] = period_ends_at
if date_start:
assert date_stop
kwargs["date_start"] = date_start
kwargs["date_stop"] = date_stop

return get_usage_data_from_local_db(**kwargs)

Expand Down
57 changes: 53 additions & 4 deletions api/app_analytics/cache.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from app_analytics.tasks import track_request
from django.utils import timezone
from collections import defaultdict

CACHE_FLUSH_INTERVAL = 60 # seconds
from app_analytics.tasks import track_feature_evaluation, track_request
from app_analytics.track import track_feature_evaluation_influxdb
from django.conf import settings
from django.utils import timezone


class APIUsageCache:
Expand Down Expand Up @@ -29,5 +31,52 @@ def track_request(self, resource: int, host: str, environment_key: str):
self._cache[key] = 1
else:
self._cache[key] += 1
if (timezone.now() - self._last_flushed_at).seconds > CACHE_FLUSH_INTERVAL:
if (
timezone.now() - self._last_flushed_at
).seconds > settings.PG_API_USAGE_CACHE_SECONDS:
self._flush()


class FeatureEvaluationCache:
def __init__(self):
self._cache = {}
self._last_flushed_at = timezone.now()

def _flush(self):
evaluation_data = defaultdict(dict)
for (environment_id, feature_name), eval_count in self._cache.items():
evaluation_data[environment_id][feature_name] = eval_count

for environment_id, feature_evaluations in evaluation_data.items():
if settings.USE_POSTGRES_FOR_ANALYTICS:
track_feature_evaluation.delay(
kwargs={
"environment_id": environment_id,
"feature_evaluations": feature_evaluations,
}
)

elif settings.INFLUXDB_TOKEN:
track_feature_evaluation_influxdb.delay(
kwargs={
"environment_id": environment_id,
"feature_evaluations": feature_evaluations,
}
)

self._cache = {}
self._last_flushed_at = timezone.now()

def track_feature_evaluation(
self, environment_id: int, feature_name: str, evaluation_count: int
):
key = (environment_id, feature_name)
if key not in self._cache:
self._cache[key] = evaluation_count
else:
self._cache[key] += evaluation_count

if (
timezone.now() - self._last_flushed_at
).seconds > settings.FEATURE_EVALUATION_CACHE_SECONDS:
self._flush()
Loading

0 comments on commit fe44e88

Please sign in to comment.