Skip to content

Commit

Permalink
lint files
Browse files Browse the repository at this point in the history
  • Loading branch information
Girish Chandrashekar committed Jan 23, 2023
1 parent 3a91378 commit 8bca278
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ def _translate_key_values(key: str, value: Any) -> KeyValue:


def get_resource_data(
sdk_resource_scope_data: Dict[SDKResource, ResourceDataT],
resource_class: Callable[..., TypingResourceT],
name: str,
sdk_resource_scope_data: Dict[SDKResource, ResourceDataT],
resource_class: Callable[..., TypingResourceT],
name: str,
) -> List[TypingResourceT]:
resource_data = []

for (
sdk_resource,
scope_data,
sdk_resource,
scope_data,
) in sdk_resource_scope_data.items():

collector_resource = Resource()
Expand Down Expand Up @@ -214,15 +214,15 @@ class OTLPExporterMixin(
"""

def __init__(
self,
endpoint: Optional[str] = None,
insecure: Optional[bool] = None,
credentials: Optional[ChannelCredentials] = None,
headers: Optional[
Union[TypingSequence[Tuple[str, str]], Dict[str, str], str]
] = None,
timeout: Optional[int] = None,
compression: Optional[Compression] = None,
self,
endpoint: Optional[str] = None,
insecure: Optional[bool] = None,
credentials: Optional[ChannelCredentials] = None,
headers: Optional[
Union[TypingSequence[Tuple[str, str]], Dict[str, str], str]
] = None,
timeout: Optional[int] = None,
compression: Optional[Compression] = None,
):
super().__init__()

Expand Down Expand Up @@ -264,10 +264,10 @@ def __init__(
self._collector_kwargs = None

compression = (
environ_to_compression(OTEL_EXPORTER_OTLP_COMPRESSION)
if compression is None
else compression
) or Compression.NoCompression
environ_to_compression(OTEL_EXPORTER_OTLP_COMPRESSION)
if compression is None
else compression
) or Compression.NoCompression

if insecure:
self._client = self._stub(
Expand All @@ -286,7 +286,7 @@ def __init__(

@abstractmethod
def _translate_data(
self, data: TypingSequence[SDKDataT]
self, data: TypingSequence[SDKDataT]
) -> ExportServiceRequestT:
pass

Expand All @@ -302,7 +302,7 @@ def _translate_attributes(self, attributes) -> TypingSequence[KeyValue]:
return output

def _export(
self, data: Union[TypingSequence[ReadableSpan], MetricsData]
self, data: Union[TypingSequence[ReadableSpan], MetricsData]
) -> ExportResultT:
# After the call to shutdown, subsequent calls to Export are
# not allowed and should return a Failure result.
Expand Down Expand Up @@ -356,8 +356,8 @@ def _export(
retry_info = RetryInfo()
retry_info.ParseFromString(retry_info_bin)
delay = (
retry_info.retry_delay.seconds
+ retry_info.retry_delay.nanos / 1.0e9
retry_info.retry_delay.seconds
+ retry_info.retry_delay.nanos / 1.0e9
)

logger.warning(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
class TestOTLPExporterMixin(TestCase):
def test_environ_to_compression(self):
with patch.dict(
"os.environ",
{
"test_gzip": "gzip",
"test_gzip_caseinsensitive_with_whitespace": " GzIp ",
"test_invalid": "some invalid compression",
},
"os.environ",
{
"test_gzip": "gzip",
"test_gzip_caseinsensitive_with_whitespace": " GzIp ",
"test_invalid": "some invalid compression",
},
):
self.assertEqual(
environ_to_compression("test_gzip"), Compression.Gzip
Expand Down Expand Up @@ -76,7 +76,7 @@ class OTLPMockExporter(OTLPExporterMixin):
)

def _translate_data(
self, data: Sequence[SDKDataT]
self, data: Sequence[SDKDataT]
) -> ExportServiceRequestT:
pass

Expand Down Expand Up @@ -119,12 +119,10 @@ def test_shutdown(self):

class OTLPMockExporter(OTLPExporterMixin):
_result = result_mock
_stub = Mock(
**{"return_value": Mock()}
)
_stub = Mock(**{"return_value": Mock()})

def _translate_data(
self, data: Sequence[SDKDataT]
self, data: Sequence[SDKDataT]
) -> ExportServiceRequestT:
pass

Expand All @@ -136,9 +134,13 @@ def _exporting(self) -> str:

with self.assertLogs(level=WARNING) as warning:
# pylint: disable=protected-access
self.assertEqual(otlp_mock_exporter._export(data={}), result_mock.SUCCESS)
self.assertEqual(
otlp_mock_exporter._export(data={}), result_mock.SUCCESS
)
otlp_mock_exporter.shutdown()
self.assertEqual(otlp_mock_exporter._export(data={}), result_mock.FAILURE)
self.assertEqual(
otlp_mock_exporter._export(data={}), result_mock.FAILURE
)
self.assertEqual(
warning.records[0].message,
"Exporter already shutdown, ignoring batch",
Expand All @@ -147,6 +149,7 @@ def _exporting(self) -> str:
def test_shutdown_wait_last_export(self):
import threading
import time

result_mock = Mock()
rpc_error = RpcError()

Expand All @@ -155,7 +158,9 @@ def code(self):

def trailing_metadata(self):
return {
"google.rpc.retryinfo-bin": RetryInfo(retry_delay=Duration(seconds=1)).SerializeToString()
"google.rpc.retryinfo-bin": RetryInfo(
retry_delay=Duration(seconds=1)
).SerializeToString()
}

rpc_error.code = MethodType(code, rpc_error)
Expand All @@ -168,7 +173,7 @@ class OTLPMockExporter(OTLPExporterMixin):
)

def _translate_data(
self, data: Sequence[SDKDataT]
self, data: Sequence[SDKDataT]
) -> ExportServiceRequestT:
pass

Expand All @@ -178,7 +183,9 @@ def _exporting(self) -> str:

otlp_mock_exporter = OTLPMockExporter()

export_thread = threading.Thread(target=otlp_mock_exporter._export, args=({},))
export_thread = threading.Thread(
target=otlp_mock_exporter._export, args=({},)
)
export_thread.start()
try:
self.assertTrue(otlp_mock_exporter._export_lock.locked())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

from concurrent.futures import ThreadPoolExecutor

# pylint: disable=too-many-lines
from logging import WARNING
from os.path import dirname
Expand All @@ -23,7 +24,6 @@
from google.protobuf.duration_pb2 import Duration
from google.rpc.error_details_pb2 import RetryInfo
from grpc import ChannelCredentials, Compression, StatusCode, server
from opentelemetry.test.metrictestutil import _generate_gauge, _generate_sum

from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import (
OTLPMetricExporter,
Expand Down Expand Up @@ -79,6 +79,7 @@
from opentelemetry.sdk.util.instrumentation import (
InstrumentationScope as SDKInstrumentationScope,
)
from opentelemetry.test.metrictestutil import _generate_gauge, _generate_sum

THIS_DIR = dirname(__file__)

Expand Down Expand Up @@ -366,7 +367,7 @@ def test_preferred_temporality(self):
{
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT: "collector:4317",
OTEL_EXPORTER_OTLP_METRICS_CERTIFICATE: THIS_DIR
+ "/fixtures/test.cert",
+ "/fixtures/test.cert",
OTEL_EXPORTER_OTLP_METRICS_HEADERS: " key1=value1,KEY2 = value=2",
OTEL_EXPORTER_OTLP_METRICS_TIMEOUT: "10",
OTEL_EXPORTER_OTLP_METRICS_COMPRESSION: "gzip",
Expand Down Expand Up @@ -397,7 +398,7 @@ def test_env_variables(self, mock_exporter_mixin):
)
# pylint: disable=unused-argument
def test_no_credentials_error(
self, mock_ssl_channel, mock_secure, mock_stub
self, mock_ssl_channel, mock_secure, mock_stub
):
OTLPMetricExporter(insecure=False)
self.assertTrue(mock_ssl_channel.called)
Expand Down Expand Up @@ -527,7 +528,7 @@ def test_otlp_exporter_endpoint(self, mock_secure, mock_insecure):
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.insecure_channel")
@patch.dict("os.environ", {OTEL_EXPORTER_OTLP_COMPRESSION: "gzip"})
def test_otlp_exporter_otlp_compression_envvar(
self, mock_insecure_channel, mock_expo
self, mock_insecure_channel, mock_expo
):
"""Just OTEL_EXPORTER_OTLP_COMPRESSION should work"""
OTLPMetricExporter(insecure=True)
Expand All @@ -551,7 +552,7 @@ def test_otlp_exporter_otlp_compression_kwarg(self, mock_insecure_channel):
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.insecure_channel")
@patch.dict("os.environ", {})
def test_otlp_exporter_otlp_compression_unspecified(
self, mock_insecure_channel
self, mock_insecure_channel
):
"""No env or kwarg should be NoCompression"""
OTLPMetricExporter(insecure=True)
Expand Down Expand Up @@ -1385,7 +1386,9 @@ def test_shutdown_wait_last_export(self):
MetricsServiceServicerUNAVAILABLEDelay(), self.server
)

export_thread = threading.Thread(target=self.exporter.export, args=(self.metrics["sum_int"],))
export_thread = threading.Thread(
target=self.exporter.export, args=(self.metrics["sum_int"],)
)
export_thread.start()
try:
self.assertTrue(self.exporter._export_lock.locked())
Expand All @@ -1401,7 +1404,7 @@ def test_shutdown_wait_last_export(self):


def _resource_metrics(
index: int, scope_metrics: List[ScopeMetrics]
index: int, scope_metrics: List[ScopeMetrics]
) -> ResourceMetrics:
return ResourceMetrics(
resource=Resource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
from google.protobuf.duration_pb2 import Duration
from google.rpc.error_details_pb2 import RetryInfo
from grpc import ChannelCredentials, Compression, StatusCode, server
from opentelemetry.test.spantestutil import (
get_span_with_dropped_attributes_events_links,
)

from opentelemetry.attributes import BoundedAttributes
from opentelemetry.exporter.otlp.proto.grpc.exporter import (
Expand Down Expand Up @@ -72,6 +69,9 @@
SpanExportResult,
)
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
from opentelemetry.test.spantestutil import (
get_span_with_dropped_attributes_events_links,
)

THIS_DIR = os.path.dirname(__file__)

Expand Down Expand Up @@ -229,7 +229,7 @@ def test_exporting(self):
{
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: "collector:4317",
OTEL_EXPORTER_OTLP_TRACES_CERTIFICATE: THIS_DIR
+ "/fixtures/test.cert",
+ "/fixtures/test.cert",
OTEL_EXPORTER_OTLP_TRACES_HEADERS: " key1=value1,KEY2 = value=2",
OTEL_EXPORTER_OTLP_TRACES_TIMEOUT: "10",
OTEL_EXPORTER_OTLP_TRACES_COMPRESSION: "gzip",
Expand Down Expand Up @@ -260,7 +260,7 @@ def test_env_variables(self, mock_exporter_mixin):
)
# pylint: disable=unused-argument
def test_no_credentials_error(
self, mock_ssl_channel, mock_secure, mock_stub
self, mock_ssl_channel, mock_secure, mock_stub
):
OTLPSpanExporter(insecure=False)
self.assertTrue(mock_ssl_channel.called)
Expand Down Expand Up @@ -397,7 +397,7 @@ def test_otlp_exporter_endpoint(self, mock_secure, mock_insecure):
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.insecure_channel")
@patch.dict("os.environ", {OTEL_EXPORTER_OTLP_COMPRESSION: "gzip"})
def test_otlp_exporter_otlp_compression_envvar(
self, mock_insecure_channel
self, mock_insecure_channel
):
"""Just OTEL_EXPORTER_OTLP_COMPRESSION should work"""
OTLPSpanExporter(insecure=True)
Expand All @@ -419,7 +419,7 @@ def test_otlp_exporter_otlp_compression_kwarg(self, mock_insecure_channel):
@patch("opentelemetry.exporter.otlp.proto.grpc.exporter.insecure_channel")
@patch.dict("os.environ", {})
def test_otlp_exporter_otlp_compression_unspecified(
self, mock_insecure_channel
self, mock_insecure_channel
):
"""No env or kwarg should be NoCompression"""
OTLPSpanExporter(insecure=True)
Expand All @@ -434,7 +434,7 @@ def test_otlp_exporter_otlp_compression_unspecified(
{OTEL_EXPORTER_OTLP_TRACES_COMPRESSION: "gzip"},
)
def test_otlp_exporter_otlp_compression_precendence(
self, mock_insecure_channel
self, mock_insecure_channel
):
"""OTEL_EXPORTER_OTLP_TRACES_COMPRESSION as higher priority than
OTEL_EXPORTER_OTLP_COMPRESSION
Expand Down Expand Up @@ -798,9 +798,9 @@ def test_translate_spans_multi(self):
)

def _check_translated_status(
self,
translated: ExportTraceServiceRequest,
code_expected: Status,
self,
translated: ExportTraceServiceRequest,
code_expected: Status,
):
status = translated.resource_spans[0].scope_spans[0].spans[0].status

Expand Down Expand Up @@ -955,7 +955,9 @@ def test_shutdown_wait_last_export(self):
TraceServiceServicerUNAVAILABLEDelay(), self.server
)

export_thread = threading.Thread(target=self.exporter.export, args=([self.span],))
export_thread = threading.Thread(
target=self.exporter.export, args=([self.span],)
)
export_thread.start()
try:
self.assertTrue(self.exporter._export_lock.locked())
Expand Down

0 comments on commit 8bca278

Please sign in to comment.