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

Log some study definition stats and timings #782

Merged
merged 10 commits into from
Apr 22, 2022
Merged

Log some study definition stats and timings #782

merged 10 commits into from
Apr 22, 2022

Conversation

rebkwok
Copy link
Contributor

@rebkwok rebkwok commented Apr 13, 2022

Log some study definition stats and execution timings:

  • study definition variable count
  • count of variables using codelists
    • for each of these, size of the codelist
  • output column count
  • table query count
  • joins count
  • index dates - count, min, max
  • measures count
  • timing:
    • each executed query
    • full generate_cohort for each index date, and all index dates
    • writing cohort to file
    • generate_measures, for each input file

see #777

@rebkwok
Copy link
Contributor Author

rebkwok commented Apr 13, 2022

From the suggestions in the issue, the one that I haven't implemented is the suggestion to log

min and max dates from here

Min/max dates can be dynamic and involve other queries, not just dates, so I'm deferring figuring out how to deal with those until Seb's back and I can ask him

@rebkwok rebkwok changed the title Log stats Log some study definition stats and timings Apr 13, 2022
Copy link
Member

@bloodearnest bloodearnest left a comment

Choose a reason for hiding this comment

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

This is wonderful. It will really help figuring stuff out.

Have left a scatter shot of minor questions and comments.

cohortextractor/cohortextractor.py Outdated Show resolved Hide resolved
cohortextractor/emis_backend.py Outdated Show resolved Hide resolved
cohortextractor/emis_backend.py Outdated Show resolved Hide resolved
cohortextractor/log_utils.py Outdated Show resolved Hide resolved


def log_stats(logger, **kwargs):
logger.info("cohortextractor-stats", **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

Mild nit: I think the "cohortextractor" prefix is a possibly redundant, I'd probably prefer just "stats"

Copy link
Member

Choose a reason for hiding this comment

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

I'm not very familiar with structlog or cohortextractor logging, but will this result in all stats being logged when running a cohortextractor job in with opensafely run?

I think we only want to enable this logging in production, as with dummy data its a) not very useful and b) noisy

Could we possibly disable this when running against the expectations backend? And also maybe enabled environment variable for testing/debugging?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I just realised most of the logging will only happen in prod anyway, as it's in the tpp/emis bits. But some would still happen in local running too, so probably still worth checking if it's noisy or confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mild nit: I think the "cohortextractor" prefix is a possibly redundant, I'd probably prefer just "stats"

The prefix was Dave's suggestion, but I'm sure he's not commited to it :). I think we want something unique for greppableness - "stats" might be too likely to turn up in places other than the stats log name

Copy link
Member

Choose a reason for hiding this comment

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

Fair point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I just realised most of the logging will only happen in prod anyway, as it's in the tpp/emis bits. But some would still happen in local running too, so probably still worth checking if it's noisy or confusing.

Yes, all the particularly noisy things (SQL logging) will only happen on prod. I ran the SRO measures study locally to see what it produces, and I think it's ok - this is the log for the main cohort generation:
generate_study_population.log

It has all the codelist variables and sizes, which could possibly be useful in a local run, and it has the timing for the overall generate_cohort for each index date, which isn't particularly useful in a local run, but it's not that much noise

cohortextractor/log_utils.py Outdated Show resolved Hide resolved
tests/test_logging.py Outdated Show resolved Hide resolved
cohortextractor/cohortextractor.py Outdated Show resolved Hide resolved
@rebkwok
Copy link
Contributor Author

rebkwok commented Apr 14, 2022

@bloodearnest I think this is ready for another review now - thanks for all the suggestions!

Copy link
Member

@bloodearnest bloodearnest left a comment

Choose a reason for hiding this comment

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

This is fab. ONWARDS!

@rebkwok rebkwok merged commit 8d85aa9 into main Apr 22, 2022
@rebkwok rebkwok deleted the log-stats branch April 22, 2022 15:27
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.

2 participants