3

I'm writing a short Python script to allow a user to change the length of the retention on a tag. The user enters the measurement they wish to look at, and then after being prompted with the possible 'Identifiers', they enter the one they want to change and then the duration. It looks like this:

from influxdb import InfluxDBClient
import os, pdb

client = InfluxDBClient('localhost', 8086, database='JSON_DATA')

print('\nEnter the Measurement, you want to access: ')
measurement = str(input())

uIds = []
ids = client.query("SHOW TAG VALUES FROM " + measurement + " WITH key = Identifier;")
print('\nAvailable Identifiers:')
for i in ids:
    for j in i:
        uIds.append(j['value'])
        print(j['value'])

print('\nEnter the Identifier you want to alter: ')
Id = str(input())

retry = True
while retry:
    if Id not in uIds:
        print('\nNot a valid Identifier, please retry:')
        Id = str(input())
    else:
        retry = False

print('\nWhat Retention Policy are you applying to' , Id ,':')
print('Current policies:')
uRps = []
Rps = client.get_list_retention_policies(database='JSON_DATA')
for i in Rps:
    uRps.append(i['name'])
    print('\t'+i['name'])

print('\nOr create your own by entering desired time')
print('24h = 24 hours, 3d = 3 days, 52w = 52 weeks/1 Year')
print('m for Months and y for Years is not compatible')
newRP = str(input())

if newRP in uRps:
    result = client.query("SELECT * INTO \"" + newRP +"\".\"" + measurement + "\" FROM " + measurement + " WHERE Identifier = \'" + Id + "\';")
    print(result)
elif newRP not in uRps:
    client.create_retention_policy(newRP, newRP, 1, database=JSON_DATA, default=False)
    result = client.query("SELECT * INTO \"" + newRP +"\".\"" + measurement + "\" FROM " + measurement + " WHERE Identifier = " + Id + ";")

The script checks to see if the duration inputted by the user is the same as an already existing Retention Policy and if not creates a new one. My question is a two-parter:

1. I've really struggled to find any in-depth documentation about RPs, but on a influx community post I found this query: SELECT * INTO <new_RP>.<measurement_name> FROM <old_RP>.<measurement_name> WHERE <tage_key> = '<tag_name>' so I tried to verify it works on a sample database

> show retention policies
name    duration shardGroupDuration replicaN default
----    -------- ------------------ -------- -------
autogen 0s       168h0m0s           1        true
1_hour  1h0m0s   1h0m0s             1        false
> select * into "1_hour"."h2o_quality" from h2o_quality where location='coyote_creek' and randtag='1'
name: result'
time                 written
----                 -------
1970-01-01T00:00:00Z 0

Does anyone know what the output 'written' means here? If it means no data had their RP altered than I guess either I've input the query wrong or it doesn't work

2. After running my script I got this error

Traceback (most recent call last):
  File "influxScript.py", line 44, in <module>
    result = client.query("SELECT * INTO \"" + newRP +"\".\"" + measurement + "\" FROM " + measurement + " WHERE Identifier = \'" + Id + "\';")
  File "C:\Users\user\Documents\Database\env\lib\site-packages\influxdb\client.py", line 461, in query
    in data.get('results', [])
  File "C:\Users\user\Documents\Database\env\lib\site-packages\influxdb\client.py", line 460, in <listcomp>
    for result
  File "C:\Users\user\Documents\Database\env\lib\site-packages\influxdb\resultset.py", line 25, in __init__
    raise InfluxDBClientError(self.error)
influxdb.exceptions.InfluxDBClientError: partial write: points beyond retention policy dropped=7294

Does anyone know what partial write: points beyond retention policy dropped=7294 means? I was thinking it might be because I'm inputting a retention policy younger/shorter than the data's timestamps but I don't know that to be the case Thanks

james12
  • 27
  • 3

0 Answers0