Skip to content

Commit aff8860

Browse files
authored
destination/influxdb3: influxdb3sink time setter update (#607)
* update in preparation for updated influxdb3sink * reorganize it and clean it up a bit * add temporary changes to test PR * tweak readme * use main instead since it's merged * change default influxdb url
1 parent 2039b13 commit aff8860

File tree

5 files changed

+33
-38
lines changed

5 files changed

+33
-38
lines changed

python/destinations/influxdb_3/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
[This connector](https://github.com/quixio/quix-samples/tree/main/python/destinations/influxdb_3) demonstrates how to consume data from a Kafka topic in Quix and persist the data to an InfluxDB v3 database using the InfluxDB write API.
44

5+
To learn more about how it functions, [check out the underlying
6+
Quix Streams `InfluxDB3Source`](https://quix.io/docs/quix-streams/connectors/sinks/influxdb3-sink.html).
7+
58
## How to run
69

710
Create a [Quix](https://portal.platform.quix.io/signup?xlink=github) account or log-in and visit the `Connectors` tab to use this connector.

python/destinations/influxdb_3/dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
FROM python:3.12.5-slim-bookworm
2-
2+
3+
# TODO: remove this RUN block when done doing "@ git+" install in requirements.txt
4+
# This should be done BEFORE merging PR
5+
RUN apt-get update && \
6+
apt-get install -y git && \
7+
apt-get clean && \
8+
rm -rf /var/lib/apt/lists/*
9+
310
# Set environment variables for non-interactive setup and unbuffered output
411
ENV DEBIAN_FRONTEND=noninteractive \
512
PYTHONUNBUFFERED=1 \

python/destinations/influxdb_3/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"Type": "EnvironmentVariable",
2727
"InputType": "FreeText",
2828
"Description": "Host address for the InfluxDB instance.",
29-
"DefaultValue": "https://eu-central-1-1.aws.cloud2.influxdata.com",
29+
"DefaultValue": "http://influxdb3:80",
3030
"Required": true
3131
},
3232
{
Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# import Utility modules
22
import os
3-
import logging
43

54
# import vendor-specific modules
65
from quixstreams import Application
@@ -10,50 +9,35 @@
109
from dotenv import load_dotenv
1110
load_dotenv()
1211

13-
logging.basicConfig(level=logging.INFO)
14-
logger = logging.getLogger(__name__)
1512

16-
# read the consumer group from config
17-
consumer_group_name = os.environ.get("CONSUMER_GROUP_NAME", "influxdb-data-writer")
18-
19-
# read the timestamp column from config
20-
timestamp_column = os.environ.get("TIMESTAMP_COLUMN") if os.environ.get("TIMESTAMP_COLUMN") else None
13+
tag_keys = keys.split(",") if (keys := os.environ.get("INFLUXDB_TAG_KEYS")) else []
14+
field_keys = keys.split(",") if (keys := os.environ.get("INFLUXDB_FIELD_KEYS")) else []
15+
measurement_name = os.environ.get("INFLUXDB_MEASUREMENT_NAME", "measurement1")
16+
time_setter = col if (col := os.environ.get("TIMESTAMP_COLUMN")) else None
2117

22-
buffer_size = int(os.environ.get("BUFFER_SIZE", "1000"))
18+
influxdb_v3_sink = InfluxDB3Sink(
19+
token=os.environ["INFLUXDB_TOKEN"],
20+
host=os.environ["INFLUXDB_HOST"],
21+
organization_id=os.environ["INFLUXDB_ORG"],
22+
tags_keys=tag_keys,
23+
fields_keys=field_keys,
24+
time_setter=time_setter,
25+
database=os.environ["INFLUXDB_DATABASE"],
26+
measurement=measurement_name,
27+
)
2328

24-
buffer_delay = float(os.environ.get("BUFFER_DELAY", "1"))
2529

26-
# Create a Quix platform-specific application instead
2730
app = Application(
28-
consumer_group=consumer_group_name,
31+
consumer_group=os.environ.get("CONSUMER_GROUP_NAME", "influxdb-data-writer"),
2932
auto_offset_reset="earliest",
30-
commit_every=buffer_size,
31-
commit_interval=buffer_delay)
32-
33+
commit_every=int(os.environ.get("BUFFER_SIZE", "1000")),
34+
commit_interval=float(os.environ.get("BUFFER_DELAY", "1")),
35+
)
3336
input_topic = app.topic(os.environ["input"])
3437

35-
# Read the environment variable and convert it to a dictionary
36-
tag_keys = os.environ.get("INFLUXDB_TAG_KEYS", "").split(",") if os.environ.get("INFLUXDB_TAG_KEYS") else []
37-
field_keys = os.environ.get("INFLUXDB_FIELD_KEYS", "").split(",")if os.environ.get("INFLUXDB_FIELD_KEYS") else []
38-
measurement_name = os.environ.get("INFLUXDB_MEASUREMENT_NAME", "measurement1")
39-
40-
influxdb_v3_sink = InfluxDB3Sink(
41-
token=os.environ["INFLUXDB_TOKEN"],
42-
host=os.environ["INFLUXDB_HOST"],
43-
organization_id=os.environ["INFLUXDB_ORG"],
44-
tags_keys=tag_keys,
45-
fields_keys=field_keys,
46-
time_key=timestamp_column,
47-
database=os.environ["INFLUXDB_DATABASE"],
48-
measurement=measurement_name)
49-
5038
sdf = app.dataframe(input_topic)
51-
52-
#sdf.print()
5339
sdf.sink(influxdb_v3_sink)
5440

41+
5542
if __name__ == "__main__":
56-
logger.info("Starting application")
5743
app.run()
58-
59-
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
quixstreams[influxdb3]==3.8.1
1+
# TODO: remove "@ git+" version of install before merging PR
2+
quixstreams[influxdb3] @ git+https://github.com/quixio/quix-streams.git
23
python-dotenv

0 commit comments

Comments
 (0)