Skip to content

feat: support env #127

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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

feat: support env #127

wants to merge 18 commits into from

Conversation

NguyenHoangSon96
Copy link
Contributor

@NguyenHoangSon96 NguyenHoangSon96 commented Apr 16, 2025

Closes Issue

Proposed Changes

  • Support creates InfluxDB client with environment variables with the same name as the Go client

Checklist

  • CHANGELOG.md updated
  • Rebased/mergeable
  • A test has been added if appropriate
  • Tests pass
  • Commit messages are conventional
  • Sign CLA (if not already signed)

@NguyenHoangSon96 NguyenHoangSon96 self-assigned this Apr 16, 2025
@NguyenHoangSon96 NguyenHoangSon96 force-pushed the feat/support-env-variables branch from 26a9f36 to 0cd20ae Compare April 21, 2025 03:01
Copy link

codecov bot commented Apr 21, 2025

Codecov Report

Attention: Patch coverage is 96.66667% with 4 lines in your changes missing coverage. Please review.

Project coverage is 63.84%. Comparing base (93129b0) to head (ec8813c).

Files with missing lines Patch % Lines
influxdb_client_3/write_client/client/write_api.py 76.92% 3 Missing ⚠️
influxdb_client_3/__init__.py 98.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #127      +/-   ##
==========================================
+ Coverage   61.92%   63.84%   +1.92%     
==========================================
  Files          33       33              
  Lines        2135     2246     +111     
==========================================
+ Hits         1322     1434     +112     
+ Misses        813      812       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jansimonb
Copy link

I think config from environment variables was already supported (see method from_env_properties). What you should support is:

@NguyenHoangSon96
Copy link
Contributor Author

I think config from environment variables was already supported (see method from_env_properties). What you should support is:

Hi Jan
I don't get it
from_env_properties supports names with v2 in its string
My new function supports names like in golang
"INFLUX_HOST"
"INFLUX_TOKEN"
"INFLUX_DATABASE"
"INFLUX_ORG"

@NguyenHoangSon96 NguyenHoangSon96 marked this pull request as draft April 24, 2025 10:05
@NguyenHoangSon96
Copy link
Contributor Author

Hi @jansimonb
I pushed the latest code. Please take a look when you have time
I converted to draft because I'm not very confident with the fix 🙈
I have not added comments for new functions...

@NguyenHoangSon96 NguyenHoangSon96 requested review from jansimonb and removed request for jansimonb April 24, 2025 10:08
Copy link
Contributor

@karel-rehor karel-rehor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the V2 values in InfluxDBClient.from_env_properties() these are relics of the original copy and paste from the V2 client libraries roughly two years ago. Perhaps we should mark it as @deprecated

e.g.

    @deprecated("Use up to date Env Properties")
    @classmethod
    def from_env_properties(cls, debug=None, enable_gzip=False, **kwargs):

INFLUX_GZIP_THRESHOLD = "INFLUX_GZIP_THRESHOLD"


def from_env(**kwargs: Any) -> 'InfluxDBClient3':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a @classmethod on InfluxDBClient3 See https://github.com/influxdata/influxdb-client-python/blob/74013566a9df3e41dc1ef67cda0cbd0f6b83c733/influxdb_client/client/influxdb_client.py#L180

Also since most of these options are passed to write_options maybe it would be cleaner to have a class method there as well. e.g.

class WriteOptions(object):
...
    @classmethod
    def from_envars(cls, debug=None, enable_gzip=False, **kwargs):
        url = os.getenv('INFLUX_HOST', "http://localhost:8086")
        ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @karel-rehor
I had upgraded the from_env function
Can you check again and see if we still need to implement a separated function in WriteOptions

Copy link
Contributor

@karel-rehor karel-rehor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment went missing in last review. Retrieved it here.

Copy link

@jansimonb jansimonb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In from_env_properties (what we want to deprecate) there are 13 environment variables supported. In the new from_env we support 7 env variables. Does that mean that we are loosing some functionality? E.g. is it still possible to use the new from_env method but also configure connection_pool_maxsize?

@NguyenHoangSon96
Copy link
Contributor Author

In from_env_properties (what we want to deprecate) there are 13 environment variables supported. In the new from_env we support 7 env variables. Does that mean that we are loosing some functionality? E.g. is it still possible to use the new from_env method but also configure connection_pool_maxsize?

Hi @jansimonb
I have increased the number of parameters we support
Please check again

@NguyenHoangSon96 NguyenHoangSon96 marked this pull request as ready for review April 29, 2025 10:38
@NguyenHoangSon96 NguyenHoangSon96 force-pushed the feat/support-env-variables branch from c7b3101 to ec8813c Compare May 6, 2025 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent Environment Variable Support Between Go v3 and Python v3 Clients
3 participants