fix(clustered): Clustered Telegraf config and example:

- Mount a volume to store test project files generated in tests.
- Allow URL and `url` in the linter
- Set timestamp precision for Telegraf example
- Fix Telegraf test, use Python to edit the TOML config file
pull/5505/head
Jason Stirnaman 2024-07-02 22:21:05 -05:00
parent 9e5f346636
commit 8f0e583cdc
5 changed files with 154 additions and 122 deletions

View File

@ -82,6 +82,5 @@ swap:
tablename: table name tablename: table name
tablet: device tablet: device
touch: tap touch: tap
url: URL
vs\.: versus vs\.: versus
World Wide Web: web World Wide Web: web

View File

@ -72,6 +72,8 @@ quoteChar
retentionRules retentionRules
sourceBucket sourceBucket
tagKey tagKey
`url[s]?`
URL
v2 v2
v3 v3
venv venv

View File

@ -34,6 +34,13 @@ function pytestStagedContent(paths, productPath) {
`docker build . `docker build .
-f Dockerfile.pytest -f Dockerfile.pytest
-t influxdata-docs/pytest:latest`, -t influxdata-docs/pytest:latest`,
// Create a Docker volume for temporary files generated during testing
`sh -c "docker volume create \
--label tag=influxdata-docs \
--label stage=test \
--name test-tmp || true"`,
// Run test runners. // Run test runners.
// Uses a pytest plugin to suppress exit code 5 (if no tests are found), // Uses a pytest plugin to suppress exit code 5 (if no tests are found),
@ -49,6 +56,7 @@ function pytestStagedContent(paths, productPath) {
--env-file ${productPath}/.env.test \ --env-file ${productPath}/.env.test \
--volumes-from ${CONTENT} \ --volumes-from ${CONTENT} \
--mount type=bind,src=./test/shared,dst=/shared \ --mount type=bind,src=./test/shared,dst=/shared \
--mount type=volume,source=test-tmp,target=/app/iot-starter \
influxdata-docs/pytest --codeblocks --suppress-no-test-exit-code --exitfirst ${productPath}/`, influxdata-docs/pytest --codeblocks --suppress-no-test-exit-code --exitfirst ${productPath}/`,
]; ];
} }

View File

@ -204,32 +204,32 @@ influxctl write \
--database get-started \ --database get-started \
--token $INFLUX_TOKEN \ --token $INFLUX_TOKEN \
--precision s \ --precision s \
'home,room=Living\ Room temp=21.1,hum=35.9,co=0i 1641024000 'home,room=Living\ Room temp=21.1,hum=35.9,co=0i 1719734400
home,room=Kitchen temp=21.0,hum=35.9,co=0i 1641024000 home,room=Kitchen temp=21.0,hum=35.9,co=0i 1719734400
home,room=Living\ Room temp=21.4,hum=35.9,co=0i 1641027600 home,room=Living\ Room temp=21.4,hum=35.9,co=0i 1719738000
home,room=Kitchen temp=23.0,hum=36.2,co=0i 1641027600 home,room=Kitchen temp=23.0,hum=36.2,co=0i 1719738000
home,room=Living\ Room temp=21.8,hum=36.0,co=0i 1641031200 home,room=Living\ Room temp=21.8,hum=36.0,co=0i 1719741600
home,room=Kitchen temp=22.7,hum=36.1,co=0i 1641031200 home,room=Kitchen temp=22.7,hum=36.1,co=0i 1719741600
home,room=Living\ Room temp=22.2,hum=36.0,co=0i 1641034800 home,room=Living\ Room temp=22.2,hum=36.0,co=0i 1719745200
home,room=Kitchen temp=22.4,hum=36.0,co=0i 1641034800 home,room=Kitchen temp=22.4,hum=36.0,co=0i 1719745200
home,room=Living\ Room temp=22.2,hum=35.9,co=0i 1641038400 home,room=Living\ Room temp=22.2,hum=35.9,co=0i 1719748800
home,room=Kitchen temp=22.5,hum=36.0,co=0i 1641038400 home,room=Kitchen temp=22.5,hum=36.0,co=0i 1719748800
home,room=Living\ Room temp=22.4,hum=36.0,co=0i 1641042000 home,room=Living\ Room temp=22.4,hum=36.0,co=0i 1719752400
home,room=Kitchen temp=22.8,hum=36.5,co=1i 1641042000 home,room=Kitchen temp=22.8,hum=36.5,co=1i 1719752400
home,room=Living\ Room temp=22.3,hum=36.1,co=0i 1641045600 home,room=Living\ Room temp=22.3,hum=36.1,co=0i 1719756000
home,room=Kitchen temp=22.8,hum=36.3,co=1i 1641045600 home,room=Kitchen temp=22.8,hum=36.3,co=1i 1719756000
home,room=Living\ Room temp=22.3,hum=36.1,co=1i 1641049200 home,room=Living\ Room temp=22.3,hum=36.1,co=1i 1719759600
home,room=Kitchen temp=22.7,hum=36.2,co=3i 1641049200 home,room=Kitchen temp=22.7,hum=36.2,co=3i 1719759600
home,room=Living\ Room temp=22.4,hum=36.0,co=4i 1641052800 home,room=Living\ Room temp=22.4,hum=36.0,co=4i 1719763200
home,room=Kitchen temp=22.4,hum=36.0,co=7i 1641052800 home,room=Kitchen temp=22.4,hum=36.0,co=7i 1719763200
home,room=Living\ Room temp=22.6,hum=35.9,co=5i 1641056400 home,room=Living\ Room temp=22.6,hum=35.9,co=5i 1719766800
home,room=Kitchen temp=22.7,hum=36.0,co=9i 1641056400 home,room=Kitchen temp=22.7,hum=36.0,co=9i 1719766800
home,room=Living\ Room temp=22.8,hum=36.2,co=9i 1641060000 home,room=Living\ Room temp=22.8,hum=36.2,co=9i 1719770400
home,room=Kitchen temp=23.3,hum=36.9,co=18i 1641060000 home,room=Kitchen temp=23.3,hum=36.9,co=18i 1719770400
home,room=Living\ Room temp=22.5,hum=36.3,co=14i 1641063600 home,room=Living\ Room temp=22.5,hum=36.3,co=14i 1719774000
home,room=Kitchen temp=23.1,hum=36.6,co=22i 1641063600 home,room=Kitchen temp=23.1,hum=36.6,co=22i 1719774000
home,room=Living\ Room temp=22.2,hum=36.4,co=17i 1641067200 home,room=Living\ Room temp=22.2,hum=36.4,co=17i 1719777600
home,room=Kitchen temp=22.7,hum=36.5,co=26i 1641067200' home,room=Kitchen temp=22.7,hum=36.5,co=26i 1719777600'
``` ```
{{% /code-placeholders %}} {{% /code-placeholders %}}
@ -258,47 +258,48 @@ and then write it to {{< product-name >}}.
```sh ```sh
cat <<- EOF > home.lp cat <<- EOF > home.lp
home,room=Living\ Room temp=21.1,hum=35.9,co=0i 1641024000 home,room=Living\ Room temp=21.1,hum=35.9,co=0i 1719820800
home,room=Kitchen temp=21.0,hum=35.9,co=0i 1641024000 home,room=Kitchen temp=21.0,hum=35.9,co=0i 1719820800
home,room=Living\ Room temp=21.4,hum=35.9,co=0i 1641027600 home,room=Living\ Room temp=21.4,hum=35.9,co=0i 1719824400
home,room=Kitchen temp=23.0,hum=36.2,co=0i 1641027600 home,room=Kitchen temp=23.0,hum=36.2,co=0i 1719824400
home,room=Living\ Room temp=21.8,hum=36.0,co=0i 1641031200 home,room=Living\ Room temp=21.8,hum=36.0,co=0i 1719828000
home,room=Kitchen temp=22.7,hum=36.1,co=0i 1641031200 home,room=Kitchen temp=22.7,hum=36.1,co=0i 1719828000
home,room=Living\ Room temp=22.2,hum=36.0,co=0i 1641034800 home,room=Living\ Room temp=22.2,hum=36.0,co=0i 1719831600
home,room=Kitchen temp=22.4,hum=36.0,co=0i 1641034800 home,room=Kitchen temp=22.4,hum=36.0,co=0i 1719831600
home,room=Living\ Room temp=22.2,hum=35.9,co=0i 1641038400 home,room=Living\ Room temp=22.2,hum=35.9,co=0i 1719835200
home,room=Kitchen temp=22.5,hum=36.0,co=0i 1641038400 home,room=Kitchen temp=22.5,hum=36.0,co=0i 1719835200
home,room=Living\ Room temp=22.4,hum=36.0,co=0i 1641042000 home,room=Living\ Room temp=22.4,hum=36.0,co=0i 1719838800
home,room=Kitchen temp=22.8,hum=36.5,co=1i 1641042000 home,room=Kitchen temp=22.8,hum=36.5,co=1i 1719838800
home,room=Living\ Room temp=22.3,hum=36.1,co=0i 1641045600 home,room=Living\ Room temp=22.3,hum=36.1,co=0i 1719842400
home,room=Kitchen temp=22.8,hum=36.3,co=1i 1641045600 home,room=Kitchen temp=22.8,hum=36.3,co=1i 1719842400
home,room=Living\ Room temp=22.3,hum=36.1,co=1i 1641049200 home,room=Living\ Room temp=22.3,hum=36.1,co=1i 1719846000
home,room=Kitchen temp=22.7,hum=36.2,co=3i 1641049200 home,room=Kitchen temp=22.7,hum=36.2,co=3i 1719846000
home,room=Living\ Room temp=22.4,hum=36.0,co=4i 1641052800 home,room=Living\ Room temp=22.4,hum=36.0,co=4i 1719849600
home,room=Kitchen temp=22.4,hum=36.0,co=7i 1641052800 home,room=Kitchen temp=22.4,hum=36.0,co=7i 1719849600
home,room=Living\ Room temp=22.6,hum=35.9,co=5i 1641056400 home,room=Living\ Room temp=22.6,hum=35.9,co=5i 1719853200
home,room=Kitchen temp=22.7,hum=36.0,co=9i 1641056400 home,room=Kitchen temp=22.7,hum=36.0,co=9i 1719853200
home,room=Living\ Room temp=22.8,hum=36.2,co=9i 1641060000 home,room=Living\ Room temp=22.8,hum=36.2,co=9i 1719856800
home,room=Kitchen temp=23.3,hum=36.9,co=18i 1641060000 home,room=Kitchen temp=23.3,hum=36.9,co=18i 1719856800
home,room=Living\ Room temp=22.5,hum=36.3,co=14i 1641063600 home,room=Living\ Room temp=22.5,hum=36.3,co=14i 1719860400
home,room=Kitchen temp=23.1,hum=36.6,co=22i 1641063600 home,room=Kitchen temp=23.1,hum=36.6,co=22i 1719860400
home,room=Living\ Room temp=22.2,hum=36.4,co=17i 1641067200 home,room=Living\ Room temp=22.2,hum=36.4,co=17i 1719864000
home,room=Kitchen temp=22.7,hum=36.5,co=26i 1641067200 home,room=Kitchen temp=22.7,hum=36.5,co=26i 1719864000
EOF EOF
``` ```
3. Run the following command to generate a Telegraf configuration file 3. Run the following command to generate a Telegraf configuration file
(`./telegraf.conf`) that enables the `inputs.file` and `outputs.influxdb_v2` (`telegraf.conf`) that enables the `inputs.file` and `outputs.influxdb_v2`
plugins: plugins:
```sh ```sh
telegraf --sample-config \ mkdir -p iot-project \
&& telegraf --sample-config \
--input-filter file \ --input-filter file \
--output-filter influxdb_v2 \ --output-filter influxdb_v2 \
> telegraf.conf > iot-project/telegraf.conf
``` ```
4. In your editor, open `./telegraf.conf` and configure the following: 4. In your editor, open `iot-project/telegraf.conf` and configure the following:
- **`file` input plugin**: In the `[[inputs.file]].files` list, replace - **`file` input plugin**: In the `[[inputs.file]].files` list, replace
`"/tmp/metrics.out"` with your sample data filename. If Telegraf can't `"/tmp/metrics.out"` with your sample data filename. If Telegraf can't
@ -309,12 +310,28 @@ and then write it to {{< product-name >}}.
## Files to parse each interval. Accept standard unix glob matching rules, ## Files to parse each interval. Accept standard unix glob matching rules,
## as well as ** to match recursive files and directories. ## as well as ** to match recursive files and directories.
files = ["home.lp"] files = ["home.lp"]
# Set the timestamp precision to the precision in your data.
influx_timestamp_precision = '1s'
## Optionally, use the newer, more efficient line protocol parser
influx_parser_type = 'upstream'
``` ```
<!--test <!--test
```bash ```python
echo '[[inputs.file]]' > telegraf.conf import toml
echo ' files = ["home.lp"]' >> telegraf.conf
# Load the TOML file
with open('iot-project/telegraf.conf', 'r') as f:
data = toml.load(f)
# Modify the file content
data['inputs']['file'][0]['files'] = ['home.lp']
data['inputs']['file'][0]['influx_parser_type'] = 'upstream'
data['inputs']['file'][0]['influx_timestamp_precision'] = '1s'
# Write the modified data back to the file
with open('iot-project/telegraf.conf', 'w') as f:
toml.dump(data, f)
``` ```
--> -->
@ -338,15 +355,20 @@ and then write it to {{< product-name >}}.
``` ```
<!--test <!--test
```bash ```python
echo '[[outputs.influxdb_v2]]' >> telegraf.conf import toml
echo ' urls = ["${INFLUX_HOST}"]' >> telegraf.conf
echo '' >> telegraf.conf with open('iot-project/telegraf.conf', 'r') as f:
echo ' token = "${INFLUX_TOKEN}"' >> telegraf.conf data = toml.load(f)
echo '' >> telegraf.conf
echo ' organization = ""' >> telegraf.conf # Modify the file content
echo '' >> telegraf.conf data['outputs']['influxdb_v2'][0]['urls'] = [f"$INFLUX_HOST"]
echo ' bucket = "get-started"' >> telegraf.conf data['outputs']['influxdb_v2'][0]['token'] = f"$INFLUX_TOKEN"
data['outputs']['influxdb_v2'][0]['organization'] = ''
data['outputs']['influxdb_v2'][0]['bucket'] = 'get-started'
# Write the modified data back to the file
with open('iot-project/telegraf.conf', 'w') as f:
toml.dump(data, f)
``` ```
--> -->
@ -367,7 +389,7 @@ and then write it to {{< product-name >}}.
Enter the following command in your terminal: Enter the following command in your terminal:
```sh ```sh
telegraf --once --config ./telegraf.conf telegraf --once --config iot-project/telegraf.conf
``` ```
If the write is successful, the output is similar to the following: If the write is successful, the output is similar to the following:
@ -445,32 +467,32 @@ response=$(curl --silent --write-out "%{response_code}:-%{errormsg}" \
--header "Content-type: text/plain; charset=utf-8" \ --header "Content-type: text/plain; charset=utf-8" \
--header "Accept: application/json" \ --header "Accept: application/json" \
--data-binary " --data-binary "
home,room=Living\ Room temp=21.1,hum=35.9,co=0i 1641024000 home,room=Living\ Room temp=21.1,hum=35.9,co=0i 1719734400
home,room=Kitchen temp=21.0,hum=35.9,co=0i 1641024000 home,room=Kitchen temp=21.0,hum=35.9,co=0i 1719734400
home,room=Living\ Room temp=21.4,hum=35.9,co=0i 1641027600 home,room=Living\ Room temp=21.4,hum=35.9,co=0i 1719738000
home,room=Kitchen temp=23.0,hum=36.2,co=0i 1641027600 home,room=Kitchen temp=23.0,hum=36.2,co=0i 1719738000
home,room=Living\ Room temp=21.8,hum=36.0,co=0i 1641031200 home,room=Living\ Room temp=21.8,hum=36.0,co=0i 1719741600
home,room=Kitchen temp=22.7,hum=36.1,co=0i 1641031200 home,room=Kitchen temp=22.7,hum=36.1,co=0i 1719741600
home,room=Living\ Room temp=22.2,hum=36.0,co=0i 1641034800 home,room=Living\ Room temp=22.2,hum=36.0,co=0i 1719745200
home,room=Kitchen temp=22.4,hum=36.0,co=0i 1641034800 home,room=Kitchen temp=22.4,hum=36.0,co=0i 1719745200
home,room=Living\ Room temp=22.2,hum=35.9,co=0i 1641038400 home,room=Living\ Room temp=22.2,hum=35.9,co=0i 1719748800
home,room=Kitchen temp=22.5,hum=36.0,co=0i 1641038400 home,room=Kitchen temp=22.5,hum=36.0,co=0i 1719748800
home,room=Living\ Room temp=22.4,hum=36.0,co=0i 1641042000 home,room=Living\ Room temp=22.4,hum=36.0,co=0i 1719752400
home,room=Kitchen temp=22.8,hum=36.5,co=1i 1641042000 home,room=Kitchen temp=22.8,hum=36.5,co=1i 1719752400
home,room=Living\ Room temp=22.3,hum=36.1,co=0i 1641045600 home,room=Living\ Room temp=22.3,hum=36.1,co=0i 1719756000
home,room=Kitchen temp=22.8,hum=36.3,co=1i 1641045600 home,room=Kitchen temp=22.8,hum=36.3,co=1i 1719756000
home,room=Living\ Room temp=22.3,hum=36.1,co=1i 1641049200 home,room=Living\ Room temp=22.3,hum=36.1,co=1i 1719759600
home,room=Kitchen temp=22.7,hum=36.2,co=3i 1641049200 home,room=Kitchen temp=22.7,hum=36.2,co=3i 1719759600
home,room=Living\ Room temp=22.4,hum=36.0,co=4i 1641052800 home,room=Living\ Room temp=22.4,hum=36.0,co=4i 1719763200
home,room=Kitchen temp=22.4,hum=36.0,co=7i 1641052800 home,room=Kitchen temp=22.4,hum=36.0,co=7i 1719763200
home,room=Living\ Room temp=22.6,hum=35.9,co=5i 1641056400 home,room=Living\ Room temp=22.6,hum=35.9,co=5i 1719766800
home,room=Kitchen temp=22.7,hum=36.0,co=9i 1641056400 home,room=Kitchen temp=22.7,hum=36.0,co=9i 1719766800
home,room=Living\ Room temp=22.8,hum=36.2,co=9i 1641060000 home,room=Living\ Room temp=22.8,hum=36.2,co=9i 1719770400
home,room=Kitchen temp=23.3,hum=36.9,co=18i 1641060000 home,room=Kitchen temp=23.3,hum=36.9,co=18i 1719770400
home,room=Living\ Room temp=22.5,hum=36.3,co=14i 1641063600 home,room=Living\ Room temp=22.5,hum=36.3,co=14i 1719774000
home,room=Kitchen temp=23.1,hum=36.6,co=22i 1641063600 home,room=Kitchen temp=23.1,hum=36.6,co=22i 1719774000
home,room=Living\ Room temp=22.2,hum=36.4,co=17i 1641067200 home,room=Living\ Room temp=22.2,hum=36.4,co=17i 1719777600
home,room=Kitchen temp=22.7,hum=36.5,co=26i 1641067200 home,room=Kitchen temp=22.7,hum=36.5,co=26i 1719777600
") ")
# Format the response code and error message output. # Format the response code and error message output.
@ -556,32 +578,32 @@ response=$(curl --silent --write-out "%{response_code}:-%{errormsg}" \
--header "Content-Type: text/plain; charset=utf-8" \ --header "Content-Type: text/plain; charset=utf-8" \
--header "Accept: application/json" \ --header "Accept: application/json" \
--data-binary " --data-binary "
home,room=Living\ Room temp=21.1,hum=35.9,co=0i 1641024000 home,room=Living\ Room temp=21.1,hum=35.9,co=0i 1719734400
home,room=Kitchen temp=21.0,hum=35.9,co=0i 1641024000 home,room=Kitchen temp=21.0,hum=35.9,co=0i 1719734400
home,room=Living\ Room temp=21.4,hum=35.9,co=0i 1641027600 home,room=Living\ Room temp=21.4,hum=35.9,co=0i 1719738000
home,room=Kitchen temp=23.0,hum=36.2,co=0i 1641027600 home,room=Kitchen temp=23.0,hum=36.2,co=0i 1719738000
home,room=Living\ Room temp=21.8,hum=36.0,co=0i 1641031200 home,room=Living\ Room temp=21.8,hum=36.0,co=0i 1719741600
home,room=Kitchen temp=22.7,hum=36.1,co=0i 1641031200 home,room=Kitchen temp=22.7,hum=36.1,co=0i 1719741600
home,room=Living\ Room temp=22.2,hum=36.0,co=0i 1641034800 home,room=Living\ Room temp=22.2,hum=36.0,co=0i 1719745200
home,room=Kitchen temp=22.4,hum=36.0,co=0i 1641034800 home,room=Kitchen temp=22.4,hum=36.0,co=0i 1719745200
home,room=Living\ Room temp=22.2,hum=35.9,co=0i 1641038400 home,room=Living\ Room temp=22.2,hum=35.9,co=0i 1719748800
home,room=Kitchen temp=22.5,hum=36.0,co=0i 1641038400 home,room=Kitchen temp=22.5,hum=36.0,co=0i 1719748800
home,room=Living\ Room temp=22.4,hum=36.0,co=0i 1641042000 home,room=Living\ Room temp=22.4,hum=36.0,co=0i 1719752400
home,room=Kitchen temp=22.8,hum=36.5,co=1i 1641042000 home,room=Kitchen temp=22.8,hum=36.5,co=1i 1719752400
home,room=Living\ Room temp=22.3,hum=36.1,co=0i 1641045600 home,room=Living\ Room temp=22.3,hum=36.1,co=0i 1719756000
home,room=Kitchen temp=22.8,hum=36.3,co=1i 1641045600 home,room=Kitchen temp=22.8,hum=36.3,co=1i 1719756000
home,room=Living\ Room temp=22.3,hum=36.1,co=1i 1641049200 home,room=Living\ Room temp=22.3,hum=36.1,co=1i 1719759600
home,room=Kitchen temp=22.7,hum=36.2,co=3i 1641049200 home,room=Kitchen temp=22.7,hum=36.2,co=3i 1719759600
home,room=Living\ Room temp=22.4,hum=36.0,co=4i 1641052800 home,room=Living\ Room temp=22.4,hum=36.0,co=4i 1719763200
home,room=Kitchen temp=22.4,hum=36.0,co=7i 1641052800 home,room=Kitchen temp=22.4,hum=36.0,co=7i 1719763200
home,room=Living\ Room temp=22.6,hum=35.9,co=5i 1641056400 home,room=Living\ Room temp=22.6,hum=35.9,co=5i 1719766800
home,room=Kitchen temp=22.7,hum=36.0,co=9i 1641056400 home,room=Kitchen temp=22.7,hum=36.0,co=9i 1719766800
home,room=Living\ Room temp=22.8,hum=36.2,co=9i 1641060000 home,room=Living\ Room temp=22.8,hum=36.2,co=9i 1719770400
home,room=Kitchen temp=23.3,hum=36.9,co=18i 1641060000 home,room=Kitchen temp=23.3,hum=36.9,co=18i 1719770400
home,room=Living\ Room temp=22.5,hum=36.3,co=14i 1641063600 home,room=Living\ Room temp=22.5,hum=36.3,co=14i 1719774000
home,room=Kitchen temp=23.1,hum=36.6,co=22i 1641063600 home,room=Kitchen temp=23.1,hum=36.6,co=22i 1719774000
home,room=Living\ Room temp=22.2,hum=36.4,co=17i 1641067200 home,room=Living\ Room temp=22.2,hum=36.4,co=17i 1719777600
home,room=Kitchen temp=22.7,hum=36.5,co=26i 1641067200 home,room=Kitchen temp=22.7,hum=36.5,co=26i 1719777600
") ")
# Format the response code and error message output. # Format the response code and error message output.

View File

@ -7,6 +7,7 @@ pytest-dotenv>=0.5.2
# Allow pytest to pass if no tests (i.e. testable code blocks) are found. # Allow pytest to pass if no tests (i.e. testable code blocks) are found.
pytest-custom-exit-code>=0.3.0 pytest-custom-exit-code>=0.3.0
requests>=2.26.0 requests>=2.26.0
toml
# Code sample dependencies # Code sample dependencies
influxdb3-python @ git+https://github.com/InfluxCommunity/influxdb3-python@v0.5.0 influxdb3-python @ git+https://github.com/InfluxCommunity/influxdb3-python@v0.5.0
influxdb3-python-cli @ git+https://github.com/InfluxCommunity/influxdb3-python-cli@main influxdb3-python-cli @ git+https://github.com/InfluxCommunity/influxdb3-python-cli@main