-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1575326
commit b1766fc
Showing
9 changed files
with
74 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,24 @@ | ||
import os | ||
import sys | ||
from typing import Dict | ||
|
||
from ._native import DDSketch # noqa: F401 | ||
from ._native import PyConfigurator # noqa: F401 | ||
from ._native import PyConfigurator | ||
|
||
|
||
def get_configuration_from_disk(debug_logs: bool = False, file_override="") -> Dict[str, str]: | ||
# type: (bool, str) -> Dict[str, str] | ||
""" | ||
Retrieves the tracer configuration from disk. Calls the PyConfigurator object | ||
to read the configuration from the disk using the libdatadog shared library | ||
and returns the corresponding configuration | ||
""" | ||
configurator = PyConfigurator(debug_logs) | ||
configurator.set_envp(["%s=%s" % (k, v) for k, v in os.environ.items()]) | ||
configurator.set_args(sys.argv) | ||
|
||
# Set the file override if provided. Only used for testing purposes. | ||
if file_override: | ||
configurator.set_file_override(file_override) | ||
|
||
return configurator.get_configuration() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from ddtrace.internal.native import get_configuration_from_disk | ||
|
||
def test_get_configuration_from_disk(tmp_path): | ||
# First test -- config matches & should be returned | ||
config_1 = tmp_path / "config_1.yaml" | ||
config_1.write_text(""" | ||
rules: | ||
- selectors: | ||
- origin: language | ||
matches: | ||
- python | ||
operator: equals | ||
configuration: | ||
DD_SERVICE: my-service | ||
""", encoding="utf-8") | ||
|
||
config = get_configuration_from_disk(file_override=str(config_1)) | ||
assert config == {"DD_SERVICE": "my-service"} | ||
|
||
# Second test -- config does not match & should not be returned | ||
config_2 = tmp_path / "config_2.yaml" | ||
config_2.write_text(""" | ||
rules: | ||
- selectors: | ||
- origin: language | ||
matches: | ||
- nodejs | ||
operator: equals | ||
configuration: | ||
DD_SERVICE: my-service | ||
""", encoding="utf-8") | ||
|
||
config = get_configuration_from_disk(file_override=str(config_2)) | ||
assert config == {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters