Skip to content

Commit

Permalink
feat(api-usage): add environment variable to prevent API usage tracki…
Browse files Browse the repository at this point in the history
…ng. (#3386)
  • Loading branch information
matthewelwell authored Feb 6, 2024
1 parent c119d0e commit 5fa0a1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 9 additions & 6 deletions api/app/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,15 @@

USE_POSTGRES_FOR_ANALYTICS = env.bool("USE_POSTGRES_FOR_ANALYTICS", default=False)

# NOTE: Because we use Postgres for analytics data in staging and Influx for tracking SSE data,
# we need to support setting the influx configuration alongside using postgres for analytics.
if USE_POSTGRES_FOR_ANALYTICS:
MIDDLEWARE.append("app_analytics.middleware.APIUsageMiddleware")
elif INFLUXDB_TOKEN:
MIDDLEWARE.append("app_analytics.middleware.InfluxDBMiddleware")
ENABLE_API_USAGE_TRACKING = env.bool("ENABLE_API_USAGE_TRACKING", default=True)

if ENABLE_API_USAGE_TRACKING:
# NOTE: Because we use Postgres for analytics data in staging and Influx for tracking SSE data,
# we need to support setting the influx configuration alongside using postgres for analytics.
if USE_POSTGRES_FOR_ANALYTICS:
MIDDLEWARE.append("app_analytics.middleware.APIUsageMiddleware")
elif INFLUXDB_TOKEN:
MIDDLEWARE.append("app_analytics.middleware.InfluxDBMiddleware")


ALLOWED_ADMIN_IP_ADDRESSES = env.list("ALLOWED_ADMIN_IP_ADDRESSES", default=list())
Expand Down
8 changes: 6 additions & 2 deletions docs/docs/deployment/hosting/locally-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ application.
Further information on the admin pages can be found [here](/deployment/configuration/django-admin).

[^1]:
Your Flagsmith's domain can also be configured via the `FLAGSMITH_DOMAIN` environment variable. See the
[full list](#application-environment-variables) of variables used for configuration.

Your Flagsmith's domain can also be configured via the `FLAGSMITH_DOMAIN` environment variable. See the
[full list](#application-environment-variables) of variables used for configuration.

## Deploying

Expand Down Expand Up @@ -251,6 +252,9 @@ the below variables will be ignored.
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.
- `ENABLE_API_USAGE_TRACKING`: Enable tracking of all API requests in Postgres / Influx. Default is True. Setting to
False will mean that the Usage tab in the Organisation Settings will not show any data. Useful when using Postgres for
analytics in high traffic environments to limit the size of database.

#### Security Environment Variables

Expand Down

0 comments on commit 5fa0a1a

Please sign in to comment.