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

feat: add chart id and dataset id to global logs #26443

Merged
merged 5 commits into from
Jan 29, 2024

Conversation

eschutho
Copy link
Member

@eschutho eschutho commented Jan 10, 2024

SUMMARY

part two of the context logs, this adds the chart and dataset ids to global context when the /data endpoints are called for use in the sql mutator.

An example of a sql_mutator override to log these values would be:

def mutator(sql: str, **kwargs: Any) -> str:
    key = "6dcd92a04feb50f14bbcf07c661680ba"
    output = (
        f"-- {key}\n"
        + f"-- slice_id: {g.logs_context.get('slice_id') if hasattr(g,'logs_context') else ''}\n"
        + f"-- dataset_id:{g.logs_context.get('dataset_id') if hasattr(g,'logs_context') else ''}\n"
    )
    return output + f"{sql}\n-- {key}"

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

After with the mutator above:
USA_Births_Names

TESTING INSTRUCTIONS

Update the sql mutator override, load a dashboard and click "view query" on a chart.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@john-bodley john-bodley self-requested a review January 10, 2024 18:34
@eschutho eschutho force-pushed the elizabeth/add_data_to_mutator branch 4 times, most recently from b4f77bb to 887ee8e Compare January 13, 2024 01:27
Copy link

codecov bot commented Jan 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (6a1ce6a) 69.48% compared to head (335752c) 69.49%.
Report is 52 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #26443   +/-   ##
=======================================
  Coverage   69.48%   69.49%           
=======================================
  Files        1894     1895    +1     
  Lines       74151    74194   +43     
  Branches     8243     8243           
=======================================
+ Hits        51527    51563   +36     
- Misses      20555    20562    +7     
  Partials     2069     2069           
Flag Coverage Δ
hive 53.82% <100.00%> (+0.01%) ⬆️
mysql 77.97% <100.00%> (-0.02%) ⬇️
postgres 78.07% <100.00%> (-0.02%) ⬇️
presto 53.77% <100.00%> (+0.01%) ⬆️
python 83.02% <100.00%> (+<0.01%) ⬆️
sqlite 77.65% <100.00%> (-0.02%) ⬇️
unit 56.40% <80.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


# limit data that can be saved to logs_context
# in order to prevent antipatterns
available_logs_context_keys = [
Copy link

@hwmarkcheng hwmarkcheng Jan 15, 2024

Choose a reason for hiding this comment

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

Would it make sense for this to be a parameter? Right now this is hard coded for query related logging, but it might be useful for other logging purposes.

If we add the available_logs_context_keys as a parameter when the decorator is called we can still keep the functionality of limiting data but for that specific call.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's a good question. In the SIP review we talked about trying to limit antipatterns of people putting random data into global context so the intention here is to use this list to limit what data can be passed in with the decorator, but there are definitely a lot of other use cases. I have three others on my todo list. I would suggest that if you think there's more data that should be considered for logging, then add it to the list in a PR and we'll see if it fits. That way we're still limiting the data that the decorator can accept, but we're not completely limited to just the set that is here now. How does that sound?

Choose a reason for hiding this comment

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

Hey Elizabeth, that sounds great! As for now there's no other data we need aside from dataset_id/slice_id so this is good on our end. Was just pointing this out as a future suggestion.

@eschutho eschutho force-pushed the elizabeth/add_data_to_mutator branch from 5677b80 to 648b8c6 Compare January 23, 2024 01:26
@eschutho eschutho marked this pull request as ready for review January 23, 2024 01:27
Comment on lines 431 to 436
context_func=lambda self, form_data: {
"dataset_id": form_data.get("datasource", {}).get("id")
if isinstance(form_data.get("datasource"), dict)
and form_data.get("datasource").get("type") == DatasourceType.TABLE.value
else None,
"slice_id": form_data.get("form_data", {}).get("slice_id"),
Copy link
Member

Choose a reason for hiding this comment

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

Can we move this to a separate function to increase readability?

@pull-request-size pull-request-size bot added size/M and removed size/S labels Jan 26, 2024
@eschutho eschutho merged commit 78dc6ce into apache:master Jan 29, 2024
40 checks passed
@eschutho eschutho deleted the elizabeth/add_data_to_mutator branch January 29, 2024 18:03
sadpandajoe pushed a commit to preset-io/superset that referenced this pull request Jan 29, 2024
eschutho added a commit to preset-io/superset that referenced this pull request Jan 31, 2024
sfirke pushed a commit to sfirke/superset that referenced this pull request Mar 22, 2024
@mistercrunch mistercrunch added the 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels label Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/M 🚢 4.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants