Skip to content

[Streams 🌊] Improve definition narrowing and reduntant requests#215897

Merged
tonyghiani merged 10 commits intoelastic:mainfrom
tonyghiani:refactor/improve-narrowing-and-requests
Apr 1, 2025
Merged

[Streams 🌊] Improve definition narrowing and reduntant requests#215897
tonyghiani merged 10 commits intoelastic:mainfrom
tonyghiani:refactor/improve-narrowing-and-requests

Conversation

@tonyghiani
Copy link
Contributor

@tonyghiani tonyghiani commented Mar 25, 2025

📓 Summary

These changes lift the check against the definition existence and narrows its value for the react context consumers.

It also fixes reduntant requests for the AI connectors used for the grok parsing suggestions.

@flash1293 I'd expect to use the AI capabilities across more places for the enrichment experience, we should probably lift the AI capabilities as part of the page initialization at a certain point, although it's not needed yet 👌

@tonyghiani tonyghiani added release_note:skip Skip the PR/issue when compiling release notes Team:obs-onboarding Observability Onboarding Team backport:version Backport to applied version labels Feature:Streams This is the label for the Streams Project v9.1.0 v8.19.0 labels Mar 25, 2025
@tonyghiani tonyghiani marked this pull request as ready for review March 25, 2025 14:40
@tonyghiani tonyghiani requested review from a team as code owners March 25, 2025 14:40
@elasticmachine
Copy link
Contributor

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

@flash1293
Copy link
Contributor

DIdn't check in depth yet, but this might be related to #215517 ? Maybe not. My PR is improving the loading of the definition, maybe it's upstream from your changes. Will check later.

@tonyghiani
Copy link
Contributor Author

Didn't check in depth yet, but this might be related to #215517 ?

Does not seems related, this work only help to guarantee the definition already exists inside the StreamDetailProvider that fetches the definition, lifting all the if (!definition) return null kind of checks we have around the codebase.

The fix for reduntant requests for connectors is also unrelated.

@flash1293
Copy link
Contributor

Cool - let's get rid of all the unnecessary loading :)

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Please don't merge yet

@tonyghiani
Copy link
Contributor Author

Please don't merge yet

@flash1293 is there any specific blocker on this?

@flash1293
Copy link
Contributor

I like how this makes the code cleaner, but I don't like how it changes the way the page is rendered progressively.

This is the current state:

current_page_load

This is the state after your change:
changed_page_load

It basically renders a blank page for a bit, while the previous version shows an empty skeleton that's then filled in (we don't show one of the panels right away, we should probably fix that).

Not sure about the easiest way to handle it, but I'm not 100% convinced this change is a net positive.

@tonyghiani
Copy link
Contributor Author

It basically renders a blank page for a bit, while the previous version shows an empty skeleton that's then filled in (we don't show one of the panels right away, we should probably fix that).

That's a fair concern and we should probably address it, IMO a simple page skeleton or loader while loading would be enough instead of rendering the blank page, mostly because it prevents us from showing a lot of empty components around or multiple loading states. I can take a look back at this, I'll ping you later with some changes.

@flash1293
Copy link
Contributor

A proper skeleton would be great 👍

@flash1293
Copy link
Contributor

I think a centered loader would probably be fine too - in a lot of cases this request is fairly fast. I also don't want us to lose too much time on this.

@dgieselaar
Copy link
Contributor

dgieselaar commented Mar 27, 2025

@tonyghiani perhaps just wrap in a waitUntil() function that renders a loading spinner until a certain condition is resolved? I figure we can use it many places. e.g.:

import { z } from 'zod';
import React from 'react';

function waitUntil<TProps extends Record<string, any>, U extends Partial<TProps>>(
  schema: z.Schema<U> | (( props:TProps ) => U | undefined),
  next: (props: TProps & U) => React.ReactNode
): React.FC<TProps> {
  if (typeof schema === 'function') {
    return ( props:TProps ) => {
      const validated = schema(props);
      if (validated) {
        return next({
          ...props,
          ...validated
        });
      }
      return <EuiLoadingSpinner/>;
    }
  }
  return (props: TProps) => {
    const result = schema.safeParse(props);
    if (!result.success) {
      return null;
    }
    return <>{next({ ...props, ...result.data })}</>;
  };
}

export const MyComponent:React.FC<{ maybe?:string }> = waitUntil(
  ( props ) => {
    if (props.maybe) {
      return {
        ...props,
        maybe: props.maybe!
      };
    }
    return undefined;
  },
  next => {
    return null;
  }
)

@tonyghiani
Copy link
Contributor Author

@flash1293 I added a simple spinner as a full page skeleton might be overkilling and it would appear for a very short time, the spinner appears on the first load but not while the definition is revalidated to avoid page unmounts unnecessarily, sort of SWR approach.
I noticed an issue that reloads the definition when going to the management tab, but I think you addressed it already in #215517. This should be ready for another check 👌

@dgieselaar thanks for the suggestion, that would make sense if case we have more conditional renders waiting for data-fetching, in this case a simple if statement does the job and the HOC + zod seems a bit too much until we need it, worth keeping an eye on this anyway for upcoming work 👌

@tonyghiani tonyghiani requested a review from flash1293 March 31, 2025 12:15
Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

LGTM

@elasticmachine
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
streamsApp 392.9KB 392.7KB -252.0B

History

@tonyghiani tonyghiani merged commit 13b536a into elastic:main Apr 1, 2025
10 checks passed
@tonyghiani tonyghiani deleted the refactor/improve-narrowing-and-requests branch April 1, 2025 14:11
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/14197903074

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.x Backport failed because of merge conflicts

You might need to backport the following PRs to 8.x:
- 🌊 Streams: Selectors for derived samples (#213638)

Manual backport

To create the backport manually run:

node scripts/backport --pr 215897

Questions ?

Please refer to the Backport tool documentation

@tonyghiani tonyghiani added backport:version Backport to applied version labels and removed backport:version Backport to applied version labels labels Apr 2, 2025
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/14214475963

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Apr 2, 2025
…tic#215897)

## 📓 Summary

These changes lift the check against the definition existence and
narrows its value for the react context consumers.

It also fixes reduntant requests for the AI connectors used for the grok
parsing suggestions.

@flash1293 I'd expect to use the AI capabilities across more places for
the enrichment experience, we should probably lift the AI capabilities
as part of the page initialization at a certain point, although it's not
needed yet 👌

(cherry picked from commit 13b536a)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Apr 2, 2025
…#215897) (#216754)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Streams 🌊] Improve definition narrowing and reduntant requests
(#215897)](#215897)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Marco Antonio
Ghiani","email":"marcoantonio.ghiani01@gmail.com"},"sourceCommit":{"committedDate":"2025-04-01T14:10:57Z","message":"[Streams
🌊] Improve definition narrowing and reduntant requests (#215897)\n\n## 📓
Summary\n\nThese changes lift the check against the definition existence
and\nnarrows its value for the react context consumers.\n\nIt also fixes
reduntant requests for the AI connectors used for the grok\nparsing
suggestions.\n\n@flash1293 I'd expect to use the AI capabilities across
more places for\nthe enrichment experience, we should probably lift the
AI capabilities\nas part of the page initialization at a certain point,
although it's not\nneeded yet
👌","sha":"13b536aed87710e60adf9a7cc3df852a4fb50542","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:obs-ux-logs","backport:version","Feature:Streams","v9.1.0","v8.19.0"],"title":"[Streams
🌊] Improve definition narrowing and reduntant
requests","number":215897,"url":"https://github.com/elastic/kibana/pull/215897","mergeCommit":{"message":"[Streams
🌊] Improve definition narrowing and reduntant requests (#215897)\n\n## 📓
Summary\n\nThese changes lift the check against the definition existence
and\nnarrows its value for the react context consumers.\n\nIt also fixes
reduntant requests for the AI connectors used for the grok\nparsing
suggestions.\n\n@flash1293 I'd expect to use the AI capabilities across
more places for\nthe enrichment experience, we should probably lift the
AI capabilities\nas part of the page initialization at a certain point,
although it's not\nneeded yet
👌","sha":"13b536aed87710e60adf9a7cc3df852a4fb50542"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/215897","number":215897,"mergeCommit":{"message":"[Streams
🌊] Improve definition narrowing and reduntant requests (#215897)\n\n## 📓
Summary\n\nThese changes lift the check against the definition existence
and\nnarrows its value for the react context consumers.\n\nIt also fixes
reduntant requests for the AI connectors used for the grok\nparsing
suggestions.\n\n@flash1293 I'd expect to use the AI capabilities across
more places for\nthe enrichment experience, we should probably lift the
AI capabilities\nas part of the page initialization at a certain point,
although it's not\nneeded yet
👌","sha":"13b536aed87710e60adf9a7cc3df852a4fb50542"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Marco Antonio Ghiani <marcoantonio.ghiani01@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels Feature:Streams This is the label for the Streams Project release_note:skip Skip the PR/issue when compiling release notes Team:obs-onboarding Observability Onboarding Team v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants