Skip to main content

Using InfluxDB for Analytics

Flagsmith has a soft dependency on InfluxDB to store time-series data. You don't need to configure InfluxDB to run the platform; by default, this data will be stored in PostgreSQL. If you are running very high traffic loads, you might be interested in deploying InfluxDB.

Docker

  1. Create a user account in InfluxDB. You can visit [http://localhost:8086/]
  2. Go into Data > Buckets and create three new buckets called default, default_downsampled_15m and default_downsampled_1h
  3. Go into Data > Tokens and grab your access token.
  4. Edit the docker-compose.yml file and add the following environment variables in the API service to connect the API to InfluxDB:
    • INFLUXDB_TOKEN: The token from the step above
    • INFLUXDB_URL: http://influxdb
    • INFLUXDB_ORG: The organisation ID - you can find it here
    • INFLUXDB_BUCKET: default
  5. Restart docker-compose
  6. Create a new task with the following query. This will downsample your per-millisecond API request data down to 15-minute blocks for faster queries. Set it to run every 15 minutes.
option task = {name: "Downsample (API Requests)", every: 15m}

data = from(bucket: "default")
|> range(start: -duration(v: int(v: task.every) * 2))
|> filter(fn: (r) =>
(r._measurement == "api_call"))

data
|> aggregateWindow(fn: sum, every: 15m)
|> filter(fn: (r) =>
(exists r._value))
|> to(bucket: "default_downsampled_15m")

Once this task has run, you will see data coming into the Organisation API Usage area.

  1. Create another new task with the following query. This will downsample your per-millisecond flag evaluation data down to 15-minute blocks for faster queries. Set it to run every 15 minutes.
option task = {name: "Downsample (Flag Evaluations)", every: 15m}

data = from(bucket: "default")
|> range(start: -duration(v: int(v: task.every) * 2))
|> filter(fn: (r) =>
(r._measurement == "feature_evaluation"))

data
|> aggregateWindow(fn: sum, every: 15m)
|> filter(fn: (r) =>
(exists r._value))
|> to(bucket: "default_downsampled_15m")

Once this task has run, and you have made some flag evaluations with analytics enabled (see documentation here for information on this), you should see data in the 'Analytics' tab against each feature in your dashboard.

  1. Create another new task with the following query. This will downsample your per-millisecond API request data down to 1-hour blocks for faster queries. Set it to run every 1 hour.
option task = {name: "Downsample API 1h", every: 1h}

data = from(bucket: "default")
|> range(start: -duration(v: int(v: task.every) * 2))
|> filter(fn: (r) =>
(r._measurement == "api_call"))

data
|> aggregateWindow(fn: sum, every: 1h)
|> filter(fn: (r) =>
(exists r._value))
|> to(bucket: "default_downsampled_1h")
  1. Create another new task with the following query. This will downsample your per-millisecond flag evaluation data down to 1-hour blocks for faster queries. Set it to run every 1 hour.
option task = {name: "Downsample API 1h - Flag Analytics", every: 1h}

data = from(bucket: "default")
|> range(start: -duration(v: int(v: task.every) * 2))
|> filter(fn: (r) =>
(r._measurement == "feature_evaluation"))
|> filter(fn: (r) =>
(r._field == "request_count"))
|> group(columns: ["feature_id", "environment_id"])

data
|> aggregateWindow(fn: sum, every: 1h)
|> filter(fn: (r) =>
(exists r._value))
|> set(key: "_measurement", value: "feature_evaluation")
|> set(key: "_field", value: "request_count")
|> to(bucket: "default_downsampled_1h")

Kubernetes (via Helm)

By default, Flagsmith uses PostgreSQL to store time-series data. You can alternatively use InfluxDB to track:

  • SDK API traffic
  • SDK Flag Evaluations

You will need to perform the steps above to configure InfluxDB itself. You can then configure the Helm chart with the following values:

ParameterDescriptionDefault
influxdb2.enabledtrue
influxdb2.nameOverrideinfluxdb
influxdb2.image.repositoryDocker image repository for InfluxDBquay.io/influxdb/influxdb
influxdb2.image.tagDocker image tag for InfluxDBv2.0.2
influxdb2.image.imagePullPolicyIfNotPresent
influxdb2.image.imagePullSecrets[]
influxdb2.adminUser.organizationinfluxdata
influxdb2.adminUser.bucketdefault
inflxdb2.adminUser.useradmin
influxdb2.adminUser.passwordrandomly generated
influxdb2.adminUser.tokenrandomly generated
influxdb2.persistence.enabledfalse
influxdb.resourcesresources per pod for the InfluxDB{}
influxdb.nodeSelector{}
influxdb.tolerations[]
influxdb.affinity{}
influxdbExternal.enabledUse an InfluxDB not managed by this chartfalse
influxdbExternal.url
influxdbExternal.bucket
influxdbExternal.organization
influxdbExternal.token
influxdbExternal.tokenFromExistingSecret.enabledUse reference to a k8s secret not managed by this chartfalse
influxdbExternal.tokenFromExistingSecret.nameReferenced secret name
influxdbExternal.tokenFromExistingSecret.keyKey within the referenced secret to use