-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Milestone
Description
Use InfluxDB 3 Core
Overview
Migrate the IoT API sample application from InfluxDB 2.x to InfluxDB 3 Core using the @influxdata/influxdb3-client JavaScript client library.
Phase 1: Core Migration ✅
Environment Changes
| Variable | New Value | Replaces |
|---|---|---|
| INFLUX_HOST | http://localhost:8181 | INFLUX_URL |
| INFLUX_DATABASE | iot_center | INFLUX_BUCKET |
| INFLUX_DATABASE_AUTH | iot_center_devices | INFLUX_BUCKET_AUTH |
| INFLUX_TOKEN | Admin token | Same |
| Removed | Not used in InfluxDB 3 |
References
- InfluxDB 3 Core Documentation
- InfluxDB 3 JavaScript Client
- Query data with SQL
- Last Value Cache
- Processing Engine
Related
- PR feat: migrate to InfluxDB 3 Core with influxdb3-javascript client #18: Initial migration implementation
- Branch:
claude/influxdb3-migration-v3-pMqwy
Overview
Migrate the IoT API sample application from InfluxDB 2.x to InfluxDB 3 Core using the @influxdata/influxdb3-client JavaScript client library.
Phase 1: Core Migration ✅
Environment Changes
| Variable | New Value | Replaces |
|---|---|---|
INFLUX_HOST |
http://localhost:8181 |
INFLUX_URL |
INFLUX_DATABASE |
iot_center |
INFLUX_BUCKET |
INFLUX_DATABASE_AUTH |
iot_center_devices |
INFLUX_BUCKET_AUTH |
INFLUX_TOKEN |
Admin token | Same |
INFLUX_ORG |
Removed | Not used in InfluxDB 3 |
Client Library Migration
- Replace
@influxdata/influxdb-clientwith@influxdata/influxdb3-clientv2.0.0 - Use
InfluxDBClientclass with{ host, token }configuration - Use
Pointclass for line protocol construction - Use
client.query(sql, database)for SQL queries - Use
client.write(data, database)for writes
Query Language Migration
- Convert all Flux queries to SQL
- InfluxDB 3 Core supports SQL queries only (no Flux)
- Query limit: Last 72 hours of data (Core limitation)
Authentication Changes
- InfluxDB 3 Core does not have the Authorizations API
- Implement application-level device tokens stored in
iot_center_devicesdatabase - Generate tokens using
crypto.randomBytes(32).toString('hex') - Store device credentials as line protocol with
deviceauthmeasurement
API Endpoints Migrated
-
GET /api/devices- List all devices (SQL query) -
GET /api/devices/:deviceId- Get single device (SQL query with parameter) -
POST /api/devices/create- Create device with application token -
GET /api/measurements- Query telemetry data (SQL query)
Phase 2: Core Enhancements
Last Value Cache (LVC)
Sub-10ms query performance for latest device readings.
influxdb3 create last_cache \
--database iot_center \
--table environment \
--key-columns deviceId \
--value-columns Temperature,Humidity,Pressure,CO2Use case: Real-time dashboard showing current sensor values for all devices.
Distinct Value Cache (DVC)
Fast metadata lookups without full table scans.
influxdb3 create distinct_cache \
--database iot_center \
--table environment \
--columns deviceId,deviceType,locationUse case: Populate device filter dropdowns, list available locations.
Processing Engine
Python plugins for data processing triggered by WAL writes, schedules, or HTTP requests.
Example: Temperature Alert Plugin
# temperature_alert.py
def process_writes(influxdb3_local, table_batches, args):
for table_batch in table_batches:
if table_batch["table_name"] == "environment":
for row in table_batch["rows"]:
if row.get("Temperature", 0) > args.get("threshold", 30):
influxdb3_local.write(
f'alerts,deviceId={row["deviceId"]},type=temperature '
f'value={row["Temperature"]},message="High temperature"'
)Use cases:
- Temperature threshold alerts (WAL trigger)
- Daily device health summary (scheduled)
- On-demand data aggregation (HTTP request)
Technical Notes
InfluxDB 3 Core Limitations
| Limitation | Description |
|---|---|
| Query window | Last 72 hours only |
| Authentication | No resource tokens (use application-level auth) |
| Availability | Single node only |
| Processing Engine | Python plugins only |
Data Model Changes
| InfluxDB 3 | InfluxDB 2.x |
|---|---|
| Database | Bucket |
| Table | Measurement |
| Tags | Tags |
| Fields | Fields |
References
- [InfluxDB 3 Core Documentation](https://docs.influxdata.com/influxdb3/core/)
- [InfluxDB 3 JavaScript Client](https://github.com/InfluxCommunity/influxdb3-js)
- [Query data with SQL](https://docs.influxdata.com/influxdb3/core/query-data/sql/)
- [Last Value Cache](https://docs.influxdata.com/influxdb3/core/query-data/last-value-cache/)
- [Processing Engine](https://docs.influxdata.com/influxdb3/core/process-data/process-engine/)
Related
- PR feat: migrate to InfluxDB 3 Core with influxdb3-javascript client #18: Initial migration implementation
- Branch:
claude/influxdb3-migration-v3-pMqwy
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels