Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@
_START_SERVICE_TIMEOUT = 30.0
_START_SERVICE_POLLING_INTERVAL = 100e-3

_DISCOVERY_SERVICE_ENV_VAR_PREFIX = "NIDiscovery_"
_DISCOVERY_SERVICE_CLUSTER_ID_ENV_VAR = "ClusterId"


def _get_discovery_service_address() -> str:
cluster_id = os.environ.get("NIDISCOVERY_CLUSTERID")
# To support operating systems other than Windows (and match Discovery Service behavior),
# we would likely want to make this check case-insensitive.
Copy link
Collaborator

Choose a reason for hiding this comment

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

How do we document this for users? If we use shout-case there, then all OSes have the same casing for this variable and we can use os.environ directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe @nick-beer's original comment (precipitating this change + comment) was that we would want to match here whatever the Discovery Service itself would be anticipated to actually support, which would be the environment variable of this given name (with optional prefix) irrespective of case. I don't have any specific insight on the question of existing documentation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If the server is going to use PascalCase, then you're better off using PascalCase in the Python and LV packages so that it works regardless of whether environment variables are case-sensitive or case-insensitive. However, a lot of software avoids this situation by using all-caps for environment variables everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To summarize (and confirm that I'm on the same page):

Nick's comment indicates that the Discovery Service itself is explicitly designed to look for this environment variable in a case-insensitive manner (regardless of operating system). To your point though, existing Discovery Service code does use PascalCase when it needs to reference ClusterId and the NIDiscovery prefix, so we can use that casing here for consistency with the server code.

cluster_id = os.environ.get(
_DISCOVERY_SERVICE_ENV_VAR_PREFIX + _DISCOVERY_SERVICE_CLUSTER_ID_ENV_VAR
)
if not cluster_id:
cluster_id = os.environ.get(_DISCOVERY_SERVICE_CLUSTER_ID_ENV_VAR)
key_file_path = _get_key_file_path(cluster_id)
_ensure_discovery_service_started(key_file_path)
_logger.debug("Discovery service key file path: %s", key_file_path)
Expand Down