-
Notifications
You must be signed in to change notification settings - Fork 171
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
Ele 1484 source freshness invocation #1165
Conversation
ELE-1484 Source Freshness Invocation ID
Is your feature request related to a problem? Please describe. Describe the solution you'd like
Describe alternatives you've considered Additional context
Would you be willing to contribute this feature? |
👋 @NoyaArie |
This PR also covers upload-once-source-freshness-results |
) | ||
select count(*) as count | ||
from invocations | ||
where invocation_id = {{ "'" ~ invocation_id ~ "'" }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where invocation_id = {{ "'" ~ invocation_id ~ "'" }} | |
where invocation_id = {{ elementary.edr_quote(invocation_id) }} |
@@ -1,5 +1,5 @@ | |||
{% macro upload_source_freshness(results) %} | |||
{% set source_freshness_results_dicts = fromjson(results) %} | |||
{% set source_freshness_results_dict = fromjson(results) %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this does take multiple dicts though as target/sources.json:results
is a list.
Otherwise it wouldn't work since upload_artifacts_to_table
takes a list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renaming to source_freshness_results
:)
where invocation_id = {{ "'" ~ invocation_id ~ "'" }} | ||
{% endset %} | ||
|
||
{% set result = elementary.run_query(query) %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use .result_value()
?
self.upload_results(results) | ||
click.echo("Uploaded source freshness results successfully.") | ||
sources_file_contents = self.get_sources_file_contents() | ||
if sources_file_contents: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How could it be falsely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
empty file, which should not happen, but since in the next line accessing to keys prefer checking it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I would just remove it as this is not something that can happen and this flow is a bit unclear.
If you want to keep it, maybe do:
if not sources_file_contents:
raise raise click.ClickException("Unexpectedly found an empty source.json file.")
@@ -0,0 +1,19 @@ | |||
{% macro validate_source_freshness_invocation(invocation_id, days_back=14) %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Care to rename this macro to something that indicates that it checks whether the source freshness was uploaded or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renaming the macro to can_upload_source_freshness
, and the internal variables as well
c48b93f
to
a9447b1
Compare
self.upload_results(results) | ||
click.echo("Uploaded source freshness results successfully.") | ||
sources_file_contents = self.get_sources_file_contents() | ||
if sources_file_contents: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I would just remove it as this is not something that can happen and this flow is a bit unclear.
If you want to keep it, maybe do:
if not sources_file_contents:
raise raise click.ClickException("Unexpectedly found an empty source.json file.")
chunk_size = 100 | ||
chunk_list = list(range(0, len(results), chunk_size)) | ||
upload_with_progress_bar = alive_it( | ||
chunk_list, title="Uploading source freshness results" | ||
) | ||
for chunk in upload_with_progress_bar: | ||
results_segment = results[chunk : chunk + chunk_size] | ||
|
||
for result in results_segment: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to pass the metadata to flatten_source_freshness for each record
No description provided.