Skip to content

Conversation

@hunter-ni
Copy link
Contributor

@hunter-ni hunter-ni commented Nov 17, 2025

What does this Pull Request accomplish?

This set of changes enables the examples and acceptance tests present in the datastore-python repo to publish data/metadata to a running Data Store Service while keeping that data separate from production data/metadata that is being published through typical usage of the client API.

Note that these changes are reliant upon a change to DiscoveryClient in ni-apis-python to be aware of the existing Cluster ID environment variable and use it to help detect the appropriate Discovery Service (with that ID).

Implementation

This set of changes centers around the addition of a DataStoreContext class that initializes the necessary state to ensure that a DataStoreClient or MetadataStoreClient that is exercised within that context interacts with a Discovery Service + Data Store Service that is publishing data to an isolated location separate from the typical location for production data. This DataStoreContext is leveraged both by examples and tests, so it has been added in a separate, new utilities top-level folder that defines a package that is referenced as a dev dependency of both the repo's overall pyproject.toml (used for tests and notebooks) and the pyproject.toml of each individual, standalone example (overview and system).

The DataStoreContext accomplishes this by setting an environment variable that instructs the Discovery Service to launch with a particular cluster ID, ensuring that the Discovery Service + Data Store Service that is used in the example/test is not the 'default' instance that could perhaps already be running on the machine due to another client's usage. The DataStoreContext also sets environment variables configuring the behavior of the Data Store Service. (These environment variables are inherited by the Data Store Service process that the Discovery Service launches.) The DataStoreContext also implements a Context Manager pattern to allow this particular environment to be easily stood up and torn down via a with statement.

  • Updated all Jupyter notebook examples to initialize a DataStoreContext as part of beginning example execution
  • Updated all standalone examples to use a DataStoreContext for the body of the example's execution
  • Updated all acceptance tests to use a DataStoreContext as a module-level test fixture for test execution

By default, the DataStoreContext will redirect Data Store Service output to a temp_data folder in the root of the repo. This location has been added to .gitignore. It is also configurable as a parameter of the DataStoreContext.

Why should this Pull Request be merged?

This set of changes helps prevent unnecessary pollution of the production data store with example or test data.

What testing has been done?

  • Ran all of the examples and confirmed that they now publish data to temp_data and do not modify the production data store.
  • Ran all automated tests and verified that they now publish data to temp_data and do not modify the production data store.
  • Added code analysis checks to the CI for the utilities folder, similar to what is already in place for examples.

@hunter-ni hunter-ni changed the title Examples - Create a Separate Data Store / Data Files Repository Examples - Create a Separate Data Store / Data Files Folder Nov 17, 2025
@hunter-ni hunter-ni changed the title Examples - Create a Separate Data Store / Data Files Folder Examples - Create a Separate Backing Data Store Nov 17, 2025
@hunter-ni hunter-ni changed the title Examples - Create a Separate Backing Data Store Examples - Create an Example-Specific Backing Data Store Nov 17, 2025
@hunter-ni hunter-ni requested a review from Copilot November 17, 2025 23:53
Copilot finished reviewing on behalf of hunter-ni November 17, 2025 23:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces an ExampleContext class that creates an isolated data store environment for examples, preventing example data from polluting the production data store. The implementation uses environment variables to configure a separate Discovery Service instance with a unique cluster ID.

  • Adds ExampleContext class with context manager support for setting up and tearing down example-specific environments
  • Updates all notebook examples and the standalone overview.py to use the new example context
  • Adds example_data/ directory to .gitignore for storing example-specific data

Reviewed Changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
examples/common/_example_context.py New class that manages example-specific Discovery Service and Data Store configuration via environment variables
examples/common/init.py Exports the ExampleContext class for use in examples
examples/notebooks/initialize_example_notebook.py Helper script for initializing example context in Jupyter notebooks
examples/overview/src/overview.py Updated to use ExampleContext as a context manager
examples/notebooks/voltage-regulator/publish_waveforms.ipynb Added initialization and cleanup calls for example context
examples/notebooks/query/query_metadata.ipynb Added initialization and cleanup calls for example context
examples/notebooks/query/query_measurements.ipynb Added initialization and cleanup calls for example context
examples/notebooks/query/publish_sample_data.ipynb Added initialization and cleanup calls for example context
examples/notebooks/overview/publish_measurement.ipynb Added initialization and cleanup calls for example context
examples/notebooks/custom-metadata/custom_metadata.ipynb Added initialization and cleanup calls for example context
examples/notebooks/alias/alias.ipynb Added initialization and cleanup calls for example context
.gitignore Added examples/example_data/ to prevent committing example-generated data

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Renamed ExampleContext to DataStoreContext.
- Generate a cluster ID from a hash of the directory path being used.
- Do not terminate the Discovery Service (with the particular cluster ID) when the DataStoreContext exits.
- Remove unnecessary code for making directories (the service will handle this for us)
@ni ni deleted a comment from Copilot AI Nov 18, 2025
@hunter-ni hunter-ni changed the title Examples - Create an Example-Specific Backing Data Store Examples and Acceptance Tests - Separate Created/Published Data from Default Data Store Nov 19, 2025
Copy link
Collaborator

@dixonjoel dixonjoel left a comment

Choose a reason for hiding this comment

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

Relatively minor feedback. Generally looks good.

@hunter-ni hunter-ni requested review from a team and dixonjoel November 20, 2025 19:02
@hunter-ni hunter-ni merged commit 5a0ab4e into main Nov 21, 2025
29 checks passed
@hunter-ni hunter-ni deleted the users/hunter-ni/example-context branch November 21, 2025 17:19
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.

5 participants