From 2f7ea0ae1f81526e47031431b14468d88fc24f80 Mon Sep 17 00:00:00 2001 From: Robert Cerven Date: Tue, 17 Oct 2023 17:01:12 +0200 Subject: [PATCH] revert opentelemetry commits Signed-off-by: Robert Cerven --- docs/configuration_file.md | 2 -- osbs/api.py | 26 +++---------------- osbs/build/user_params.py | 18 ------------- osbs/cli/main.py | 4 +-- osbs/conf.py | 10 ------- osbs/constants.py | 2 -- osbs/tekton.py | 12 --------- osbs/utils/otel.py | 53 -------------------------------------- requirements.txt | 5 ---- 9 files changed, 5 insertions(+), 127 deletions(-) delete mode 100644 osbs/utils/otel.py diff --git a/docs/configuration_file.md b/docs/configuration_file.md index 2419a1f19..801af2af5 100644 --- a/docs/configuration_file.md +++ b/docs/configuration_file.md @@ -41,8 +41,6 @@ Some options are also mandatory. - `openshift_uri` (mandatory, str): root URL where openshift master API server is listening (e.g. 'localhost:8443') -- `otel_url` (optional, str): root URL where opentelemetry collector is - listening (e.g. 'localhost:4318') - `git_url` (optional, str): URL of git repository where dockerfile lives (it is used to perform `git clone`) - `git_ref` (optional, str): name of git ref (branch/commit) to check out diff --git a/osbs/api.py b/osbs/api.py index 434f88132..186bf534b 100644 --- a/osbs/api.py +++ b/osbs/api.py @@ -16,20 +16,17 @@ from typing import Any, Dict from string import Template -from otel_extensions import get_tracer - from osbs.build.user_params import ( BuildUserParams, SourceContainerUserParams ) from osbs.constants import (RELEASE_LABEL_FORMAT, VERSION_LABEL_FORBIDDEN_CHARS, - ISOLATED_RELEASE_FORMAT, OTEL_SERVICE_NAME) + ISOLATED_RELEASE_FORMAT) from osbs.tekton import Openshift, PipelineRun from osbs.exceptions import (OsbsException, OsbsValidationException, OsbsResponseException) from osbs.utils.labels import Labels # import utils in this way, so that we can mock standalone functions with flexmock from osbs import utils -from osbs.utils.otel import get_current_traceparent, init_otel def _load_pipeline_from_template(pipeline_run_path, substitutions): @@ -84,7 +81,6 @@ class OSBS(object): def __init__(self, openshift_configuration): """ """ self.os_conf = openshift_configuration - init_otel(self.os_conf.get_otel_url(), traceparent=get_current_traceparent()) self.os = Openshift(openshift_api_url=self.os_conf.get_openshift_base_uri(), openshift_oauth_url=self.os_conf.get_openshift_oauth_api_uri(), k8s_api_url=self.os_conf.get_k8s_api_uri(), @@ -258,15 +254,7 @@ def _get_binary_container_pipeline_data(self, *, buildtime_limit, user_params, @osbsapi def create_binary_container_build(self, **kwargs): - span_name = 'binary_build' - tracer = get_tracer(module_name=span_name, service_name=OTEL_SERVICE_NAME) - with tracer.start_as_current_span(span_name) as span: - for k, v in kwargs.items(): - if not v: - continue - span.set_attribute(k, v) - result = self.create_binary_container_pipeline_run(**kwargs) - return result + return self.create_binary_container_pipeline_run(**kwargs) @osbsapi def create_binary_container_pipeline_run(self, @@ -362,15 +350,7 @@ def _get_source_container_pipeline_data(self, *, user_params, pipeline_run_name) @osbsapi def create_source_container_build(self, **kwargs): - span_name = 'source_build' - tracer = get_tracer(module_name=span_name, service_name=OTEL_SERVICE_NAME) - with tracer.start_as_current_span(span_name) as span: - for k, v in kwargs.items(): - if not v: - continue - span.set_attribute(k, v) - result = self.create_source_container_pipeline_run(**kwargs) - return result + return self.create_source_container_pipeline_run(**kwargs) @osbsapi def create_source_container_pipeline_run(self, diff --git a/osbs/build/user_params.py b/osbs/build/user_params.py index 438fa5e0c..b276c3a35 100644 --- a/osbs/build/user_params.py +++ b/osbs/build/user_params.py @@ -19,7 +19,6 @@ from osbs.exceptions import OsbsValidationException from osbs.utils import (make_name_from_git, utcnow) -from osbs.utils.otel import get_current_traceparent logger = logging.getLogger(__name__) @@ -87,7 +86,6 @@ class BuildCommon(BuildParamsBase): koji_target = BuildParam("koji_target") koji_task_id = BuildParam("koji_task_id") platform = BuildParam("platform") - opentelemetry_info = BuildParam("opentelemetry_info") reactor_config_map = BuildParam("reactor_config_map") scratch = BuildParam("scratch") signing_intent = BuildParam("signing_intent") @@ -150,17 +148,6 @@ def make_params(cls, reactor_config = build_conf.get_reactor_config_map_scratch() else: reactor_config = build_conf.get_reactor_config_map() - # we are effectively making current span as parent here - # if the traceparent is not updated then child call will - # be linked to the parent of current call - traceparent = get_current_traceparent() - otel_url = build_conf.get_otel_url() - opentelemetry_info = None - if traceparent or otel_url: - opentelemetry_info = { - "traceparent": traceparent, - "otel_url": otel_url, - } # Update kwargs with arguments explicitly accepted by this method kwargs.update({ "component": component, @@ -175,11 +162,6 @@ def make_params(cls, "scratch": build_conf.get_scratch(scratch), }) - if opentelemetry_info: - kwargs.update({ - "opentelemetry_info": opentelemetry_info - }) - # Drop arguments that are: # - unknown; some callers may pass deprecated params # - not set (set to None, either explicitly or implicitly) diff --git a/osbs/cli/main.py b/osbs/cli/main.py index 5c7a98553..03cd7b0c8 100644 --- a/osbs/cli/main.py +++ b/osbs/cli/main.py @@ -137,7 +137,7 @@ def cmd_build(args): if osbs.os_conf.get_flatpak(): build_kwargs['flatpak'] = True - pipeline_run = osbs.create_binary_container_build(**build_kwargs) + pipeline_run = osbs.create_binary_container_pipeline_run(**build_kwargs) print_output(pipeline_run, export_metadata_file=args.export_metadata_file) @@ -177,7 +177,7 @@ def cmd_build_source_container(args): if args.userdata: build_kwargs['userdata'] = json.loads(args.userdata) - pipeline_run = osbs.create_source_container_build(**build_kwargs) + pipeline_run = osbs.create_source_container_pipeline_run(**build_kwargs) print_output(pipeline_run, export_metadata_file=args.export_metadata_file) diff --git a/osbs/conf.py b/osbs/conf.py index b429dfbfa..181cc7696 100644 --- a/osbs/conf.py +++ b/osbs/conf.py @@ -116,16 +116,6 @@ def get_openshift_base_uri(self): val = self._get_value(key, self.conf_section, key) return val - def get_otel_url(self): - """ - https://[:]/ - - :return: str - """ - key = "otel_url" - val = self._get_value(key, self.conf_section, key) - return val - @staticmethod def get_k8s_api_version(): # This is not configurable. diff --git a/osbs/constants.py b/osbs/constants.py index caec35d4d..18e003f48 100644 --- a/osbs/constants.py +++ b/osbs/constants.py @@ -74,8 +74,6 @@ # number of seconds to wait, before retrying on openshift not found OS_NOT_FOUND_MAX_WAIT = 1 -OTEL_SERVICE_NAME = "osbs" - ISOLATED_RELEASE_FORMAT = re.compile(r'^\d+\.\d+(\..+)?$') RELEASE_LABEL_FORMAT = re.compile(r"""^\d+ # First character must be a digit ([._]? # allow separators between groups diff --git a/osbs/tekton.py b/osbs/tekton.py index ae46ab646..56a857769 100644 --- a/osbs/tekton.py +++ b/osbs/tekton.py @@ -14,7 +14,6 @@ from typing import Dict, List, Tuple, Callable, Any from datetime import datetime -from otel_extensions import instrumented from osbs.exceptions import OsbsResponseException, OsbsAuthException, OsbsException from osbs.constants import (DEFAULT_NAMESPACE, SERVICEACCOUNT_SECRET, SERVICEACCOUNT_TOKEN, @@ -423,7 +422,6 @@ def pipeline_run_url(self): ) return self._pipeline_run_url - @instrumented def start_pipeline_run(self): if not self.input_data: raise OsbsException("No input data provided for pipeline run to start") @@ -447,7 +445,6 @@ def start_pipeline_run(self): ) return response.json() - @instrumented def remove_pipeline_run(self): url = self.os.build_url( self.api_path, @@ -461,7 +458,6 @@ def remove_pipeline_run(self): return response.json() @retry_on_conflict - @instrumented def cancel_pipeline_run(self): data = copy.deepcopy(self.minimal_data) data['spec']['status'] = 'CancelledRunFinally' @@ -483,7 +479,6 @@ def cancel_pipeline_run(self): raise OsbsException(exc_msg) return response_json - @instrumented def get_info(self, wait=False): if wait: self.wait_for_start() @@ -677,7 +672,6 @@ def matches_state(task_run: Dict[str, Any]) -> bool: task_runs = self.data['status'].get('taskRuns', {}).values() return any(matches_state(tr) for tr in task_runs) - @instrumented def wait_for_finish(self): """ use this method after reading logs finished, to ensure that pipeline run finished, @@ -737,7 +731,6 @@ def load_result(result: Dict[str, str]) -> Tuple[str, Any]: name: value for name, value in map(load_result, pipeline_results) if value is not None } - @instrumented def wait_for_start(self): """ https://tekton.dev/docs/pipelines/pipelineruns/#monitoring-execution-status @@ -771,7 +764,6 @@ def wait_for_start(self): logger.debug("Waiting for pipeline run, current status %s, reason %s", status, reason) - @instrumented def wait_for_taskruns(self): """ This generator method watches new task runs in a pipeline run @@ -865,7 +857,6 @@ def __init__(self, os, task_run_name): self.api_path = 'apis' self.api_version = API_VERSION - @instrumented def get_info(self, wait=False): if wait: self.wait_for_start() @@ -892,7 +883,6 @@ def get_logs(self, follow=False, wait=False): pod = Pod(os=self.os, pod_name=pod_name, containers=containers) return pod.get_logs(follow=follow, wait=wait) - @instrumented def wait_for_start(self): """ https://tekton.dev/docs/pipelines/taskruns/#monitoring-execution-status @@ -932,7 +922,6 @@ def __init__(self, os, pod_name, containers=None): self.api_version = 'v1' self.api_path = 'api' - @instrumented def get_info(self, wait=False): if wait: self.wait_for_start() @@ -1044,7 +1033,6 @@ def _stream_logs(self, container): logger.debug("Fetching logs starting from %ds ago", since) kwargs['sinceSeconds'] = since - @instrumented def wait_for_start(self): logger.info("Waiting for pod to start '%s'", self.pod_name) for pod in self.os.watch_resource( diff --git a/osbs/utils/otel.py b/osbs/utils/otel.py deleted file mode 100644 index ec29654d0..000000000 --- a/osbs/utils/otel.py +++ /dev/null @@ -1,53 +0,0 @@ -""" -Copyright (c) 2023 Red Hat, Inc -All rights reserved. - -This software may be modified and distributed under the terms -of the BSD license. See the LICENSE file for details. -""" -import logging -import os -from typing import Optional - -from opentelemetry import trace -from opentelemetry.instrumentation.requests import RequestsInstrumentor -from opentelemetry.trace import format_trace_id, format_span_id -from otel_extensions import TelemetryOptions, init_telemetry_provider - -from osbs.constants import OTEL_SERVICE_NAME - -logger = logging.getLogger(__name__) - - -def init_otel(otel_url: Optional[str], traceparent: Optional[str]): - logger.info("Initializing otel with traceparent %s", traceparent) - span_exporter = '' - otel_protocol = 'http/protobuf' - if not otel_url: - otel_protocol = 'custom' - span_exporter = '"opentelemetry.sdk.trace.export.ConsoleSpanExporter"' - - if traceparent: - os.environ['TRACEPARENT'] = traceparent - otel_options = TelemetryOptions( - OTEL_SERVICE_NAME=OTEL_SERVICE_NAME, - OTEL_EXPORTER_CUSTOM_SPAN_EXPORTER_TYPE=span_exporter, - OTEL_EXPORTER_OTLP_ENDPOINT=otel_url, - OTEL_EXPORTER_OTLP_PROTOCOL=otel_protocol, - ) - init_telemetry_provider(otel_options) - if 'TRACEPARENT' in os.environ: - del os.environ['TRACEPARENT'] - RequestsInstrumentor().instrument() - logger.info("Initialization complete") - - -def get_current_traceparent(): - tracecontext = trace.get_current_span().get_span_context() - traceparent = (f'00-{format_trace_id(tracecontext.trace_id)}-' - f'{format_span_id(tracecontext.span_id)}-01') - logger.info("current traceparent is %s", traceparent) - none_traceparent = '00-00000000000000000000000000000000-0000000000000000-01' - if traceparent == none_traceparent: - return None - return traceparent diff --git a/requirements.txt b/requirements.txt index b557c5040..69d285777 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,8 +5,3 @@ requests requests-kerberos six PyYAML -opentelemetry-api==1.19.0 -opentelemetry-exporter-otlp==1.19.0 -opentelemetry-instrumentation-requests==0.40b0 -opentelemetry-sdk==1.19.0 -otel-extensions