Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unstructured logging variable formatting #2029

Merged
merged 48 commits into from
Sep 18, 2024
Merged

Conversation

aysim319
Copy link
Contributor

@aysim319 aysim319 commented Aug 21, 2024

Description

replacing logging with f strings with parameters

Associated Issue(s)

Copy link
Contributor

@melange396 melange396 left a comment

Choose a reason for hiding this comment

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

looks pretty good! i marked a few things i think you mightve missed, and tried to change filename= where it actually referred to a directory and not a singular file.

doctor_visits/delphi_doctor_visits/patch.py Outdated Show resolved Hide resolved
google_symptoms/delphi_google_symptoms/patch.py Outdated Show resolved Hide resolved
quidel_covidtest/delphi_quidel_covidtest/pull.py Outdated Show resolved Hide resolved
doctor_visits/delphi_doctor_visits/run.py Outdated Show resolved Hide resolved
claims_hosp/delphi_claims_hosp/update_indicator.py Outdated Show resolved Hide resolved
claims_hosp/delphi_claims_hosp/update_indicator.py Outdated Show resolved Hide resolved
@@ -96,7 +93,7 @@ def run_module(params, logger=None):
df = df.reset_index()
sensor_name = "_".join([smoother, "search"])
if len(df) == 0:
logger.info("No data for %s_%s_%s", geo_res, metric.lower(), sensor_name)
logger.info("No data for signal", signal=f"{geo_res}_{metric.lower()}_{sensor_name}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Match the above?

Suggested change
logger.info("No data for signal", signal=f"{geo_res}_{metric.lower()}_{sensor_name}")
logger.info("No data for signal", geo_res=geo_res, metric=metric.lower(), sensor_name=sensor_name)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure since the original log wanted to capture it as a signal and not into seperate metric, sensor, geo....

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, these old pipelines like to mix together geo resolution, metric and sensor name into a single name and call it signal, though that doesn't match our definition of signal anywhere else. Seems better to me to separate these out, since then you can do granular search in the logs without doing substring search.

Copy link
Contributor

Choose a reason for hiding this comment

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

Two lines below this is a call to create_export_csv() which combines metric and sensor in the output file name, in what will ultimately be the signal name. How about:

Suggested change
logger.info("No data for signal", signal=f"{geo_res}_{metric.lower()}_{sensor_name}")
logger.info("No data for signal", geo_type=geo_res, signal=f"{metric}_{sensor_name}")

Should we use this opportunity to add better logging to create_export_csv()? @aysim319, you have something planned to change doctor visits and hospital admissions to use this method, right? Perhaps we can add the logging then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah.. I think it's better to revisit once all the indicators are using create_export_csv... because at least for hospital-admissions it doesn't quite use the metric and the sensor combination if I recall

@aysim319
Copy link
Contributor Author

looks pretty good! i marked a few things i think you mightve missed, and tried to change filename= where it actually referred to a directory and not a singular file.

Ah yeah, that was an intentional choice. I didn't see any output_path being used and it techincally also has the filename so whynot and worst comes to worst someone tells me it's not right and i'd fix it.

@melange396
Copy link
Contributor

im gonna set this to "draft" and then back again to try to get ci to re-run

@melange396 melange396 marked this pull request as draft August 29, 2024 14:50
@melange396 melange396 marked this pull request as ready for review August 29, 2024 14:50
Copy link
Contributor

@dshemetov dshemetov left a comment

Choose a reason for hiding this comment

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

We'll likely make more adjustments, but this seems like a nice incremental change for the better to me. Let's make an issue to follow up on a few more changes once all indicators are migrated to create_export_csv.

changehc/delphi_changehc/update_sensor.py Outdated Show resolved Hide resolved
changehc/delphi_changehc/update_sensor.py Outdated Show resolved Hide resolved
changehc/delphi_changehc/update_sensor.py Outdated Show resolved Hide resolved
doctor_visits/tests/receiving/.gitignore Outdated Show resolved Hide resolved
@aysim319
Copy link
Contributor Author

aysim319 commented Sep 9, 2024

./changehc/delphi_changehc/sensor.py:121: logger.debug("{0}: {1:.3f},[{2:.3f}]".format(
./changehc/delphi_changehc/update_sensor.py:52: logger.warning("value suspiciously high, {0}: {1}".format(
./changehc/delphi_changehc/update_sensor.py:149: self.logger.error("{0} is invalid, pick one of 'county', "
./doctor_visits/delphi_doctor_visits/sensor.py:242: logger.debug(f"{geo_id}: {new_rates[-1]:.3f},[{se[-1]:.3f}]")
./claims_hosp/delphi_claims_hosp/indicator.py:146: logging.debug("%s: %05.3f, [%05.3f]

The second one is one that I missed and third one, I didn't feel like parameterizing a wrong value made sense, but I could also see why it would be helpful...

But for the rest, I think it's better to leave it as is as they're debugging logs where I think seeing the message as is seems more helpful instead of having it parameterized.

Edited changed all of the instance

@aysim319
Copy link
Contributor Author

aysim319 commented Sep 10, 2024

@dshemetov since you and david is planning a formatting PR, thought I ping you about this
getting inconsistent behavior for darker:
similar isssue: psf/black#1140

in _delphi_utils.delphi_utils.runner.py
line 63-66 and 82:
local darker wants one line

# Logging - Starting Indicator
        logger.info("Started a covidcast-indicator", indicator_name=ind_name, current_version=current_version)
    else:
        logger.info("Started a covidcast-indicator without version.cfg", indicator_name=ind_name)      

logger.error("Flash step timed out, terminating", elapsed_time_in_seconds=round(time.time() - start, 2))

CI wants multi-line

@@ -62,11 +62,11 @@
                     current_version = current_version.replace("current_version = ", "")
     #Logging - Starting Indicator
         logger.info(
             "Started a covidcast-indicator",
             indicator_name=ind_name,
-            current_version=current_version
+            current_version=current_version,
         )
     else:
         logger.info(
             "Started a covidcast-indicator without version.cfg", indicator_name=ind_name
         )
@@ -83,13 +83,14 @@
             logger.info("Completed flash step",
                     elapsed_time_in_seconds = round(time.time() - start, 2))
             break
         time.sleep(1)
     else:
-        logger.error("Flash step timed out, terminating",
-                     elapsed_time_in_seconds=round(time.time() - start, 2)
-                 )
+        logger.error(
+            "Flash step timed out, terminating",
+            elapsed_time_in_seconds=round(time.time() - start, 2),
+        )

@dshemetov
Copy link
Contributor

dshemetov commented Sep 11, 2024

Hm, is it resolved now or did you have to manually adjust it to make CI happy? I might need to point the format commands in both CI and Makefiles to the pyproject.toml just to eliminate the possibility that they're not finding it (it specifies line-length = 120 there and this seems like a disagreement about line-length).

@aysim319
Copy link
Contributor Author

Hm, is it resolved now or did you have to manually adjust it to make CI happy? I might need to point the format commands in both CI and Makefiles to the pyproject.toml just to eliminate the possibility that they're not finding it (it specifies line-length = 120 there and this seems like a disagreement about line-length).

I had to manually adjust it .... :/

Copy link
Contributor

@melange396 melange396 left a comment

Choose a reason for hiding this comment

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

last ones!

_delphi_utils_python/delphi_utils/runner.py Outdated Show resolved Hide resolved
changehc/delphi_changehc/update_sensor.py Outdated Show resolved Hide resolved
changehc/delphi_changehc/sensor.py Outdated Show resolved Hide resolved
claims_hosp/delphi_claims_hosp/indicator.py Outdated Show resolved Hide resolved
doctor_visits/delphi_doctor_visits/sensor.py Outdated Show resolved Hide resolved
@melange396
Copy link
Contributor

@aysim319 i removed some stray files that somehow wandered into your last commit, and i changed the format of a reverted logger call back to make it pass linting.

@melange396 melange396 merged commit 12a9712 into main Sep 18, 2024
16 checks passed
@melange396 melange396 deleted the 2025-fix-unstruc-logging branch September 18, 2024 21:41
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.

4 participants