-
Notifications
You must be signed in to change notification settings - Fork 8
Revive jaeger #500
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
Merged
Merged
Revive jaeger #500
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
06a6f36
Allow user to provide arbitrary config
hardbyte fac1c23
Allow user to provide arbitrary deployment annotations
hardbyte b1441a9
Try use default tracing connection
hardbyte 5a7583a
Use default tracing connection for api too
hardbyte 292e46a
Extract load_yaml_config from setup_logging and add tests
hardbyte 4fb2578
K8s: Add a config file for tracing. Always mount all config files in …
hardbyte cea3bb7
Remove redundant helper function from test_serialization
hardbyte f87a2ca
Remove individual tracing setting in favor of passing in a file path.
hardbyte f5f8aad
Use tracing config file or default
hardbyte e6a2f5a
Strings to yaml not objects
hardbyte 39df146
Add config volume to db init job
hardbyte 5b4316d
Try to use jaeger during CI testing for api
hardbyte 4548c59
Use default tracing connection for workers
hardbyte f5a6677
Try enable tracing
hardbyte bedc79a
Use default tracing connection for api too
hardbyte 083affb
Ok enough of azure, just enable the tracing annotation by default
hardbyte 2f2b7e2
Use default logging config in k8s
hardbyte 729032f
fix filename typo
hardbyte 5439e49
cleanup after review
hardbyte 278cccd
Only log celery container from worker pod
hardbyte b563cb4
Remove a stray print statement
hardbyte 95ff98c
Minor tweaks to improve logging
hardbyte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Extract load_yaml_config from setup_logging and add tests
- Loading branch information
commit 292e46ad707712d290d15bce42691060a14ce375
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,64 @@ | ||
| import textwrap | ||
|
|
||
| import pytest | ||
|
|
||
| from entityservice.errors import InvalidConfiguration | ||
| from entityservice.utils import load_yaml_config | ||
| from entityservice.tests.util import generate_bytes, temp_file_containing | ||
|
|
||
|
|
||
| class TestYamlLoader: | ||
|
|
||
| def test_empty(self): | ||
| with temp_file_containing(b'') as fp: | ||
| filename = fp.name | ||
| assert None == load_yaml_config(filename) | ||
|
|
||
| def test_list(self): | ||
| with temp_file_containing(b'[1,2,3]') as fp: | ||
| filename = fp.name | ||
| assert [1,2,3] == load_yaml_config(filename) | ||
|
|
||
| def test_missing_file(self): | ||
| filename = 'unlikely a valid file' | ||
| with pytest.raises(InvalidConfiguration): | ||
| load_yaml_config(filename) | ||
|
|
||
| def test_random_bytes(self): | ||
| with temp_file_containing(generate_bytes(128)) as fp: | ||
| filename = fp.name | ||
| with pytest.raises(InvalidConfiguration): | ||
| load_yaml_config(filename) | ||
|
|
||
| def test_valid_yaml(self): | ||
| yamldata = textwrap.dedent(""" | ||
| api: | ||
| number: 42 | ||
| ingress: | ||
| enabled: true | ||
| host: example.com | ||
| """) | ||
| self._check_valid_yaml(yamldata) | ||
|
|
||
| def _check_valid_yaml(self, yamldata:str): | ||
| with temp_file_containing(yamldata.encode()) as fp: | ||
| filename = fp.name | ||
| loaded = load_yaml_config(filename) | ||
| assert 'api' in loaded | ||
| assert 'number' in loaded['api'] | ||
| assert loaded['api']['number'] == 42 | ||
| assert loaded['api']['ingress']['enabled'] | ||
| return loaded | ||
|
|
||
| def test_valid_yaml_with_comments(self): | ||
| yamldata = textwrap.dedent(""" | ||
| ## Api is a thing | ||
| api: | ||
| number: 42 | ||
| ingress: | ||
| enabled: true | ||
| # host: example.com | ||
| """) | ||
| loaded = self._check_valid_yaml(yamldata) | ||
| assert 'host' not in loaded['api']['ingress'] | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| import os | ||
| import random | ||
| import time | ||
| import tempfile | ||
| from contextlib import contextmanager | ||
| from enum import IntEnum | ||
|
|
||
|
|
@@ -14,6 +15,15 @@ | |
| from entityservice.tests.config import url | ||
|
|
||
|
|
||
| @contextmanager | ||
| def temp_file_containing(data): | ||
| # Code to acquire resource, e.g.: | ||
|
||
| with tempfile.NamedTemporaryFile('wb') as fp: | ||
| fp.write(data) | ||
| fp.seek(0) | ||
| yield fp | ||
|
|
||
|
|
||
| def serialize_bytes(hash_bytes): | ||
| """ Serialize bloomfilter bytes | ||
|
|
||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -8,15 +8,36 @@ | |
|
|
||
| import binascii | ||
| import bitmath | ||
| from flask import request | ||
| from connexion import ProblemException | ||
| from flask import request | ||
| from structlog import get_logger | ||
| import yaml | ||
|
|
||
| from entityservice.errors import InvalidConfiguration | ||
| from entityservice.database import DBConn, get_number_parties_uploaded, get_number_parties_ready, get_project_column | ||
|
|
||
| logger = get_logger() | ||
|
|
||
|
|
||
| def load_yaml_config(filename): | ||
| """ | ||
| Load a yaml file as a Python object. | ||
| :param filename: a Path or String object | ||
| :raises InvalidConfiguration if the file isn't found or the yaml isn't valid. | ||
| :return: Python representation of yaml file's contents (usually Dict), or None if empty. | ||
| """ | ||
| try: | ||
| with open(filename, 'rt') as f: | ||
| return yaml.safe_load(f) | ||
| except UnicodeDecodeError as e: | ||
| raise InvalidConfiguration("YAML file appears corrupt") from e | ||
|
||
| except yaml.YAMLError as e: | ||
| raise InvalidConfiguration("Parsing YAML config failed") from e | ||
| except FileNotFoundError as e: | ||
| raise InvalidConfiguration(f"Logging config YAML file '{filename}' doesn't exist.") from e | ||
|
|
||
|
|
||
| def fmt_bytes(num_bytes): | ||
| """ | ||
| Displays an integer number of bytes in a human friendly form. | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a non-zero chance that those random bytes resemble valid yaml. Why not just feeding a known invalid config to the test?