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

[Aggs] Fix column.meta.type for top hit, top metric and all filtered metrics #169834

Merged
merged 6 commits into from Oct 26, 2023

Conversation

mbondyra
Copy link
Contributor

@mbondyra mbondyra commented Oct 25, 2023

Summary

When checking my PR here #169258 @stratoula noticed that the column.meta.type is not set properly for last value aggregation (it always defaults to 'number', same with all the filtered metrics too!). When I dug deeper, I noticed that happens because we calculate it as:

   type:
              column.aggConfig.type.valueType
              column.aggConfig.params.field?.type ||
              'number',

and some of the AggConfigs don't have the static valueType property nor field, specifically the one with nested aggregations, like top_hits, top_metrics and filtered_metric. instead of a static valueType, I've decided to change it to a method getValueType where we can pass AggConfigs and get the type from different places internally. This way top_hits, top_metrics and filtered_metric get the type of the field from customMetric.
I also changed the values for min and max aggregation - they were set on number, but they can also be a date.

@mbondyra mbondyra added Team:Visualizations Visualization editors, elastic-charts and infrastructure release_note:skip Skip the PR/issue when compiling release notes Feature:Lens v8.12.0 labels Oct 25, 2023
@mbondyra mbondyra marked this pull request as ready for review October 25, 2023 16:02
@mbondyra mbondyra requested review from a team as code owners October 25, 2023 16:02
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-visualizations (Team:Visualizations)

@@ -16,8 +16,7 @@ export function isNumericFieldForDatatable(currentData: Datatable | undefined, a
const column = currentData?.columns.find(
(col) => col.id === accessor || getOriginalId(col.id) === accessor
);
// min and max aggs are reporting as number but are actually dates - work around this by checking for the date formatter until this is fixed at the source
Copy link
Contributor Author

Choose a reason for hiding this comment

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

now that the min and max aggs were fixed, I think we can safely remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we could also remove the code in line 24, but I am leaving it just in case if there's something I miss!

const isNumericMap: Record<string, boolean> = useMemo(() => {
const numericMap: Record<string, boolean> = {};
for (const column of firstLocalTable.columns) {
// filtered metrics result as "number" type, but have no field
Copy link
Contributor Author

Choose a reason for hiding this comment

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

now when the bug on aggs is fixed, filtered metrics will always have the value of the nested metric so we don't have to do the check here. I tested it with creating a datatable with a few metrics and seeing if they align properly:

Screenshot 2023-10-25 at 22 25 05

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that a test is failing but I think is fine, we are now actually fixing the last value alignmentws

@@ -545,53 +545,6 @@ describe('DatatableComponent', () => {
});
});

test('it detect last_value filtered metric type', () => {
Copy link
Contributor Author

@mbondyra mbondyra Oct 26, 2023

Choose a reason for hiding this comment

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

🎉 This is test is not needed anymore as it was added to guard against the buggy response from aggs that we were getting. Now, as we get a proper response (number type is always number, string is always a string) we don't have to test this.

Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

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

Tested locally and could not find issues with changes. LGTM 👍

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.

I don't find any bugs, on the contrary I think that we are improving our code a lot and we are possibly fixing bugs we don't know they exist :) Thanx Marta for working on this!

@@ -28,8 +28,7 @@ export class BaseParamType<TAggConfig extends IAggConfig = IAggConfig> {
deserialize: (value: any, aggConfig?: TAggConfig) => any;
toExpressionAst?: (value: any) => ExpressionAstExpression[] | ExpressionAstExpression | undefined;
options: any[];
valueType?: any;

getValueType: (aggConfig: IAggConfig) => any;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder is instead of any we give the DatatableColumnType will we have TS failures?

Copy link
Contributor Author

@mbondyra mbondyra Oct 26, 2023

Choose a reason for hiding this comment

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

This breaks because of the weird line I don't understand but without it the expression throws an error:
this.getValueType = () => AggConfig; in file: src/plugins/data/common/search/aggs/param_types/agg.ts

Not sure how we could fix it, I'll talk to Peter about it once he's back to understand things better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes with so many anys it makes sense! Thanx for looking into it!

const isNumericMap: Record<string, boolean> = useMemo(() => {
const numericMap: Record<string, boolean> = {};
for (const column of firstLocalTable.columns) {
// filtered metrics result as "number" type, but have no field
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that a test is failing but I think is fine, we are now actually fixing the last value alignmentws

Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

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

lgtm

@mbondyra mbondyra changed the title [Aggs] Fix valueType for top hit, top metric and all filtered metrics [Aggs] Fix column.meta.type for top hit, top metric and all filtered metrics Oct 26, 2023
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
data 2537 2539 +2

Any counts in public APIs

Total count of every any typed public API. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats any for more detailed information.

id before after diff
data 33 32 -1

Async chunks

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

id before after diff
lens 1.4MB 1.4MB -581.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
data 409.5KB 410.1KB +532.0B
Unknown metric groups

API count

id before after diff
data 3186 3188 +2

History

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

@mbondyra mbondyra merged commit cadbaee into elastic:main Oct 26, 2023
29 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Oct 26, 2023
@mbondyra mbondyra deleted the aggs/pass_correct_valueType branch October 26, 2023 14:16
bryce-b pushed a commit to bryce-b/kibana that referenced this pull request Oct 30, 2023
…metrics (elastic#169834)

## Summary

When checking my PR here elastic#169258
@stratoula noticed that the `column.meta.type` is not set properly for
last value aggregation (it always defaults to 'number', same with all
the filtered metrics too!). When I dug deeper, I noticed that happens
because we calculate it as:
```
   type:
              column.aggConfig.type.valueType
              column.aggConfig.params.field?.type ||
              'number',
```

and some of the `AggConfigs` don't have the static `valueType` property
nor field, specifically the one with nested aggregations, like top_hits,
top_metrics and filtered_metric. instead of a static `valueType`, I've
decided to change it to a method `getValueType` where we can pass
AggConfigs and get the type from different places internally. This way
`top_hits`, `top_metrics` and `filtered_metric` get the type of the
field from `customMetric`.
I also changed the values for `min` and `max` aggregation - they were
set on `number`, but they can also be a `date`.
awahab07 pushed a commit to awahab07/kibana that referenced this pull request Oct 31, 2023
…metrics (elastic#169834)

## Summary

When checking my PR here elastic#169258
@stratoula noticed that the `column.meta.type` is not set properly for
last value aggregation (it always defaults to 'number', same with all
the filtered metrics too!). When I dug deeper, I noticed that happens
because we calculate it as:
```
   type:
              column.aggConfig.type.valueType
              column.aggConfig.params.field?.type ||
              'number',
```

and some of the `AggConfigs` don't have the static `valueType` property
nor field, specifically the one with nested aggregations, like top_hits,
top_metrics and filtered_metric. instead of a static `valueType`, I've
decided to change it to a method `getValueType` where we can pass
AggConfigs and get the type from different places internally. This way
`top_hits`, `top_metrics` and `filtered_metric` get the type of the
field from `customMetric`.
I also changed the values for `min` and `max` aggregation - they were
set on `number`, but they can also be a `date`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants