Skip to content

Python access to InfluxDB parameters via JSON fie #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rslippert opened this issue May 26, 2022 · 10 comments · Fixed by #467
Closed

Python access to InfluxDB parameters via JSON fie #444

rslippert opened this issue May 26, 2022 · 10 comments · Fixed by #467
Labels
enhancement New feature or request
Milestone

Comments

@rslippert
Copy link

Proposal:
Access to InfluxDB parameters were unnecessarily difficult to determine and use as magic numbers.
The Influx could save all those parameters to a JSON file, thus allow multiple use cases for multiple datasets.
Then access to the correct parameters for a given dataset comes from dictionary items.

Current behavior:

url = "http://localhost:8086" # must find an these paste magic numbers into my code here
token = "my-token" #token generated online and pasted here
bucket = "my-bucket"
org = "my-org"
with InfluxDBClient( url=url, token=token, org=org) as client:
(more code here)

Desired behavior:

import json
jfile = open('stock_data_rslippert.json',)
my = json.load( jfile)
with InfluxDBClient( url= my['influx_url'] token=my['influx_token'], org=my['influx_org']) as client:
(more code here)

Alternatives considered:
Would need to be some other way that automates collection of the parameters without magic numbers.

Use case:
Rather than searching and copy pasting parameters as magic numbers, for many different use cases,
use a similar method as when generating a token, but all needed parameters are generated to an easy to use json file
this simplifies access to the correct parameters, IE. it automates the access for many different use cases.
This is useful because engineers will be working on many different datasets, but the code should be the same.
so rather that pasting in magic numbers, access to the data is automatic. just provide a json filename as reference.
The file.json would look like this:
{
"influx_bucket": "rslippert's Bucket",
"influx_org": "d9ae8eef6f1bd6da",
"influx_token": "E3zGsMqgMrDYthxjfT921FXhipsOfGOIOxpcfvn61SnBE4D1mdgYKF5aYefaCbroy0UpBIsOEEMZr2XM96dtFg==",
"influx_url": "https://us-east-1-1.aws.cloud2.influxdata.com",
"timezone": "EST",
"influxdb_version": "1.0"
}

@bednar
Copy link
Contributor

bednar commented May 26, 2022

Hi @rslippert,

thanks for using our client.

How is generated your json file? Is it output from influx auth create?

Regards

@bednar bednar added the question Further information is requested label May 26, 2022
@rslippert
Copy link
Author

Did not know about influx auth create, I will check that out.

The point is to generate a simple point of entry for access to InfluxDB data.
This simplifies access, and other parameters could be added without affect to users,
for example, the code could be simplified even further to this:

with InfluxDBClient( access= 'stock_data_rslippert.json' ) as client:
(more code here)

@rslippert
Copy link
Author

As an alternative:
If 'influx auth create' knows everthing already to create a token,
why do I need the other parameters to access my data. Just get the info into that token:

with InfluxDBClient( access= token) as client:
(more code here)

I think a json file would be better because you could add things without the user needing to know about it.
That json file would even have a version to make sweeping changes.
This is how I have simplified things with my Iceberg software

@rslippert
Copy link
Author

Yes, the json file would be an alternative to the creation of a token

@rslippert
Copy link
Author

Iceberg/Sagent is Artificial General Intelligence AGI.
With AGI, the context for a process can involve hundreds (thousands) of parameters, metadata, and data.
Iceberg/Sagent saves complex contextual information as JSON "ICE" files. The user sees context rather than complexity.
Humans are very familiar with using a context simplification. You could get rid of all the parameters:

with InfluxDBClient( context= 'stock_data_rslippert' ) as client:
(more contextual code here)

@rslippert
Copy link
Author

Sorry for so many words, I am writing the AGI "Sagent Standard" documentation:

All processes will soon operate using smart agents (Sagent) that collect and control data within the process.
The problem with complex processes; the information grows like a snowball rolling down hill.
In complex systems, we must use context referencing, or the code gets messy as more information is collected.
Instead, contextual information should be hidden in contextual referencing, like web "COOKIES".
In Iceberg Sagent processes, a dictionary defines the contextual information. This cleans Iceberg code up a lot.
Most of the parameters come from ICE that defines and controls information in the process instance.
Humans use this all the time. In English the word "THE" is used to define an assumed context.
To say "The dog" does not say which dog, unless "dog" is a contextual referencing for what came before.
When we read a book, we have no problem with using this context, unless we read the book backwards.
This "dog" assumes a dog.json file that could have hundreds of things about the dog instance in the process.

@bednar bednar added enhancement New feature or request and removed question Further information is requested labels May 27, 2022
@bednar
Copy link
Contributor

bednar commented May 27, 2022

@rslippert thanks for the explanation.

Currently the client supports initialisation from configuration file:

with InfluxDBClient.from_config_file('./config.ini') as client:
    ...

The initialisation from JSON context file could be next option, something like:

with InfluxDBClient.from_json_file('./stock_data_rslippert.json') as client:
    ...

@rslippert
Copy link
Author

bednar thanks,

The important issue is automatic generation of this access data from the InfluxDB site point of access.
Does that exist? or is config.ini a hand setup job?

JSON is more suited to processes (API), external access. Config is more suited to an application (APP), internal access.
IE. If I need any of those parameters individually, I would need to parse the file. JSON needs no parser in Python.

You should also add "timezone" to that config.ini to allow simple pandas date formats.

@rslippert
Copy link
Author

It looks like it already supports .ini and .toml formats, just add .json to that.
Then provide a web based generation of any of those from the InfluxDB site point of access.

@bednar
Copy link
Contributor

bednar commented Jul 18, 2022

Then provide a web based generation of any of those from the InfluxDB site point of access.

The generation of the access configuration files is already present in influx config. For more info see: https://docs.influxdata.com/influxdb/cloud/reference/cli/influx/config/

It looks like it already supports .ini and .toml formats, just add .json to that.

The format of the json file will be same as is produced by influx config:

influx config --json
{
        "url": "http://localhost:8086",
        "token": "my-token",
        "org": "my-org",
        "active": true
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants