Skip to content

Commit 4f13c6d

Browse files
committed
Convert f-string logging statements to %s format
1 parent ab6ec07 commit 4f13c6d

File tree

1 file changed

+39
-34
lines changed

1 file changed

+39
-34
lines changed

nemoguardrails/benchmark/validate_mocks.py

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ def check_endpoint(port: int, expected_model: str):
3939
base_url = f"http://localhost:{port}"
4040
all_ok = True
4141

42-
logging.info(f"\n--- Checking Port: {port} ---")
42+
logging.info("\n--- Checking Port: %s ---", port)
4343

4444
# --- 1. Health Check ---
4545
health_url = f"{base_url}/health"
46-
logging.info(f"Checking {health_url} ...")
46+
logging.info("Checking %s ...", health_url)
4747
try:
4848
response = requests.get(health_url, timeout=3)
4949

5050
if response.status_code != 200:
51-
logging.error(f"Health Check FAILED: Status code {response.status_code}")
51+
logging.error("Health Check FAILED: Status code %s", response.status_code)
5252
all_ok = False
5353
else:
5454
try:
@@ -58,30 +58,33 @@ def check_endpoint(port: int, expected_model: str):
5858
logging.info("Health Check PASSED: Status is 'healthy'.")
5959
else:
6060
logging.warning(
61-
f"Health Check FAILED: Expected 'healthy', got '{status}'."
61+
"Health Check FAILED: Expected 'healthy', got '%s'.", status
6262
)
6363
all_ok = False
6464
except requests.exceptions.JSONDecodeError:
6565
logging.error("Health Check FAILED: Could not decode JSON response.")
6666
all_ok = False
6767

6868
except requests.exceptions.ConnectionError:
69-
logging.error(f"Health Check FAILED: No response from server on port {port}.")
70-
logging.error(f"--- Port {port}: CHECKS FAILED ---")
71-
return False, f"Port {port} ({expected_model}): FAILED (Connection Error)"
69+
logging.error("Health Check FAILED: No response from server on port %s.", port)
70+
logging.error("--- Port %s: CHECKS FAILED ---", port)
71+
return False, "Port %s (%s): FAILED (Connection Error)" % (port, expected_model)
7272
except requests.exceptions.Timeout:
73-
logging.error(f"Health Check FAILED: Connection timed out for port {port}.")
74-
logging.error(f"--- Port {port}: CHECKS FAILED ---")
75-
return False, f"Port {port} ({expected_model}): FAILED (Connection Timeout)"
73+
logging.error("Health Check FAILED: Connection timed out for port %s.", port)
74+
logging.error("--- Port %s: CHECKS FAILED ---", port)
75+
return False, "Port %s (%s): FAILED (Connection Timeout)" % (
76+
port,
77+
expected_model,
78+
)
7679

7780
# --- 2. Model Check ---
7881
models_url = f"{base_url}/v1/models"
79-
logging.info(f"Checking {models_url} for '{expected_model}'...")
82+
logging.info("Checking %s for '%s'...", models_url, expected_model)
8083
try:
8184
response = requests.get(models_url, timeout=3)
8285

8386
if response.status_code != 200:
84-
logging.error(f"Model Check FAILED: Status code {response.status_code}")
87+
logging.error("Model Check FAILED: Status code %s", response.status_code)
8588
all_ok = False
8689
else:
8790
try:
@@ -91,39 +94,41 @@ def check_endpoint(port: int, expected_model: str):
9194

9295
if expected_model in model_ids:
9396
logging.info(
94-
f"Model Check PASSED: Found '{expected_model}' in model list."
97+
"Model Check PASSED: Found '%s' in model list.", expected_model
9598
)
9699
else:
97100
logging.warning(
98-
f"Model Check FAILED: Expected '{expected_model}', but it was NOT found."
101+
"Model Check FAILED: Expected '%s', but it was NOT found.",
102+
expected_model,
99103
)
100104
logging.warning("Available models:")
101105
for model_id in model_ids:
102-
logging.warning(f" - {model_id}")
106+
logging.warning(" - %s", model_id)
103107
all_ok = False
104108
except requests.exceptions.JSONDecodeError:
105109
logging.error("Model Check FAILED: Could not decode JSON response.")
106110
all_ok = False
107111
except AttributeError:
108112
logging.error(
109-
f"Model Check FAILED: Unexpected JSON structure in response from {models_url}."
113+
"Model Check FAILED: Unexpected JSON structure in response from %s.",
114+
models_url,
110115
)
111116
all_ok = False
112117

113118
except requests.exceptions.ConnectionError:
114-
logging.error(f"Model Check FAILED: No response from server on port {port}.")
119+
logging.error("Model Check FAILED: No response from server on port %s.", port)
115120
all_ok = False
116121
except requests.exceptions.Timeout:
117-
logging.error(f"Model Check FAILED: Connection timed out for port {port}.")
122+
logging.error("Model Check FAILED: Connection timed out for port %s.", port)
118123
all_ok = False
119124

120125
# --- Final Status ---
121126
if all_ok:
122-
logging.info(f"--- Port {port}: ALL CHECKS PASSED ---")
123-
return True, f"Port {port} ({expected_model}): PASSED"
127+
logging.info("--- Port %s: ALL CHECKS PASSED ---", port)
128+
return True, "Port %s (%s): PASSED" % (port, expected_model)
124129
else:
125-
logging.error(f"--- Port {port}: CHECKS FAILED ---")
126-
return False, f"Port {port} ({expected_model}): FAILED"
130+
logging.error("--- Port %s: CHECKS FAILED ---", port)
131+
return False, "Port %s (%s): FAILED" % (port, expected_model)
127132

128133

129134
def check_rails_endpoint(port: int):
@@ -136,18 +141,18 @@ def check_rails_endpoint(port: int):
136141
endpoint = f"{base_url}/v1/rails/configs"
137142
all_ok = True
138143

139-
logging.info(f"\n--- Checking Port: {port} (Rails Config) ---")
140-
logging.info(f"Checking {endpoint} ...")
144+
logging.info("\n--- Checking Port: %s (Rails Config) ---", port)
145+
logging.info("Checking %s ...", endpoint)
141146

142147
try:
143148
response = requests.get(endpoint, timeout=3)
144149

145150
# --- 1. HTTP Status Check ---
146151
if response.status_code == 200:
147-
logging.info(f"HTTP Status PASSED: Got {response.status_code}.")
152+
logging.info("HTTP Status PASSED: Got %s.", response.status_code)
148153
else:
149154
logging.warning(
150-
f"HTTP Status FAILED: Expected 200, got '{response.status_code}'."
155+
"HTTP Status FAILED: Expected 200, got '%s'.", response.status_code
151156
)
152157
all_ok = False
153158

@@ -163,30 +168,30 @@ def check_rails_endpoint(port: int):
163168
"Body Check FAILED: Response is not an array or is empty."
164169
)
165170
logging.debug(
166-
f"Response body (first 200 chars): {str(response.text)[:200]}"
171+
"Response body (first 200 chars): %s", str(response.text)[:200]
167172
)
168173
all_ok = False
169174
except requests.exceptions.JSONDecodeError:
170175
logging.error("Body Check FAILED: Could not decode JSON response.")
171176
logging.debug(
172-
f"Response body (first 200 chars): {str(response.text)[:200]}"
177+
"Response body (first 200 chars): %s", str(response.text)[:200]
173178
)
174179
all_ok = False
175180

176181
except requests.exceptions.ConnectionError:
177-
logging.error(f"Rails Check FAILED: No response from server on port {port}.")
182+
logging.error("Rails Check FAILED: No response from server on port %s.", port)
178183
all_ok = False
179184
except requests.exceptions.Timeout:
180-
logging.error(f"Rails Check FAILED: Connection timed out for port {port}.")
185+
logging.error("Rails Check FAILED: Connection timed out for port %s.", port)
181186
all_ok = False
182187

183188
# --- Final Status ---
184189
if all_ok:
185-
logging.info(f"--- Port {port}: ALL CHECKS PASSED ---")
186-
return True, f"Port {port} (Rails Config): PASSED"
190+
logging.info("--- Port %s: ALL CHECKS PASSED ---", port)
191+
return True, "Port %s (Rails Config): PASSED" % port
187192
else:
188-
logging.error(f"--- Port {port}: CHECKS FAILED ---")
189-
return False, f"Port {port} (Rails Config): FAILED"
193+
logging.error("--- Port %s: CHECKS FAILED ---", port)
194+
return False, "Port %s (Rails Config): FAILED" % port
190195

191196

192197
def main():

0 commit comments

Comments
 (0)