Skip to content

Conversation

@crespocarlos
Copy link
Contributor

@crespocarlos crespocarlos commented Jul 30, 2025

part of #226336

Summary

This PR fixes and simplifies some things in the Infra Inventory UI

Payload simplified

The Snapshop API currently accepts query DSL in the request body. This object is complex, and there are no apparent reason for it to remain like this.

Before After
filterQuery: "{\"bool\":{\"should\":[{\"term\":{\"host.name\":{\"value\":\"advertService\"}}}],\"minimum_should_match\":1}}" kuery: "host.name:\"metricbeat-host\""

Race condition fix

An old issue with a race condition between Saved Views and URL state has been fixed

Before After
inv_state_problem inv_state_fix

Misc

  • Centralize entity-specific code in the inventory models
  • Fix caching issues with the useUrlState

Comment on lines 96 to 109
const { onViewChange } = useWaffleViewState();

useEffect(() => {
if (currentView) {
onViewChange(currentView);
}
}, [currentView, onViewChange]);

useEffect(() => {
// load snapshot data after default view loaded, unless we're not loading a view
if (currentView != null) {
reload();
}
}, [currentView, reload]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Srlsy, why?

@@ -1,101 +0,0 @@
/*
Copy link
Contributor Author

@crespocarlos crespocarlos Jul 30, 2025

Choose a reason for hiding this comment

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

This thing had become a second source of truth, causing all the shenanigans around race conditions between saved view state and URL state

});
});

it('should work with filterQuery as Lucene expressions', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

kqlQuery takes care of this

Comment on lines -54 to -57
const filterQueryAsJson = useMemo(
() => convertKueryToElasticSearchQuery(urlState.expression, metricsView?.dataViewReference),
[metricsView?.dataViewReference, urlState.expression]
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are 0 reasons to send a DSL query object to APIs

rt.partial({
accountId: rt.string,
region: rt.string,
filterQuery: rt.union([rt.string, rt.null]),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the API can handle KQL filters internally

Comment on lines +8 to +22
export const METRICS_EXPLORER_API_MAX_METRICS = 20;

export const TIMESTAMP_FIELD = '@timestamp';
export const HOST_FIELD = 'host.name';
export const CONTAINER_FIELD = 'container.id';
export const POD_FIELD = 'kubernetes.pod.uid';
export const HOST_NAME_FIELD = 'host.name';
export const CONTAINER_ID_FIELD = 'container.id';
export const KUBERNETES_POD_UID_FIELD = 'kubernetes.pod.uid';

export const METRICS_EXPLORER_API_MAX_METRICS = 20;
export const EVENT_MODULE = 'event.module';
export const METRICSET_MODULE = 'metricset.module';
export const METRICSET_NAME = 'metricset.name';
export const DATASTREAM_DATASET = 'data_stream.dataset';

// integrations
export const SYSTEM_INTEGRATION = 'system';
export const HOST_METRICS_RECEIVER_OTEL = 'hostmetricsreceiver.otel';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has to be temporary and we need a centralized place to define these constants, but this will do for this PR

urlStateKey: 'waffleFilter',
});

const [state, setState] = useState<InventoryFiltersState>(urlState);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

second source of truth

urlStateKey: 'waffleTime',
});

const [state, setState] = useState<WaffleTimeState>(urlState);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

second source of truth

urlStateKey: 'waffleOptions',
});

const [state, setState] = useState<WaffleOptionsState>(urlState);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

second source of truth

history.replace(newLocation);
}
},
[decodeUrlState, defaultState, encodeUrlState, history, urlStateKey]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

defaultState was causing setState function to be redefined during re-renders

@crespocarlos crespocarlos changed the title feat: add schema selection to host inventory alert rule [Infra] Infra Inventory refactors Jul 31, 2025
@crespocarlos crespocarlos added release_note:fix backport:skip This PR does not require backporting Team:obs-ux-infra_services - DEPRECATED DEPRECATED - Use Team:obs-presentation. v9.2.0 labels Jul 31, 2025
@crespocarlos crespocarlos marked this pull request as ready for review July 31, 2025 16:45
@crespocarlos crespocarlos requested a review from a team as a code owner July 31, 2025 16:45
@crespocarlos crespocarlos requested a review from a team July 31, 2025 16:45
@crespocarlos crespocarlos requested review from a team as code owners July 31, 2025 16:45
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-infra_services-team (Team:obs-ux-infra_services)

<EuiSelect
aria-label={i18n.translate('xpack.infra.nodeTypeExpression.select.ariaLabel', {
defaultMessage: 'Select a node type',
})}
Copy link
Contributor

Choose a reason for hiding this comment

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

A11y ❤️

schema: config.featureFlags.hostOtelEnabled
? DataSchemaFormat.SEMCONV
: DataSchemaFormat.ECS,
schema: config.featureFlags.hostOtelEnabled ? DataSchemaFormat.SEMCONV : undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we change this to undefined instead of 'ecs'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'll change this soon when we add the schema selector to the page

const [state, setState] = useState<WaffleOptionsState>(urlState);

useEffect(() => setUrlState(state), [setUrlState, state]);
const previousViewId = useRef<string | undefined>(currentView?.id);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

Copy link
Contributor

@MiriamAparicio MiriamAparicio left a comment

Choose a reason for hiding this comment

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

Thanks for making our infra live better, just added a couple of comments and a question

@crespocarlos
Copy link
Contributor Author

@elasticmachine merge upstream

@crespocarlos crespocarlos added release_note:skip Skip the PR/issue when compiling release notes and removed release_note:fix labels Aug 4, 2025
Copy link
Contributor

@tonyghiani tonyghiani left a comment

Choose a reason for hiding this comment

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

Unblocking for shared ownership of use_url_state, change LGTM

export const PrefilledInventoryAlertFlyout = ({ onClose }: { onClose(): void }) => {
const { inventoryPrefill } = useAlertPrefillContext();
const { nodeType, metric, filterQuery } = inventoryPrefill;
const { nodeType, metric, kuery } = inventoryPrefill;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of a query DSL object, inventoryPrefill will store a kql filter

nodeType,
}: Props) => {
const [popoverOpen, setPopoverOpen] = useState(false);
const [popoverOpen, { toggle: togglePopover }] = useBoolean(false);
Copy link
Contributor Author

@crespocarlos crespocarlos Aug 4, 2025

Choose a reason for hiding this comment

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

This solves a problem with the popover not closing when the focus leaves the popover if the field is clicked twice

popover_problem

export const useInventoryAlertPrefill = () => {
const [nodeType, setNodeType] = useState<InventoryItemType>('host');
const [filterQuery, setFilterQuery] = useState<string | undefined>();
const [kuery, setKuery] = useState<string | undefined>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change to store kql instead of query DSL

@crespocarlos crespocarlos enabled auto-merge (squash) August 4, 2025 14:54
@crespocarlos crespocarlos disabled auto-merge August 4, 2025 14:54
Copy link
Contributor

@cesco-f cesco-f left a comment

Choose a reason for hiding this comment

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

obs-ux-management-team changes LGTM.

Just a heads up that I see this error when creating an inventory rule from observability/alerts/rules but I see the same error in the edge-oblt cluster so I don't think it's related with changes in this PR.

Screenshot 2025-08-05 at 10 01 59

@cesco-f
Copy link
Contributor

cesco-f commented Aug 5, 2025

Same error if I try creating the rule from management/insightsAndAlerting/triggersActions/rules/create/metrics.alert.inventory.threshold

@crespocarlos
Copy link
Contributor Author

Same error if I try creating the rule from management/insightsAndAlerting/triggersActions/rules/create/metrics.alert.inventory.threshold

I think this was introduced by another PR. I'll check it. Thanks for flagging it.

@crespocarlos
Copy link
Contributor Author

triggersActions/rules/create/metrics.alert.inventory.threshold

fixed: beaacdc

image

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #132 / InfraOps App Metrics UI Home page with metrics present sort nodes by ascending value

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
infra 1531 1530 -1

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
metricsDataAccess 136 146 +10

Async chunks

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

id before after diff
infra 1.0MB 1.0MB -110.0B
metricsDataAccess 78.7KB 78.7KB -6.0B
total -116.0B

Page load bundle

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

id before after diff
infra 50.1KB 50.1KB +16.0B
metricsDataAccess 38.3KB 38.9KB +622.0B
observabilityShared 67.1KB 67.1KB -20.0B
total +618.0B
Unknown metric groups

API count

id before after diff
metricsDataAccess 136 146 +10

ESLint disabled line counts

id before after diff
infra 38 37 -1

Total ESLint disabled count

id before after diff
infra 46 45 -1

History

@crespocarlos crespocarlos merged commit 381ef6e into elastic:main Aug 5, 2025
12 checks passed
@crespocarlos crespocarlos deleted the 226336-infra-inventory-ui-improvements branch August 5, 2025 10:57
delanni pushed a commit to delanni/kibana that referenced this pull request Aug 5, 2025
part of elastic#226336 

## Summary

This PR fixes and simplifies some things in the Infra Inventory UI

**Payload simplified**

The Snapshop API currently accepts query DSL in the request body. This
object is complex, and there are no apparent reason for it to remain
like this.

| Before |           After          |
|--------|-----------------|
| `filterQuery:
"{\"bool\":{\"should\":[{\"term\":{\"host.name\":{\"value\":\"advertService\"}}}],\"minimum_should_match\":1}}"`
| `kuery: "host.name:\"metricbeat-host\""` |


**Race condition fix**

An old issue with a race condition between Saved Views and URL state has
been fixed
| Before |           After          |
|--------|-----------------|

|![inv_state_problem](https://github.com/user-attachments/assets/d3c3e3b1-11a8-4b48-832c-42b17de4f3ac)|![inv_state_fix](https://github.com/user-attachments/assets/90e597a8-6ee8-42cd-9a81-915c8ca2ec7f)|



**Misc**
- Centralize entity-specific code in the inventory models
- Fix caching issues with the `useUrlState`

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
@wildemat wildemat mentioned this pull request Aug 7, 2025
10 tasks
NicholasPeretti pushed a commit to NicholasPeretti/kibana that referenced this pull request Aug 18, 2025
part of elastic#226336 

## Summary

This PR fixes and simplifies some things in the Infra Inventory UI

**Payload simplified**

The Snapshop API currently accepts query DSL in the request body. This
object is complex, and there are no apparent reason for it to remain
like this.

| Before |           After          |
|--------|-----------------|
| `filterQuery:
"{\"bool\":{\"should\":[{\"term\":{\"host.name\":{\"value\":\"advertService\"}}}],\"minimum_should_match\":1}}"`
| `kuery: "host.name:\"metricbeat-host\""` |


**Race condition fix**

An old issue with a race condition between Saved Views and URL state has
been fixed
| Before |           After          |
|--------|-----------------|

|![inv_state_problem](https://github.com/user-attachments/assets/d3c3e3b1-11a8-4b48-832c-42b17de4f3ac)|![inv_state_fix](https://github.com/user-attachments/assets/90e597a8-6ee8-42cd-9a81-915c8ca2ec7f)|



**Misc**
- Centralize entity-specific code in the inventory models
- Fix caching issues with the `useUrlState`

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-infra_services - DEPRECATED DEPRECATED - Use Team:obs-presentation. v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants