Skip to content

Commit 01b6b2f

Browse files
committed
Ruff format
1 parent 7df1091 commit 01b6b2f

File tree

12 files changed

+138
-31
lines changed

12 files changed

+138
-31
lines changed

newrelic/core/agent_control_health.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,8 @@ def update_to_healthy_status(self, protocol_error=False, collector_error=False):
172172
# session. This function allows us to update to a healthy status if so based on the error type
173173
# Since this function is only called when we are in scenario where the agent functioned as expected, we check to
174174
# see if the previous status was unhealthy so we know to update it
175-
if (
176-
(protocol_error
177-
and self.status_code in PROTOCOL_ERROR_CODES)
178-
or (collector_error
179-
and self.status_code == HealthStatus.FAILED_NR_CONNECTION.value)
175+
if (protocol_error and self.status_code in PROTOCOL_ERROR_CODES) or (
176+
collector_error and self.status_code == HealthStatus.FAILED_NR_CONNECTION.value
180177
):
181178
self.status_code = HealthStatus.HEALTHY.value
182179
self.status_message = HEALTHY_STATUS_MESSAGE

tests/agent_features/test_distributed_tracing.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ def test_distributed_trace_attributes(span_events, accept_payload):
141141
_forgone_error_attributes = {"intrinsic": _forgone_error_intrinsics, "agent": [], "user": []}
142142
else:
143143
_required_intrinsics = distributed_trace_intrinsics
144-
_forgone_txn_intrinsics = _forgone_error_intrinsics = [*inbound_payload_intrinsics, "grandparentId", "parentId", "parentSpanId"]
144+
_forgone_txn_intrinsics = _forgone_error_intrinsics = [
145+
*inbound_payload_intrinsics,
146+
"grandparentId",
147+
"parentId",
148+
"parentSpanId",
149+
]
145150

146151
_required_attributes = {"intrinsic": _required_intrinsics, "agent": [], "user": []}
147152
_forgone_txn_attributes = {"intrinsic": _forgone_txn_intrinsics, "agent": [], "user": []}

tests/component_graphqlserver/test_graphql.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,26 @@ def test_query_and_mutation(target_application):
102102
("GraphQL/operation/GraphQLServer/query/<anonymous>/storage", 1),
103103
(_view_metrics[framework], 1),
104104
]
105-
_test_query_unscoped_metrics = [("GraphQL/all", 1), ("GraphQL/GraphQLServer/all", 1), ("GraphQL/allWeb", 1), ("GraphQL/GraphQLServer/allWeb", 1), *_test_query_scoped_metrics]
105+
_test_query_unscoped_metrics = [
106+
("GraphQL/all", 1),
107+
("GraphQL/GraphQLServer/all", 1),
108+
("GraphQL/allWeb", 1),
109+
("GraphQL/GraphQLServer/allWeb", 1),
110+
*_test_query_scoped_metrics,
111+
]
106112

107113
_test_mutation_scoped_metrics = [
108114
("GraphQL/resolve/GraphQLServer/storage_add", 1),
109115
("GraphQL/operation/GraphQLServer/mutation/<anonymous>/storage_add", 1),
110116
(_view_metrics[framework], 1),
111117
]
112-
_test_mutation_unscoped_metrics = [("GraphQL/all", 1), ("GraphQL/GraphQLServer/all", 1), ("GraphQL/allWeb", 1), ("GraphQL/GraphQLServer/allWeb", 1), *_test_mutation_scoped_metrics]
118+
_test_mutation_unscoped_metrics = [
119+
("GraphQL/all", 1),
120+
("GraphQL/GraphQLServer/all", 1),
121+
("GraphQL/allWeb", 1),
122+
("GraphQL/GraphQLServer/allWeb", 1),
123+
*_test_mutation_scoped_metrics,
124+
]
113125

114126
_expected_mutation_operation_attributes = {
115127
"graphql.operation.type": "mutation",
@@ -204,7 +216,12 @@ def test_exception_in_middleware(target_application):
204216
(f"GraphQL/operation/GraphQLServer/query/MyQuery/{field}", 1),
205217
(f"GraphQL/resolve/GraphQLServer/{field}", 1),
206218
]
207-
_test_exception_rollup_metrics = [("Errors/all", 1), ("Errors/allWeb", 1), ("Errors/WebTransaction/GraphQL/component_graphqlserver.test_graphql:error_middleware", 1), *_test_exception_scoped_metrics]
219+
_test_exception_rollup_metrics = [
220+
("Errors/all", 1),
221+
("Errors/allWeb", 1),
222+
("Errors/WebTransaction/GraphQL/component_graphqlserver.test_graphql:error_middleware", 1),
223+
*_test_exception_scoped_metrics,
224+
]
208225

209226
# Attributes
210227
_expected_exception_resolver_attributes = {
@@ -247,7 +264,12 @@ def test_exception_in_resolver(target_application, field):
247264
(f"GraphQL/operation/GraphQLServer/query/MyQuery/{field}", 1),
248265
(f"GraphQL/resolve/GraphQLServer/{field}", 1),
249266
]
250-
_test_exception_rollup_metrics = [("Errors/all", 1), ("Errors/allWeb", 1), (f"Errors/WebTransaction/GraphQL/{txn_name}", 1), *_test_exception_scoped_metrics]
267+
_test_exception_rollup_metrics = [
268+
("Errors/all", 1),
269+
("Errors/allWeb", 1),
270+
(f"Errors/WebTransaction/GraphQL/{txn_name}", 1),
271+
*_test_exception_scoped_metrics,
272+
]
251273

252274
# Attributes
253275
_expected_exception_resolver_attributes = {
@@ -302,7 +324,12 @@ def test_exception_in_validation(target_application, is_graphql_2, query, exc_cl
302324
exc_class = callable_name(GraphQLError)
303325

304326
_test_exception_scoped_metrics = [("GraphQL/operation/GraphQLServer/<unknown>/<anonymous>/<unknown>", 1)]
305-
_test_exception_rollup_metrics = [("Errors/all", 1), ("Errors/allWeb", 1), (f"Errors/WebTransaction/GraphQL/{txn_name}", 1), *_test_exception_scoped_metrics]
327+
_test_exception_rollup_metrics = [
328+
("Errors/all", 1),
329+
("Errors/allWeb", 1),
330+
(f"Errors/WebTransaction/GraphQL/{txn_name}", 1),
331+
*_test_exception_scoped_metrics,
332+
]
306333

307334
# Attributes
308335
_expected_exception_operation_attributes = {

tests/external_aiobotocore/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class MotoService:
6969

7070
_services = {} # {name: instance}
7171

72-
def __init__(self, service_name, port = None, ssl = False):
72+
def __init__(self, service_name, port=None, ssl=False):
7373
self._service_name = service_name
7474

7575
if port:

tests/framework_django/test_asgi_application.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,12 @@ def test_asgi_html_insertion_failed(application, url):
166166

167167
@validate_transaction_metrics(
168168
"views:template_tags",
169-
scoped_metrics=[("Function/views:template_tags", 1), ("Template/Render/main.html", 1), ("Template/Render/results.html", 1), *scoped_metrics],
169+
scoped_metrics=[
170+
("Function/views:template_tags", 1),
171+
("Template/Render/main.html", 1),
172+
("Template/Render/results.html", 1),
173+
*scoped_metrics,
174+
],
170175
rollup_metrics=rollup_metrics,
171176
)
172177
@validate_code_level_metrics("views", "template_tags")

tests/framework_graphql/test_application.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,12 @@ def test_exception_in_middleware(target_application, middleware):
236236
(f"GraphQL/resolve/{framework}/{field}", 1),
237237
(f"Function/{name}", 1),
238238
]
239-
_test_exception_rollup_metrics = [("Errors/all", 1), (f"Errors/all{'Other' if is_bg else 'Web'}", 1), (f"Errors/{'Other' if is_bg else 'Web'}Transaction/GraphQL/{name}", 1), *_test_exception_scoped_metrics]
239+
_test_exception_rollup_metrics = [
240+
("Errors/all", 1),
241+
(f"Errors/all{'Other' if is_bg else 'Web'}", 1),
242+
(f"Errors/{'Other' if is_bg else 'Web'}Transaction/GraphQL/{name}", 1),
243+
*_test_exception_scoped_metrics,
244+
]
240245

241246
# Attributes
242247
_expected_exception_resolver_attributes = {
@@ -281,7 +286,12 @@ def test_exception_in_resolver(target_application, field):
281286
(f"GraphQL/operation/{framework}/query/MyQuery/{field}", 1),
282287
(f"GraphQL/resolve/{framework}/{field}", 1),
283288
]
284-
_test_exception_rollup_metrics = [("Errors/all", 1), (f"Errors/all{'Other' if is_bg else 'Web'}", 1), (f"Errors/{'Other' if is_bg else 'Web'}Transaction/GraphQL/{txn_name}", 1), *_test_exception_scoped_metrics]
289+
_test_exception_rollup_metrics = [
290+
("Errors/all", 1),
291+
(f"Errors/all{'Other' if is_bg else 'Web'}", 1),
292+
(f"Errors/{'Other' if is_bg else 'Web'}Transaction/GraphQL/{txn_name}", 1),
293+
*_test_exception_scoped_metrics,
294+
]
285295

286296
# Attributes
287297
_expected_exception_resolver_attributes = {
@@ -335,7 +345,12 @@ def test_exception_in_validation(target_application, query, exc_class):
335345
exc_class = callable_name(GraphQLError)
336346

337347
_test_exception_scoped_metrics = [(f"GraphQL/operation/{framework}/<unknown>/<anonymous>/<unknown>", 1)]
338-
_test_exception_rollup_metrics = [("Errors/all", 1), (f"Errors/all{'Other' if is_bg else 'Web'}", 1), (f"Errors/{'Other' if is_bg else 'Web'}Transaction/GraphQL/{txn_name}", 1), *_test_exception_scoped_metrics]
348+
_test_exception_rollup_metrics = [
349+
("Errors/all", 1),
350+
(f"Errors/all{'Other' if is_bg else 'Web'}", 1),
351+
(f"Errors/{'Other' if is_bg else 'Web'}Transaction/GraphQL/{txn_name}", 1),
352+
*_test_exception_scoped_metrics,
353+
]
339354

340355
# Attributes
341356
_expected_exception_operation_attributes = {

tests/framework_starlette/test_application.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ def target_application():
4747
("Function/starlette.exceptions:ExceptionMiddleware.__call__", 1),
4848
]
4949

50-
MIDDLEWARE_METRICS = [("Function/_test_application:middleware_factory.<locals>.middleware", 2), ("Function/_test_application:middleware_decorator", 1), *DEFAULT_MIDDLEWARE_METRICS]
50+
MIDDLEWARE_METRICS = [
51+
("Function/_test_application:middleware_factory.<locals>.middleware", 2),
52+
("Function/_test_application:middleware_decorator", 1),
53+
*DEFAULT_MIDDLEWARE_METRICS,
54+
]
5155

5256

5357
@pytest.mark.parametrize("app_name", ("no_error_handler",))

tests/framework_strawberry/_target_application.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def _run_sync(query, middleware=None):
3333

3434
response = schema.execute_sync(query)
3535

36-
if (isinstance(query, str) and "error" not in query) or (isinstance(query, Source) and "error" not in query.body):
36+
if (isinstance(query, str) and "error" not in query) or (
37+
isinstance(query, Source) and "error" not in query.body
38+
):
3739
assert not response.errors
3840
else:
3941
assert response.errors
@@ -53,7 +55,9 @@ def _run_async(query, middleware=None):
5355
loop = asyncio.get_event_loop()
5456
response = loop.run_until_complete(schema.execute(query))
5557

56-
if (isinstance(query, str) and "error" not in query) or (isinstance(query, Source) and "error" not in query.body):
58+
if (isinstance(query, str) and "error" not in query) or (
59+
isinstance(query, Source) and "error" not in query.body
60+
):
5761
assert not response.errors
5862
else:
5963
assert response.errors

tests/messagebroker_confluentkafka/test_consumer.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929

3030

3131
def test_custom_metrics(get_consumer_record, topic, expected_broker_metrics):
32-
custom_metrics = [(f"Message/Kafka/Topic/Named/{topic}/Received/Bytes", 1), (f"Message/Kafka/Topic/Named/{topic}/Received/Messages", 1), *expected_broker_metrics]
32+
custom_metrics = [
33+
(f"Message/Kafka/Topic/Named/{topic}/Received/Bytes", 1),
34+
(f"Message/Kafka/Topic/Named/{topic}/Received/Messages", 1),
35+
*expected_broker_metrics,
36+
]
3337

3438
@validate_transaction_metrics(
3539
f"Named/{topic}", group="Message/Kafka/Topic", custom_metrics=custom_metrics, background_task=True
@@ -55,7 +59,12 @@ def test_custom_metrics_on_existing_transaction(get_consumer_record, topic, expe
5559

5660
@validate_transaction_metrics(
5761
"test_consumer:test_custom_metrics_on_existing_transaction.<locals>._test",
58-
custom_metrics=[(f"Message/Kafka/Topic/Named/{topic}/Received/Bytes", 1), (f"Message/Kafka/Topic/Named/{topic}/Received/Messages", 1), (f"Python/MessageBroker/Confluent-Kafka/{version}", 1), *expected_broker_metrics],
62+
custom_metrics=[
63+
(f"Message/Kafka/Topic/Named/{topic}/Received/Bytes", 1),
64+
(f"Message/Kafka/Topic/Named/{topic}/Received/Messages", 1),
65+
(f"Python/MessageBroker/Confluent-Kafka/{version}", 1),
66+
*expected_broker_metrics,
67+
],
5968
background_task=True,
6069
)
6170
@validate_transaction_count(1)
@@ -69,7 +78,11 @@ def _test():
6978
def test_custom_metrics_inactive_transaction(get_consumer_record, topic, expected_missing_broker_metrics):
7079
@validate_transaction_metrics(
7180
"test_consumer:test_custom_metrics_inactive_transaction.<locals>._test",
72-
custom_metrics=[(f"Message/Kafka/Topic/Named/{topic}/Received/Bytes", None), (f"Message/Kafka/Topic/Named/{topic}/Received/Messages", None), *expected_missing_broker_metrics],
81+
custom_metrics=[
82+
(f"Message/Kafka/Topic/Named/{topic}/Received/Bytes", None),
83+
(f"Message/Kafka/Topic/Named/{topic}/Received/Messages", None),
84+
*expected_missing_broker_metrics,
85+
],
7386
background_task=True,
7487
)
7588
@validate_transaction_count(1)
@@ -129,7 +142,11 @@ def _produce():
129142
@validate_transaction_metrics(
130143
f"Named/{topic}",
131144
group="Message/Kafka/Topic",
132-
rollup_metrics=[("Supportability/DistributedTrace/AcceptPayload/Success", None), ("Supportability/TraceContext/Accept/Success", 1), *expected_broker_metrics],
145+
rollup_metrics=[
146+
("Supportability/DistributedTrace/AcceptPayload/Success", None),
147+
("Supportability/TraceContext/Accept/Success", 1),
148+
*expected_broker_metrics,
149+
],
133150
background_task=True,
134151
)
135152
@validate_transaction_count(1)

tests/messagebroker_confluentkafka/test_producer.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ def test():
9696
def test_distributed_tracing_headers(topic, send_producer_message, expected_broker_metrics):
9797
@validate_transaction_metrics(
9898
"test_producer:test_distributed_tracing_headers.<locals>.test",
99-
rollup_metrics=[("Supportability/TraceContext/Create/Success", 1), ("Supportability/DistributedTrace/CreatePayload/Success", 1), *expected_broker_metrics],
99+
rollup_metrics=[
100+
("Supportability/TraceContext/Create/Success", 1),
101+
("Supportability/DistributedTrace/CreatePayload/Success", 1),
102+
*expected_broker_metrics,
103+
],
100104
background_task=True,
101105
)
102106
@background_task()
@@ -111,7 +115,11 @@ def test():
111115
def test_distributed_tracing_headers_under_terminal(topic, send_producer_message, expected_broker_metrics):
112116
@validate_transaction_metrics(
113117
"test_distributed_tracing_headers_under_terminal",
114-
rollup_metrics=[("Supportability/TraceContext/Create/Success", 1), ("Supportability/DistributedTrace/CreatePayload/Success", 1), *expected_broker_metrics],
118+
rollup_metrics=[
119+
("Supportability/TraceContext/Create/Success", 1),
120+
("Supportability/DistributedTrace/CreatePayload/Success", 1),
121+
*expected_broker_metrics,
122+
],
115123
background_task=True,
116124
)
117125
@background_task(name="test_distributed_tracing_headers_under_terminal")

0 commit comments

Comments
 (0)