generated from ministryofjustice/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/fmd-206 add ingestion timing (#213)
* fix: Notify on failure GHA steps referencing incorrect `input` var for environment * fix: downversion datahub cli to `0.13.2.4` * chore: type checker linting (fixes pylance type checking errors) * chore: use non-depricated suggested methods from datahub utils * perf: time ingestion sources and transformers - add calls to `time` unix command to `datahub ingest` calls - add decorators for timing function/iterator runs - use the timers for - create_cadet_databases_source - justice_data_source - `AssignCadetDatabases transformer Co-authored-by: Mat Moore <[email protected]>
- Loading branch information
1 parent
3591714
commit ffcbfe9
Showing
13 changed files
with
369 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,14 +71,14 @@ jobs: | |
DATAHUB_GMS_TOKEN: ${{ secrets.DATAHUB_GMS_TOKEN }} | ||
DATAHUB_GMS_URL: ${{ vars.DATAHUB_GMS_URL }} | ||
DATAHUB_TELEMETRY_ENABLED: false | ||
run: poetry run datahub ingest -c ingestion/create_cadet_databases.yaml | ||
run: time poetry run datahub ingest -c ingestion/create_cadet_databases.yaml | ||
|
||
- name: push metadata to datahub | ||
env: | ||
DATAHUB_GMS_TOKEN: ${{ secrets.DATAHUB_GMS_TOKEN }} | ||
DATAHUB_GMS_URL: ${{ vars.DATAHUB_GMS_URL }} | ||
DATAHUB_TELEMETRY_ENABLED: false | ||
run: poetry run datahub ingest -c ingestion/cadet.yaml | ||
run: time poetry run datahub ingest -c ingestion/cadet.yaml | ||
|
||
- name: Notify on failure | ||
uses: slackapi/[email protected] | ||
|
@@ -87,7 +87,7 @@ jobs: | |
channel-id: "C071VNHPUHZ" | ||
payload: | | ||
{ | ||
"text": ":warning: Unable to ingest CaDeT metadata on ${{inputs.env}}!", | ||
"text": ":warning: Unable to ingest CaDeT metadata on ${{inputs.ENVIRONMENT}}!", | ||
"blocks": [ | ||
{ | ||
"type": "section", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ jobs: | |
DATAHUB_GMS_TOKEN: ${{ secrets.DATAHUB_GMS_TOKEN }} | ||
DATAHUB_GMS_URL: ${{ vars.DATAHUB_GMS_URL }} | ||
DATAHUB_TELEMETRY_ENABLED: false | ||
run: poetry run datahub ingest -c ingestion/justice_data_ingest.yaml | ||
run: time poetry run datahub ingest -c ingestion/justice_data_ingest.yaml | ||
|
||
- name: Notify on failure | ||
uses: slackapi/[email protected] | ||
|
@@ -72,7 +72,7 @@ jobs: | |
channel-id: "C071VNHPUHZ" | ||
payload: | | ||
{ | ||
"text": ":warning: Unable to ingest Justice Data metadata on ${{inputs.env}}!", | ||
"text": ":warning: Unable to ingest Justice Data metadata on ${{inputs.ENVIRONMENT}}!", | ||
"blocks": [ | ||
{ | ||
"type": "section", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import logging | ||
import time | ||
from datetime import timedelta | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
|
||
|
||
def report_time(func): | ||
""" | ||
Decorator to report the total time of a function call | ||
""" | ||
|
||
def wrapped_func(*args, **kwargs): | ||
arg_types = [type(arg) for arg in args] | ||
stopwatch = Stopwatch( | ||
function=func.__name__, arg_types=arg_types, kwargs=kwargs | ||
) | ||
|
||
stopwatch.start() | ||
|
||
r = func(*args, **kwargs) | ||
|
||
stopwatch.stop() | ||
stopwatch.report() | ||
|
||
return r | ||
|
||
return wrapped_func | ||
|
||
|
||
def report_generator_time(func): | ||
""" | ||
Decorator to report the total time of an iterable | ||
""" | ||
|
||
def wrapped_func(*args, **kwargs): | ||
arg_types = [type(arg) for arg in args] | ||
stopwatch = Stopwatch( | ||
function=func.__name__, arg_types=arg_types, kwargs=kwargs | ||
) | ||
|
||
stopwatch.start() | ||
|
||
r = func(*args, **kwargs) | ||
yield from r | ||
|
||
stopwatch.stop() | ||
stopwatch.report() | ||
|
||
return r | ||
|
||
return wrapped_func | ||
|
||
|
||
class Stopwatch: | ||
""" | ||
Wrapper around the time module for timing code execution | ||
""" | ||
|
||
def __init__(self, **meta): | ||
self.running = False | ||
self.start_time = None | ||
self.stop_time = None | ||
self.elapsed = 0 | ||
joined_meta = ", ".join(f"{k}={v}" for k, v in meta.items()) | ||
self.prefix = f"TIMING: {joined_meta}, " if joined_meta else "TIMING: " | ||
|
||
def start(self): | ||
self.start_time = time.time() | ||
self.running = True | ||
|
||
def stop(self): | ||
self.running = False | ||
if not self.start_time: | ||
return | ||
|
||
now = time.time() | ||
elapsed = now - self.start_time | ||
self.stop_time = now | ||
self.elapsed += elapsed | ||
|
||
def report(self): | ||
logging.info( | ||
f"{self.prefix}" | ||
f"start_time={time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(self.start_time))}, " | ||
f"end_time={time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(self.stop_time))}, " | ||
f"elapsed_time={str(timedelta(seconds=self.elapsed))}" | ||
) |
Oops, something went wrong.