Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andmat900 committed Apr 22, 2024
1 parent e187c17 commit 8329071
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 11 deletions.
8 changes: 6 additions & 2 deletions projects/etos_suite_runner/src/etos_suite_runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@
if os.getenv("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"):
PROVIDER = TracerProvider(
resource=Resource.create(
{SERVICE_NAME: "etos-suite-runner", SERVICE_VERSION: VERSION, SERVICE_NAMESPACE: ENVIRONMENT}
{
SERVICE_NAME: "etos-suite-runner",
SERVICE_VERSION: VERSION,
SERVICE_NAMESPACE: ENVIRONMENT,
}
)
)
EXPORTER = OTLPSpanExporter()
PROCESSOR = BatchSpanProcessor(EXPORTER)
PROVIDER.add_span_processor(PROCESSOR)
trace.set_tracer_provider(PROVIDER)
else:
LOGGER.info("Suite runner OTEL_EXPORTER_OTLP_TRACES_ENDPOINT not set!")
LOGGER.info("Suite runner OTEL_EXPORTER_OTLP_TRACES_ENDPOINT not set!")
2 changes: 2 additions & 0 deletions projects/etos_suite_runner/src/etos_suite_runner/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ def main():
esr.etos.publisher.stop()
LOGGER.info("ESR Finished Executing.", extra={"user_log": True})


def run():
"""Entry point for console_scripts."""
main()


if __name__ == "__main__":
run()
5 changes: 3 additions & 2 deletions projects/etos_suite_runner/src/etos_suite_runner/esr.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

SUBSUITE_CONTEXT = None


class ESR: # pylint:disable=too-many-instance-attributes
"""Suite runner for ETOS main program.
Expand Down Expand Up @@ -78,7 +79,7 @@ def _request_environment(self, ids: list[str]) -> None:
try:
provider = EnvironmentProvider(self.params.tercc.meta.event_id, ids, copy=False)
result = provider.run()
except Exception as exc:
except Exception:
self.params.set_status("FAILURE", "Failed to run environment provider")
self.logger.error(
"Environment provider has failed in creating an environment for test.",
Expand Down Expand Up @@ -107,7 +108,7 @@ def _release_environment(self) -> None:
jsontas = JsonTas()
span_name = "release_full_environment"
suite_context = get_current_context()
with self.otel_tracer.start_as_current_span(span_name, context=suite_context) as span:
with self.otel_tracer.start_as_current_span(span_name, context=suite_context):
status, message = release_full_environment(
etos=self.etos, jsontas=jsontas, suite_id=self.params.tercc.meta.event_id
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from requests.exceptions import ConnectionError as RequestsConnectionError
from requests.exceptions import HTTPError

from ..otel_tracing import get_current_context

class TestStartException(Exception):
"""Exception when starting tests."""
Expand Down Expand Up @@ -94,7 +93,7 @@ def run_tests(self, test_suite: dict) -> None:
method = getattr(self.etos.http, request.pop("method").lower())
span_name = "start_execution_space"
with self.tracer.start_as_current_span(span_name) as span:
span.set_attribute("executor_id", executor['id'])
span.set_attribute("executor_id", executor["id"])
span.set_attribute("request", dumps(request, indent=4))
try:
response = method(**request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def start_suites_and_wait(self):
"""Get environments and start all test suites."""
try:
test_suites = [
TestSuite(self.etos, self.params, suite, otel_context=self.otel_suite_context) for suite in self.params.test_suite
TestSuite(self.etos, self.params, suite, otel_context=self.otel_suite_context)
for suite in self.params.test_suite
]
with ThreadPool() as pool:
pool.map(self.run, test_suites)
Expand Down
16 changes: 12 additions & 4 deletions projects/etos_suite_runner/src/etos_suite_runner/lib/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
request_test_suite_started,
)
from .log_filter import DuplicateFilter
from ..otel_tracing import get_current_context


class SubSuite: # pylint:disable=too-many-instance-attributes
Expand Down Expand Up @@ -149,7 +148,10 @@ def release(self, testrun_id) -> None:
span_name = "release_environment"
with self.otel_tracer.start_as_current_span(span_name) as span:
failure = release_environment(
etos=self.etos, jsontas=jsontas, provider_registry=registry, sub_suite=self.environment
etos=self.etos,
jsontas=jsontas,
provider_registry=registry,
sub_suite=self.environment,
)
span.set_attribute("testrun_id", testrun_id)
span.set_attribute("failure", str(failure))
Expand All @@ -172,7 +174,12 @@ class TestSuite: # pylint:disable=too-many-instance-attributes
__activity_triggered = None
__activity_finished = None

def __init__(self, etos: ETOS, params: ESRParameters, suite: dict, otel_context: opentelemetry.context.context.Context = None) -> None:
def __init__(self,
etos: ETOS,
params: ESRParameters,
suite: dict,
otel_context: opentelemetry.context.context.Context = None
) -> None:
"""Initialize a TestSuite instance."""
self.etos = etos
self.params = params
Expand Down Expand Up @@ -340,7 +347,8 @@ def start(self) -> None:
)
self.sub_suites.append(sub_suite)
thread = threading.Thread(
target=sub_suite.start, args=(self.params.tercc.meta.event_id, self.otel_context)
target=sub_suite.start,
args=(self.params.tercc.meta.event_id, self.otel_context),
)
threads.append(thread)
thread.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

LOGGER = logging.getLogger(__name__)


def get_current_context() -> opentelemetry.context.context.Context:
"""Get current context (propagated via environment variable OTEL_CONTEXT)."""
carrier = {}
Expand Down

0 comments on commit 8329071

Please sign in to comment.