Skip to content

Commit dc0c9fe

Browse files
committed
chore(monolith): Update installing and configuring plugins:
Updates the guide and examples for using the latest influxdb3 install command. Provides more Docker-specific examples. Cleanup.
1 parent 3abf1c5 commit dc0c9fe

File tree

3 files changed

+135
-53
lines changed

3 files changed

+135
-53
lines changed

content/influxdb3/core/query-data/sql/parameterized-queries.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ list_code_example: |
3232
// Call the client's function to query InfluxDB with parameters.
3333
iterator, err := client.QueryWithParameters(context.Background(), query, parameters)
3434
```
35-
# Leaving in draft until tested
36-
draft: true
3735
source: /shared/influxdb3-query-guides/sql/parameterized-queries.md
3836
---
3937

4038
<!--
41-
The content for this page is at content/shared/influxdb3-query-guides/sql/parameterized-queries.md
39+
The content for this page is at
40+
//SOURCE content/shared/influxdb3-query-guides/sql/parameterized-queries.md
4241
-->

content/influxdb3/enterprise/query-data/sql/parameterized-queries.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ list_code_example: |
3232
// Call the client's function to query InfluxDB with parameters.
3333
iterator, err := client.QueryWithParameters(context.Background(), query, parameters)
3434
```
35-
# Leaving in draft until tested
36-
draft: true
3735
source: /shared/influxdb3-query-guides/sql/parameterized-queries.md
3836
---
3937

4038
<!--
41-
The content for this page is at content/shared/influxdb3-query-guides/sql/parameterized-queries.md
39+
The content for this page is at
40+
//SOURCE content/shared/influxdb3-query-guides/sql/parameterized-queries.md
4241
-->

content/shared/v3-core-plugins/_index.md

Lines changed: 131 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,69 @@
33
>
44
> The Processing engine is currently supported only in Docker x86 environments. Non-Docker support is coming soon. The engine, API, and developer experience are actively evolving and may change. Join our [Discord](https://discord.gg/9zaNCW2PRT) for updates and feedback.
55
6-
InfluxDB 3 has an embedded Python VM for dynamically loading plugins that can execute code in the database. There are four types of plugins that can be triggered by the following events in the database:
6+
Use the {{% product-name %}} Processing engine to run code and perform tasks
7+
for different database events.
78

8-
* **WAL flush**: Triggered when the write-ahead log (WAL) is flushed to object store (once a second by default)
9-
* **Parquet persistenc (coming soon)**: Triggered when data is persisted to object store in Parquet format
10-
* **Scheduled tasks**: Triggered by a schedule, specified in cron sytnax
11-
* **On Request**: Bind to a specific endpoint under `/api/v3/engine` and trigger when GET or POST requests are made
9+
{{% product-name %}} provides the InfluxDB 3 Processing engine, an embedded Python VM that can dynamically load and trigger Python plugins
10+
in response to events in your database.
1211

13-
Each plugin type has a different trigger configuration, which will be described in the section on each plugin type.
12+
## Plugins
1413

15-
When starting the server, the argument `--plugin-dir` must be provided that specifies what directory plugins are located in. There is also a public Github repository of example plugins that can be referenced when creating a trigger. The repository at [https://github.com/influxdata/influxdb3_plugins](https://github.com/influxdata/influxdb3_plugins) contans example plugins and contributions from the community.
14+
> [!Note]
15+
> #### Contribute and use community plugins
16+
>
17+
> [influxdata/influxdb3_plugins](https://github.com/influxdata/influxdb3_plugins) is a public repository on GitHub where you can find
18+
> and contribute example plugins.
19+
> You can reference plugins from the repository directly within a trigger configuration.
20+
21+
A Processing engine _plugin_ is Python code you provide to run tasks, such as
22+
downsampling data, monitoring, creating alerts, or calling external services.
23+
24+
## Triggers
25+
26+
A _trigger_ is an InfluxDB 3 resource you create to associate a database
27+
event (for example, a WAL flush) with the plugin that should run.
28+
When an event occurs, the trigger passes configuration, optional arguments, and event data to the plugin.
29+
30+
The Processing engine provides four types of plugins and triggers--each type corresponds to an event type with event-specific configuration to let you handle events with targeted logic.
31+
32+
- **WAL flush**: Triggered when the write-ahead log (WAL) is flushed to the object store (default is every second)
33+
- **Parquet persistence (coming soon)**: Triggered when InfluxDB 3 persists data to object store Parquet files
34+
- **Scheduled tasks**: Triggered on a schedule you specify using cron syntax
35+
- **On Request**: Bound to the HTTP API `/api/v3/engine/<CUSTOM_PATH>` endpoint and triggered by a GET or POST request to the endpoint.
36+
37+
## Activate the Processing engine
38+
To enable the Processing engine, start the {{% product-name %}} server with the --plugin-dir argument and a path to your plugins directory (it doesn't need to exist yet)--for example:
39+
40+
```bash
41+
influxdb3 serve --node-id node0 --plugin-dir /path/to/plugins
42+
```
1643

1744
## Shared API
1845

19-
Within any of the plugin types, a shared API is available to interact with the database. The shared API provides access to the following:
20-
* `LineBuilder` to create Line Protocol lines that can be written to the database
21-
* `query` to query data from any database
22-
* `info`, `warn`, and `error` to log messages to the database log, which will be output in the server logs and captured in system tables queryable by SQL
46+
All plugin types provide the InfluxDB 3 _shared API_ for interacting with the database.
47+
The shared API provides access to the following:
2348

24-
### Line Builder
49+
- `LineBuilder` to create Line Protocol lines for writing to the database
50+
- `query` to query data from any database
51+
- `info`, `warn`, and `error` to log messages to the database log, which is output in the server logs and captured in system tables queryable by SQL
2552

26-
The `LineBuilder` is a simple API for building lines of Line Protocol to write into the database. Writes are buffered while the plugin runs and are flushed when the plugin completes. The `LineBuilder` API is available in all plugin types. Here are some examples of using the `LineBuilder` API:
53+
### Line builder
2754

28-
```python
29-
line = LineBuilder("weather")
30-
.tag("location", "us-midwest")
31-
.float64_field("temperature", 82.5)
32-
.time_ns(1627680000000000000)
33-
influxdb3_local.write(line)
55+
The `LineBuilder` is a simple API for building lines of Line Protocol to write into the database. Writes are buffered while the plugin runs and are flushed when the plugin completes. The `LineBuilder` API is available in all plugin types.
3456

35-
# to output it as a string: "weather,location=us-midwest temperature=82.5 1627680000000000000"
36-
line_str = line.build()
57+
The following example shows how to use the `LineBuilder` API:
3758

38-
# or build incrementally
59+
```python
60+
# Build line protocol incrementally
3961
line = LineBuilder("weather")
4062
line.tag("location", "us-midwest")
4163
line.float64_field("temperature", 82.5)
4264
line.time_ns(1627680000000000000)
4365
influxdb3_local.write(line)
66+
67+
# Output line protocol as a string ("weather,location=us-midwest temperature=82.5 1627680000000000000")
68+
line_str = line.build()
4469
```
4570

4671
Here is the Python implementation of the `LineBuilder` API:
@@ -160,32 +185,47 @@ class LineBuilder:
160185
```
161186

162187
### Query
163-
The `query` function on the API will execute a SQL query with optional parameters (through a parameterized query) and return the results as a `List` of `Dict[String, Any]` where the key is the column name and the value is the value for that column. The `query` function is available in all plugin types.
164188

165-
Some examples:
189+
The shared API `query` function executes an SQL query with optional parameters (a [parameterized query](/influxdb3/version/query-data/sql/parameterized-queries/)) and returns results as a `List` of `Dict[String, Any]` where the key is the column name and the value is the column value. The `query` function is available in all plugin types.
190+
191+
The following examples show how to use the `query` function:
166192

167193
```python
168194
influxdb3_local.query("SELECT * from foo where bar = 'baz' and time > now() - 'interval 1 hour'")
169195

170-
# or using parameterized queries
196+
# Or using parameterized queries
171197
args = {"bar": "baz"}
172198
influxdb3_local.query("SELECT * from foo where bar = $bar and time > now() - 'interval 1 hour'", args)
173199
```
174200

175201
### Logging
176-
The `info`, `warn`, and `error` functions on the API will log messages to the database log, which will be output in the server logs and captured in system tables queryable by SQL. The `info`, `warn`, and `error` functions are available in all plugin types. The functions take an arbitrary number of arguments and will convert them to strings and join them into a single message separated by a space. Examples:
202+
203+
The shared API `info`, `warn`, and `error` functions log messages to the database log, which is output in the server logs and captured in system tables queryable by SQL.
204+
The `info`, `warn`, and `error` functions are available in all plugin types. The functions take an arbitrary number of arguments, convert them to strings, and then join them into a single message separated by a space.
205+
206+
The following examples show to use the `info`, `warn`, and `error` logging functions:
177207

178208
```python
179209
ifluxdb3_local.info("This is an info message")
180210
influxdb3_local.warn("This is a warning message")
181211
influxdb3_local.error("This is an error message")
182212

213+
# Log a message that contains a data object
183214
obj_to_log = {"hello": "world"}
184215
influxdb3_local.info("This is an info message with an object", obj_to_log)
185216
```
186217

187218
### Trigger arguments
188-
Every plugin type can receive arguments from the configuration of the trigger. This is useful for passing configuration to the plugin. This can drive behavior like things to monitor for or it could be connection information to third party services that the plugin will interact with. The arguments are passed as a `Dict[str, str]` where the key is the argument name and the value is the argument value. Here's an example of how to use arguments in a WAL plugin:
219+
220+
Every plugin type can receive arguments from the configuration of the trigger that runs it.
221+
You can use this to provide runtime configuration and drive behavior of a plugin--for example:
222+
223+
- threshold values for monitoring
224+
- connection properties for connecting to third-party services
225+
226+
The arguments are passed as a `Dict[str, str]` where the key is the argument name and the value is the argument value.
227+
228+
The following example shows how to use an argument in a WAL plugin:
189229

190230
```python
191231
def process_writes(influxdb3_local, table_batches, args=None):
@@ -196,28 +236,66 @@ def process_writes(influxdb3_local, table_batches, args=None):
196236
influxdb3_local.warn("No threshold provided")
197237
```
198238

199-
The `args` parameter is optional and can be omitted from the trigger definitions if the plugin does not need to use arguments.
239+
The `args` parameter is optional and can be omitted from the trigger definition if the plugin doesn't need to use arguments.
200240

201-
## Imports
202-
The Python plugins run using the system Python in the Docker container. Pip is installed in the container and can be used to install any dependencies.
203-
You will need to start up the server with the `PYTHONPATH` set to the location of your site packages for your virtual environment. For example: `PYTHONPATH=myenvl/lib/python3.13/site-packages`
241+
## Import plugin dependencies
204242

205-
## WAL Flush Plugin
206-
When a WAL flush plugin is triggered, the plugin will receive a list of `table_batches` that have matched the plugin trigger (either all tables in the database or a specific table). Here's an example of a simple WAL flush plugin
243+
Use the `influxdb3 install` command to download and install Python packages that your plugin depends on.
244+
245+
```bash
246+
influxdb3 install package <PACKAGE_NAME>
247+
248+
### Use `influxdb3 install` with Docker
249+
250+
1. Start the server
251+
252+
```bash
253+
docker run \
254+
--name CONTAINER_NAME \
255+
-v /path/to/.influxdb3/data:/data \
256+
-v /path/to/.influxdb3/plugins:/plugins \
257+
quay.io/influxdb/influxdb3-core:latest \
258+
serve --node-id=node0 \
259+
--object-store=file \
260+
--data-dir=/data \
261+
--http-bind=localhost:8183 \
262+
--plugin-dir=/plugins
263+
```
264+
265+
2. Use `docker exec` to run the `influxdb3 install` command:
266+
267+
```bash
268+
docker exec -it CONTAINER_NAME influxdb3 install package pandas
269+
```
270+
271+
The result is an active Python virtual environment with the package installed in `<PLUGINS_DIR>/.venv`.
272+
You can pass additional options to use a `requirements.txt` file or a custom virtual environment path.
273+
For more information, see the `influxdb3` CLI help:
274+
275+
```bash
276+
influxdb3 install package --help
277+
```
278+
279+
## WAL flush plugin
280+
281+
When a WAL flush plugin is triggered, the plugin receives a list of `table_batches` filtered by the trigger configuration (either _all tables_ in the database or a specific table).
282+
283+
The following example shows a simple WAL flush plugin:
207284

208285
```python
209286
def process_writes(influxdb3_local, table_batches, args=None):
210287
for table_batch in table_batches:
211-
# Skip if table_name is write_reports
288+
# Skip the batch if table_name is write_reports
212289
if table_batch["table_name"] == "write_reports":
213290
continue
214291
215292
row_count = len(table_batch["rows"])
216293
217-
# Double row count if table name matches args table_name
294+
# Double the row count if table name matches args table_name
218295
if args and "double_count_table" in args and table_batch["table_name"] == args["double_count_table"]:
219296
row_count *= 2
220297
298+
# Use the LineBuilder API to write data
221299
line = LineBuilder("write_reports")\
222300
.tag("table_name", table_batch["table_name"])\
223301
.int64_field("row_count", row_count)
@@ -226,27 +304,33 @@ def process_writes(influxdb3_local, table_batches, args=None):
226304
influxdb3_local.info("wal_plugin.py done")
227305
```
228306
229-
### WAL Flush Trigger Configuration
307+
### WAL flush trigger Configuration
230308
231-
Every trigger is associated with a specific database. The best reference for the arguments for trigger definition can be accessed through the CLI help:
309+
When you create a trigger, you associate it with a database and provide configuration specific to the trigger type.
232310
233-
```shell
234-
influxdb3 create trigger help
235-
```
311+
For a WAL flush trigger you specify a `trigger-spec`, which determines when the plugin is triggered (and what table data it receives):
236312
237-
For the WAL plugin, the `trigger-spec` can be either `all-tables` which will trigger on any write to the assoicated database or `table:<table_name>` which will call the `process_writes` function only with the writes for the given table. The trigger-spec is what the server uses to determine which plugin type the plugin-filename points to.
313+
- `all-tables`: triggers the plugin on every write to the associated database
314+
- `table:<table_name>` triggers the plugin function only for writes to the specified table.
238315
239-
The `args` parameter can be used to pass configuration to the plugin.
316+
The following example creates a WAL flush trigger for the `gh:examples/wal_plugin/wal_plugin.py` plugin.
240317
241-
For example, if creating a trigger of WAL flush from the examples repo:
242-
243-
```shell
244-
influxdb3 create trigger --trigger-spec "table:foo" --plugin-filename "gh:examples/wal_plugin/wal_plugin.py" --database mydb foo-trigger
318+
```bash
319+
influxdb3 create trigger --trigger-spec "table:TABLE_NAME" --plugin-filename "gh:examples/wal_plugin/wal_plugin.py" --database DATABASE_NAME TRIGGER_NAME
245320
```
246321
247-
Without the `gh:` at the start of the filename, the server will look for the file in its plugin directory.
322+
The `gh:` prefix lets you fetch a plugin file directly from the [influxdata/influxdb3_plugins](https://github.com/influxdata/influxdb3_plugins) repository in GitHub.
323+
Without the prefix, the server looks for the file inside of the plugins directory.
324+
325+
To provide additional configuration to your plugin, pass a list of key-value pairs in the `--trigger-arguments` option and, in your plugin, use the `args` parameter to receive the arguments.
326+
For more information about trigger arguments, see the CLI help:
327+
328+
```bash
329+
influxdb3 create trigger help
330+
```
248331
249332
## Schedule Plugin
333+
250334
Schedule plugins run on a schedule specified in cron syntax. The plugin will receive the local API, the time of the trigger, and any arguments passed in the trigger definition. Here's an example of a simple schedule plugin:
251335
252336
```python

0 commit comments

Comments
 (0)