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(vis_type_vega): support reading time field #9152

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ruanyl
Copy link
Member

@ruanyl ruanyl commented Jan 7, 2025

Description

This PR introduces time range filter support to Vega visualizations with PPL queries. When "%timefield%" is specified, the time range filter from the dashboard will be applied to the PPL query automatically.

Before This PR

Vega visualizations with PPL queries did not respect the time range set on the dashboard. Regardless of the selected time range, the query remained unaffected.

After This PR

With the addition of "%timefield%", changing the time range filter on a dashboard now impacts Vega visualizations with PPL queries.

Example

{
    "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
    "data": {
        "url": {
+            "%timefield%": "timestamp",
            "%type%": "ppl",
            "body": {
                "query": "source=opensearch_dashboards_sample_data_logs | stats count() as request_count by extension | sort -request_count"
            }
        }
    }
}

Issues Resolved

#9169

Screenshot

Testing the changes

Changelog

  • feat: vega visualization with ppl now supports reading time field

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Copy link
Contributor

github-actions bot commented Jan 7, 2025

❌ Empty Changelog Section

The Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section.

opensearch-changeset-bot bot added a commit to ruanyl/OpenSearch-Dashboards that referenced this pull request Jan 7, 2025
@ruanyl ruanyl force-pushed the vega-ppl-support-timefilter-from-context branch from 39872e3 to a4be69c Compare January 7, 2025 06:26
Copy link

codecov bot commented Jan 7, 2025

Codecov Report

Attention: Patch coverage is 87.50000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 61.03%. Comparing base (2aac3ee) to head (5bbbb2d).
Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
...gins/vis_type_vega/public/data_model/ppl_parser.ts 87.50% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9152      +/-   ##
==========================================
+ Coverage   60.94%   61.03%   +0.09%     
==========================================
  Files        3809     3813       +4     
  Lines       91270    91412     +142     
  Branches    14414    14442      +28     
==========================================
+ Hits        55620    55797     +177     
+ Misses      32096    32055      -41     
- Partials     3554     3560       +6     
Flag Coverage Δ
Linux_1 29.10% <87.50%> (+0.12%) ⬆️
Linux_2 56.45% <ø> (ø)
Linux_3 38.04% <ø> (+0.06%) ⬆️
Linux_4 29.03% <ø> (-0.01%) ⬇️
Windows_1 29.13% <87.50%> (+0.14%) ⬆️
Windows_2 56.40% <ø> (ø)
Windows_3 38.03% <ø> (+0.06%) ⬆️
Windows_4 29.03% <ø> (-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.

@@ -34,6 +55,11 @@ export class PPLQueryParser {
);
}

if (timefield) {
const query = this.injectTimeFilter(url.body.query, timefield);
url.body.query = query;
Copy link
Member

Choose a reason for hiding this comment

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

Is this the url that vega uses to query the cluster? I wouldn't expect the url parser to format/mutate the url, but I'm new to this area so it may be a gap in my understanding.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this the url that vega uses to query the cluster?

Yes, url.body.query is the ppl query and will be send to opensearch. We modify it here to encapsulate the time filter from the UI, for example, the time range user selected on a dashboard. The behavior is the same as vega visualization with opensearch DSL which modified the query DSL to add time filter.

I wouldn't expect the url parser to format/mutate the url

Could you please share your concern?

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense. No concerns, my expectation was that the parser is a pure function but it looks like this is more of a parser and formatter of the original url if I'm understanding correctly.

Copy link
Member Author

Choose a reason for hiding this comment

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

I got your point now, I think we can also make it a pure function, for example we can deep copy the url object and then modify the deep copied object. I don’t notice much of a difference in this particular case since the existing parser mutate the url object as well, but I’d love to hear your thoughts on it :)

Comment on lines +43 to +44
const timefield = url[TIMEFIELD];
delete url[TIMEFIELD];
Copy link
Collaborator

@Hailong-am Hailong-am Jan 15, 2025

Choose a reason for hiding this comment

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

will this synced to other apps(discovery/dashboards)?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not the current browser url, it's the url property of vega-lite config object, the TIMEFIELD defines the time field name of current index, for example, timestamp, and it will used as the time filter of the query.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants