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(api-usage): add environment variable to prevent API usage tracking. #3386

Merged
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
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
Loading