Skip to content

Sourcery refactored master branch - #1

Open
sourcery-ai[bot] wants to merge 1 commit into
masterfrom
sourcery/master
Open

Sourcery refactored master branch#1
sourcery-ai[bot] wants to merge 1 commit into
masterfrom
sourcery/master

Conversation

@sourcery-ai

@sourcery-ai sourcery-ai Bot commented Nov 1, 2023

Copy link
Copy Markdown

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai
sourcery-ai Bot requested a review from Prhmma November 1, 2023 12:45

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to GitHub API limits, only the first 60 comments can be shown.

self.name,
self.parent,
))
return f'{type(self).__name__}(name={self.name}, parent={self.parent})'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Span.__repr__ refactored with the following changes:

i,
RuntimeContext,
))
print(f'Hello {name} {i} {RuntimeContext}')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function hello refactored with the following changes:


def __repr__(self):
return ('{}({})'.format(type(self).__name__, self.name))
return f'{type(self).__name__}({self.name})'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Span.__repr__ refactored with the following changes:

Comment on lines -31 to +34
println('Entering worker[{}]: {}'.format(name, RuntimeContext))
println(f'Entering worker[{name}]: {RuntimeContext}')
RuntimeContext.operation_id = name
time.sleep(0.01)
println('Exiting worker[{}]: {}'.format(name, RuntimeContext))
println(f'Exiting worker[{name}]: {RuntimeContext}')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function work refactored with the following changes:


if __name__ == "__main__":
println('Main thread: {}'.format(RuntimeContext))
println(f'Main thread: {RuntimeContext}')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 38-50 refactored with the following changes:

if fullpath.endswith('.lock'):
fullpath = fullpath[: fullpath.rindex('@')]
fullpath += '@{}.lock'.format(_fmt(timestamp))
fullpath += f'@{_fmt(timestamp)}.lock'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LocalFileBlob.lease refactored with the following changes:

interval=self.maintenance_period,
function=self._maintenance_routine,
name='{} Storage Worker'.format(source)
name=f'{source} Storage Worker',

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LocalFileStorage.__init__ refactored with the following changes:

pass
try:
for blob in self.gets():
for _ in self.gets():

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LocalFileStorage._maintenance_routine refactored with the following changes:

if self.options.credential:
token = self.options.credential.get_token(_MONITOR_OAUTH_SCOPE)
headers["Authorization"] = "Bearer {}".format(token.token)
headers["Authorization"] = f"Bearer {token.token}"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TransportMixin._transmit refactored with the following changes:

Comment on lines -347 to +345
if type_name == "success" or type_name == "count": # success, count
if type_name in ["success", "count"]: # success, count

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _update_requests_map refactored with the following changes:

opencensus_version,
ext_version,
),
'ai.internal.sdkVersion': f'py{platform.python_version()}:oc{opencensus_version}:ext{ext_version}',

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 33-37 refactored with the following changes:

super(Worker, self).__init__(
name='{} Worker'.format(type(dst).__name__)
)
super(Worker, self).__init__(name=f'{type(dst).__name__} Worker')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Worker.__init__ refactored with the following changes:

Comment on lines -213 to +230
level = 0
has_full_stack = False
exc_type = "N/A"
message = self.format(record)
if tb is not None:
has_full_stack = True
for fileName, line, method, _text in traceback.extract_tb(tb):
callstack.append({
callstack.extend(
{
'level': level,
'method': method,
'fileName': fileName,
'line': line,
})
level += 1
}
for level, (fileName, line, method, _text) in enumerate(
traceback.extract_tb(tb)
)
)
callstack.reverse()
elif record.message:
message = record.message

if exctype is not None:
exc_type = exctype.__name__

exc_type = exctype.__name__ if exctype is not None else "N/A"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AzureLogHandler.log_record_to_envelope refactored with the following changes:

Comment on lines -304 to +303
envelope.tags['ai.operation.parentId'] = '|{}.{}.'.format(
envelope.tags['ai.operation.id'],
getattr(record, 'spanId', '0000000000000000'),
)
envelope.tags[
'ai.operation.parentId'
] = f"|{envelope.tags['ai.operation.id']}.{getattr(record, 'spanId', '0000000000000000')}."

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function create_envelope refactored with the following changes:

Comment on lines 166 to 170
if self.exporter_thread:
# flush if metrics exporter is not for stats
if not self._is_stats:
self.exporter_thread.close()
else:
if self._is_stats:
self.exporter_thread.cancel()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MetricsExporter.shutdown refactored with the following changes:

This removes the following comments ( why? ):

# flush if metrics exporter is not for stats

envelope.tags['ai.operation.parentId'] = '{}'.format(
sd.parent_span_id,
)
envelope.tags['ai.operation.parentId'] = f'{sd.parent_span_id}'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AzureExporter.span_data_to_envelope refactored with the following changes:

This removes the following comments ( why? ):

# TODO
# Modify based off attributes or status


mm = metric.Metric(descriptor=desc, time_series=ts)
return mm
return metric.Metric(descriptor=desc, time_series=ts)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function create_metric refactored with the following changes:

Comment on lines -105 to +104
mm = metric.Metric(descriptor=desc, time_series=ts)
return mm
return metric.Metric(descriptor=desc, time_series=ts)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function create_metric_ts refactored with the following changes:

Comment on lines -130 to +128
mm = metric.Metric(descriptor=desc, time_series=ts)
return mm
return metric.Metric(descriptor=desc, time_series=ts)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function create_stats_metric refactored with the following changes:

_requests_map.clear()
_requests_map['failure'] = {}
_requests_map['failure'][400] = 10
_requests_map['failure'] = {400: 10}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestStatsbeatMetrics.test_get_failure_count_value refactored with the following changes:

Comment on lines -398 to +397
_requests_map['retry'] = {}
_requests_map['retry'][401] = 10
_requests_map['retry'] = {401: 10}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestStatsbeatMetrics.test_get_retry_count_value refactored with the following changes:

Comment on lines -406 to +404
_requests_map['throttle'] = {}
_requests_map['throttle'][402] = 10
_requests_map['throttle'] = {402: 10}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestStatsbeatMetrics.test_get_throttle_count_value refactored with the following changes:

Comment on lines -414 to +411
_requests_map['exception'] = {}
_requests_map['exception']['Timeout'] = 10
_requests_map['exception'] = {'Timeout': 10}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestStatsbeatMetrics.test_get_exception_count_value refactored with the following changes:

Comment on lines -688 to +684
_vm_data = {}
_vm_data["vmId"] = "123"
_vm_data["subscriptionId"] = "sub123"
_vm_data["osType"] = "linux"
_vm_data = {"vmId": "123", "subscriptionId": "sub123", "osType": "linux"}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestStatsbeatMetrics.test_get_attach_metric_vm refactored with the following changes:

Comment on lines -712 to +705
_vm_data = {}
_vm_data["vmId"] = "123"
_vm_data["subscriptionId"] = "sub123"
_vm_data["osType"] = None
_vm_data = {"vmId": "123", "subscriptionId": "sub123", "osType": None}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestStatsbeatMetrics.test_get_attach_metric_vm_no_os refactored with the following changes:


span = tracer.start_span()
span.name = '{}.query'.format(vendor)
span.name = f'{vendor}.query'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _trace_db_call refactored with the following changes:

trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05'
span_id = '6e0c63257de34c92'
django_trace_id = '00-{}-{}-00'.format(trace_id, span_id)
django_trace_id = f'00-{trace_id}-{span_id}-00'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestOpencensusMiddleware.test_process_request refactored with the following changes:

trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05'
span_id = '6e0c63257de34c92'
django_trace_id = '00-{}-{}-00'.format(trace_id, span_id)
django_trace_id = f'00-{trace_id}-{span_id}-00'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestOpencensusMiddleware.test_process_response refactored with the following changes:

trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05'
span_id = '6e0c63257de34c92'
django_trace_id = '00-{}-{}-00'.format(trace_id, span_id)
django_trace_id = f'00-{trace_id}-{span_id}-00'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestOpencensusMiddleware.test_process_response_unfinished_child_span refactored with the following changes:

trace_id = '2dd43a1d6b2549c6bc2a1a54c2fc0b05'
span_id = '6e0c63257de34c92'
django_trace_id = '00-{}-{}-00'.format(trace_id, span_id)
django_trace_id = f'00-{trace_id}-{span_id}-00'

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestOpencensusMiddleware.test_process_exception refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants