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

Index Patterns Management - use /_resolve endpoint for data streams support #70271

Merged
merged 32 commits into from
Jul 8, 2020

Conversation

mattkime
Copy link
Contributor

@mattkime mattkime commented Jun 29, 2020

Summary

Addresses #70271 #61368 #67329 #61368

  • Index patterns management now uses the _/resolve/indices endpoint - Resolve index API elasticsearch#57626
  • Can create index pattern against data streams and frozen indices
  • Misc UI rendering improvements

Step 1 - define pattern

Before
Screen Shot 2020-07-06 at 8 19 25 AM
After
Screen Shot 2020-07-07 at 5 10 47 PM

Step 1 - matched items

Before
Screen Shot 2020-07-06 at 8 19 54 AM
After
Screen Shot 2020-07-06 at 5 08 30 PM

Step 2

Before
Screen Shot 2020-07-06 at 8 20 11 AM
After
Screen Shot 2020-07-06 at 3 20 44 PM

Useful commands for creating data streams. Create an index template, a data stream, and then add aa doc to create the index behind the data stream

PUT /_index_template/generic-logs
{
    "index_patterns": ["logs-*", "test_data_stream"],
    "template": {
        "mappings" : {
            "properties": {
                "@timestamp": {
                    "type": "date"
                }
            }
        }
    },
    "data_stream": {
        "timestamp_field": "@timestamp"
    }
}

PUT /_data_stream/test_data_stream

POST test_data_stream/_doc/
{
    "@timestamp" : "2020-10-10"
}

Create an alias

POST blogs/_doc/
{
    "user" : "matt",
    "message" : 20
}

POST /_aliases
{
    "actions" : [
        { "add" : { "index" : "blogs", "alias" : "alias1" } }
    ]
}

Checklist

Delete any items that are not applicable to this PR.

@mattkime mattkime added release_note:skip Skip the PR/issue when compiling release notes v8.0.0 v7.9.0 Team:AppArch labels Jun 29, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch (Team:AppArch)

@mattkime mattkime added Feature:Data Views Data Views code and UI - index patterns before 8.0 Feature:Kibana Management Feature label for Data Views, Advanced Setting, Saved Object management pages labels Jun 29, 2020
@elastic elastic deleted a comment from kibanamachine Jul 2, 2020
@mattkime
Copy link
Contributor Author

mattkime commented Jul 2, 2020

@elasticmachine merge upstream

@elastic elastic deleted a comment from kibanamachine Jul 2, 2020
@mattkime mattkime requested a review from ppisljar July 3, 2020 04:14
@elastic elastic deleted a comment from kibanamachine Jul 6, 2020
Copy link
Contributor

@mdefazio mdefazio left a comment

Choose a reason for hiding this comment

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

UI design looks good! Thanks for making the edits!

@mattkime
Copy link
Contributor Author

mattkime commented Jul 7, 2020

@elasticmachine merge upstream

Copy link
Member

@lukeelmers lukeelmers 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 (chrome macos), and it works great!

Added a few comments but code overall LGTM

src/plugins/index_pattern_management/server/plugin.ts Outdated Show resolved Hide resolved
{ canPreselect, timeFieldName }: { canPreselect: boolean; timeFieldName?: string },
matchedItem
) => {
const dataStreamItem = matchedItem.item as ResolveIndexResponseItemDataStream;
Copy link
Member

Choose a reason for hiding this comment

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

nit: Would be nice to use typeguards to differentiate between the different possible matchedItem.item types so that you don't need casting here.

Or perhaps make MatchedItem generic so that you can optionally specify an item type if it is known at compile time:

type MatchedItemTypes =
    | ResolveIndexResponseItemIndex
    | ResolveIndexResponseItemAlias
    | ResolveIndexResponseItemDataStream;

export interface MatchedItem<I extends MatchedItemTypes = MatchedItemTypes> {
  name: string;
  tags: Tag[];
  item: I;
}

// usage:
type MatchedDataStreamItem = MatchedItem<ResolveIndexResponseItemDataStream>;
export const canPreselectTimeField = (indices: MatchedDataStreamItem[]) => {}

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 just made the MatchedItem['item'] definition more flexible. I think the larger problem is that I'm trying to determine a specific type from a general type. It seems that typescript will allow me to write a function to do it but that seems like overkill just to check a single field. The best fix would be to track Data source items in their own array but I'd rather not make that change at this stage.

@@ -106,22 +111,43 @@ export const Header: React.FC<HeaderProps> = ({
isInvalid={isInputInvalid}
onChange={onQueryChanged}
Copy link
Member

Choose a reason for hiding this comment

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

Should we be debouncing this?

While testing locally I noticed that we are firing a new HTTP request on every keystroke, which can be a lot if you are typing a longer index pattern name.

To be clear, this behavior existed before this PR, but since we are updating related behavior here I wonder if it'd be worth throwing this in a lodash debounce

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 attempted this but the debounce functionality was becoming troublesome to implement since it was conflicting with the code that appends a *. I'll try to address in a separate PR. If nothing else, the calls to _resolve/indices are much more performant than running queries as the code previously did.

@mattkime mattkime requested a review from a team as a code owner July 7, 2020 21:31
Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

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

Code changes LGTM, pending green build!

I did not retest in a browser to verify the pluralization changes, but the syntax looks correct AFAICT.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

✅ unchanged

History

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

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

Looks like we got pinged due to a change in the rollup plugin, but the code in question pertains to index patterns. I'm going to approve without reviewing to dismiss the codeowner requirement.

@mattkime mattkime merged commit ea7012e into elastic:master Jul 8, 2020
mattkime added a commit to mattkime/kibana that referenced this pull request Jul 8, 2020
… support (elastic#70271)

* Index Patterns Management - use `/_resolve` endpoint for data streams support
mattkime added a commit that referenced this pull request Jul 8, 2020
… support (#70271) (#71105)

* Index Patterns Management - use `/_resolve` endpoint for data streams support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Data Views Data Views code and UI - index patterns before 8.0 Feature:Kibana Management Feature label for Data Views, Advanced Setting, Saved Object management pages release_note:skip Skip the PR/issue when compiling release notes v7.9.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants