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

[TSVB] Top_hit supports runtime fields #103401

Merged
merged 9 commits into from
Jul 12, 2021

Conversation

DianaDerevyankina
Copy link
Contributor

@DianaDerevyankina DianaDerevyankina commented Jun 25, 2021

Closes #101705

Summary

  • Replaced top_hits search request _source option with the fields option to retrieve the fields.

  • Fix unnecessary symbol escaping for table cells values.

    Before:
    image
    After:
    image

Checklist

For maintainers

@DianaDerevyankina DianaDerevyankina added Feature:TSVB TSVB (Time Series Visual Builder) Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.15.0 labels Jun 25, 2021
@DianaDerevyankina DianaDerevyankina self-assigned this Jun 25, 2021
@alexwizp
Copy link
Contributor

@elasticmachine merge upstream

@@ -110,7 +110,7 @@ const TopHitAggUi = (props) => {
PANEL_TYPES.METRIC,
PANEL_TYPES.MARKDOWN,
].includes(panel.type)
? [KBN_FIELD_TYPES.NUMBER, KBN_FIELD_TYPES.STRING]
? [KBN_FIELD_TYPES.NUMBER, KBN_FIELD_TYPES.STRING, KBN_FIELD_TYPES.DATE]
Copy link
Contributor

@alexwizp alexwizp Jun 28, 2021

Choose a reason for hiding this comment

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

You are right here.

  • For TimeSeries/Gauge we support only KBN_FIELD_TYPES.NUMBER field type.
  • For Table/Metric/Markdown - KBN_FIELD_TYPES.NUMBER, KBN_FIELD_TYPES.STRING, KBN_FIELD_TYPES.DATE

The main problem in your PR and code which was implemented before your changes that there are no correct Aggregation function for String and Date.

Currenly it's undefined but I prefer to do it like in classical visualizations with Concatenate option

image

Screen if I select Date field
image

Copy link
Contributor

@alexwizp alexwizp left a comment

Choose a reason for hiding this comment

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

Needs some changes

@@ -45,7 +45,7 @@ export const getAggValue = (row, metric) => {
}

const hits = get(row, [metric.id, 'docs', 'hits', 'hits'], []);
const values = hits.map((doc) => get(doc, `_source.${metric.field}`));
const [values] = hits.map((doc) => doc.fields[metric.field]);
Copy link
Contributor

Choose a reason for hiding this comment

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

should be double checked. Why you take only first value?

@@ -110,7 +110,7 @@ const TopHitAggUi = (props) => {
PANEL_TYPES.METRIC,
PANEL_TYPES.MARKDOWN,
].includes(panel.type)
? [KBN_FIELD_TYPES.NUMBER, KBN_FIELD_TYPES.STRING]
? [KBN_FIELD_TYPES.NUMBER, KBN_FIELD_TYPES.STRING, KBN_FIELD_TYPES.DATE]
: [KBN_FIELD_TYPES.NUMBER];

Copy link
Contributor

Choose a reason for hiding this comment

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

@dziyanadzeraviankina @stratoula I see after switching from numbers to strings (and now to dates) our model keep wrong value (value which was selected to numbers). On UI we see Select... . This is issue should be fixed.

image

Please think about adding UI effect to set first option from available list

  useEffect(() => {
    const defaultFn = aggWithOptions?.[0].value;
    const aggWith = model[AGG_WITH_KEY];
    if (aggWith && defaultFn && aggWith !== defaultFn && !selectedAggWithOption) {
      handleChange({
        AGG_WITH_KEY: defaultFn,
      });
    }
  }, [model, selectedAggWithOption, aggWithOptions, handleChange]);

or fix it using different way, e.g. set agg_with to noop. I don't have strong opinion here

@alexwizp alexwizp requested a review from VladLasitsa July 8, 2021 10:43
order: 'desc',
};
const model = { ...defaults, ...props.model };
const defaults = useMemo(
Copy link
Contributor

Choose a reason for hiding this comment

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

in this case it looks like additional optimization. In fact, this will lead to a slight degradation in performance, since each time the React caching mechanism will be used to get the value.

If you want you can move it to one level up and create getDefaults() method or move it directly in line 108 with removing defaults at all

@alexwizp
Copy link
Contributor

alexwizp commented Jul 9, 2021

Please run https://kibana-ci.elastic.co/job/kibana+flaky-test-suite-runner/ to be sure that your new tests are not flucky

@DianaDerevyankina
Copy link
Contributor Author

@alexwizp

Please run https://kibana-ci.elastic.co/job/kibana+flaky-test-suite-runner/ to be sure that your new tests are not flucky

Sure, no failures

image

Copy link
Contributor

@VladLasitsa VladLasitsa left a comment

Choose a reason for hiding this comment

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

LGTM, tested locally

@alexwizp alexwizp requested a review from stratoula July 9, 2021 12:36
@alexwizp alexwizp marked this pull request as ready for review July 9, 2021 12:37
@alexwizp alexwizp requested a review from a team July 9, 2021 12:37
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

Copy link
Contributor

@alexwizp alexwizp left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you

@DianaDerevyankina
Copy link
Contributor Author

@elasticmachine merge upstream

@stratoula stratoula added release_note:fix and removed release_note:skip Skip the PR/issue when compiling release notes labels Jul 12, 2021
@stratoula stratoula requested review from wylieconlon and dej611 July 12, 2021 08:32
@stratoula stratoula changed the title [TSVB] Refactor top-hit aggregation to work with fields instead of _source [TSVB] Top_hit supports runtime fields Jul 12, 2021
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
visTypeTimeseries 1001.6KB 1002.3KB +639.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @dziyanadzeraviankina

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

Code LGTM,

I tested it with runtime fields and "normal" ones. It works fine. Thanx for all the tests added ❤️

@DianaDerevyankina DianaDerevyankina merged commit 87066e0 into elastic:master Jul 12, 2021
DianaDerevyankina added a commit to DianaDerevyankina/kibana that referenced this pull request Jul 12, 2021
* [TSVB] Refactor top-hit aggregation to work with fields instead of _source

* Allow select date strings for top_hit aggregation in table, metric, and markdown

* Fix agg_with handling for top_hit and add some tests

* Refactor get_agg_value and fix type check for _tsvb_chart

* Refactor top_hit.js

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
DianaDerevyankina added a commit that referenced this pull request Jul 12, 2021
* [TSVB] Refactor top-hit aggregation to work with fields instead of _source

* Allow select date strings for top_hit aggregation in table, metric, and markdown

* Fix agg_with handling for top_hit and add some tests

* Refactor get_agg_value and fix type check for _tsvb_chart

* Refactor top_hit.js

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:TSVB TSVB (Time Series Visual Builder) release_note:fix Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.15.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TSVB] Refactor top-hit aggregation to work with fields instead of _source
6 participants