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

Add ignore_missing_component_templates config option #92436

Merged
merged 39 commits into from
Jan 31, 2023

Conversation

ruflin
Copy link
Contributor

@ruflin ruflin commented Dec 19, 2022

This change introduces the configuration option ignore_missing_component_templates as discussed in #92426 The implementation option 6 was picked with a slight adjustment meaning no patterns are allowed.

Implementation

During the creation of an index template, the list of component templates is checked if all component templates exist. This check is extended to skip any component templates which are listed under ignore_missing_component_templates. An index template that skips the check for the component template logs-foo@custom looks as following:

PUT _index_template/logs-foo
{
  "index_patterns": ["logs-foo-*"],
  "data_stream": { },
  "composed_of": ["logs-foo@package", "logs-foo@custom"],
  "ignore_missing_component_templates": ["logs-foo@custom"],
  "priority": 500
}

The component template logs-foo@package has to exist before creation. It can be created with:

PUT _component_template/logs-foo@custom
{
  "template": {
    "mappings": {
      "properties": {
        "host.ip": {
          "type": "ip"
        }
      }
    }
  }
}

Testing

For manual testing, different scenarios can be tested. To simplify testing, the commands from .http file are added. Before each test run, a clean cluster is expected.

New behaviour, missing component template

With the new config option, it must be possible to create an index template with a missing component templates without getting an error:

### Add logs-foo@package component template

PUT http://localhost:9200/
    _component_template/logs-foo@package
Authorization: Basic elastic password
Content-Type: application/json

{
  "template": {
    "mappings": {
      "properties": {
        "host.name": {
          "type": "keyword"
        }
      }
    }
  }
}

### Add logs-foo index template

PUT http://localhost:9200/
    _index_template/logs-foo
Authorization: Basic elastic password
Content-Type: application/json

{
  "index_patterns": ["logs-foo-*"],
  "data_stream": { },
  "composed_of": ["logs-foo@package", "logs-foo@custom"],
  "ignore_missing_component_templates": ["logs-foo@custom"],
  "priority": 500
}

### Create data stream

PUT http://localhost:9200/
    _data_stream/logs-foo-bar
Authorization: Basic elastic password
Content-Type: application/json

### Check if mappings exist

GET http://localhost:9200/
    logs-foo-bar
Authorization: Basic elastic password
Content-Type: application/json

It is checked if all templates could be created and data stream mappings are correct.

Old behaviour, with all component templates

In the following, a component template is made optional but it already exists. It is checked, that it will show up in the mappings:

### Add logs-foo@package component template

PUT http://localhost:9200/
    _component_template/logs-foo@package
Authorization: Basic elastic password
Content-Type: application/json

{
  "template": {
    "mappings": {
      "properties": {
        "host.name": {
          "type": "keyword"
        }
      }
    }
  }
}

### Add logs-foo@custom component template

PUT http://localhost:9200/
    _component_template/logs-foo@custom
Authorization: Basic elastic password
Content-Type: application/json

{
  "template": {
    "mappings": {
      "properties": {
        "host.ip": {
          "type": "ip"
        }
      }
    }
  }
}

### Add logs-foo index template

PUT http://localhost:9200/
    _index_template/logs-foo
Authorization: Basic elastic password
Content-Type: application/json

{
  "index_patterns": ["logs-foo-*"],
  "data_stream": { },
  "composed_of": ["logs-foo@package", "logs-foo@custom"],
  "ignore_missing_component_templates": ["logs-foo@custom"],
  "priority": 500
}

### Create data stream

PUT http://localhost:9200/
    _data_stream/logs-foo-bar
Authorization: Basic elastic password
Content-Type: application/json

### Check if mappings exist

GET http://localhost:9200/
    logs-foo-bar
Authorization: Basic elastic password
Content-Type: application/json

Check old behaviour

Ensure, that the old behaviour still exists when a component template is used that is not part of ignore_missing_component_templates:

### Add logs-foo index template

PUT http://localhost:9200/
    _index_template/logs-foo
Authorization: Basic elastic password
Content-Type: application/json

{
  "index_patterns": ["logs-foo-*"],
  "data_stream": { },
  "composed_of": ["logs-foo@package", "logs-foo@custom"],
  "ignore_missing_component_templates": ["logs-foo@custom"],
  "priority": 500
}

As described in elastic#92426 a config option to not ignore missing component templates is needed. This introduces the config option `ignore_missing_component_templates`. If set to true, missing component templates are ignored. If set to false or not set at all, the existing behaviour applies.

This is currently a draft PR as it only contains the functionality. It still needs tests and docs. Goal is to get an initial set of opinions on it.
@ruflin ruflin self-assigned this Dec 19, 2022
@elasticsearchmachine elasticsearchmachine added v8.7.0 external-contributor Pull request authored by a developer outside the Elasticsearch team labels Dec 19, 2022
@ruflin ruflin changed the title Add ignore_missing_component_tempaltes config option Add ignore_missing_component_templates config option Dec 19, 2022
Copy link
Contributor

@abdonpijpelink abdonpijpelink left a comment

Choose a reason for hiding this comment

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

Left some comments and suggestions that should help the code snippets CI tests pass.

@ruflin ruflin marked this pull request as ready for review January 16, 2023 15:32
@elasticsearchmachine elasticsearchmachine added the needs:triage Requires assignment of a team area label label Jan 16, 2023
@ruflin
Copy link
Contributor Author

ruflin commented Jan 16, 2023

@dakrone Who would be a good person to have a first read of this PR. I would like to know if the approach I'm following is the expected path as this is has been my first ES PR in quite some time.

@ruflin
Copy link
Contributor Author

ruflin commented Jan 17, 2023

What exactly is the bwc ci build? How can I run this one locally to figure out what is not working?

@ruflin
Copy link
Contributor Author

ruflin commented Jan 18, 2023

Update: Found the issue. The bot put two areas into the list but seems only 1 is allowed.

The docs-check currently fails with:

12:46:52 Execution failed for task ':validateChangelogs'.
12:46:52 > Verification failed. See the report at: file:/dev/shm/elastic+elasticsearch+pull-request+docs-check/build/reports/validateYaml.txt
12:46:52   Error validating YAML: 1 files contained 1 violations

But it is not clear to me why the changelog is invalid?

@ruflin
Copy link
Contributor Author

ruflin commented Jan 18, 2023

@dakrone Thanks for the review. I did a first round of changes and by now also CI is happy. Could you take another look?

Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

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

Okay, I left a few more minor comments, but this is pretty close.

+ name
+ "] specifies a missing component templates ["
+ missingComponentTemplate
+ "] that does not exist and is not part of 'ignore_missing_component_templates'"
Copy link
Member

Choose a reason for hiding this comment

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

If it is used with a non empty list but template is not found, we leave a not in the logs.

I'm not sure what you mean by this, if it has a non-empty list and the template is not found, we should throw an exception like this currently does (rather than logging anything).

ruflin and others added 3 commits January 30, 2023 10:12
…dices.put_index_template/15_composition.yml

Co-authored-by: Lee Hinman <dakrone@users.noreply.github.com>
…ableIndexTemplateTests.java

Co-authored-by: Lee Hinman <dakrone@users.noreply.github.com>
@@ -0,0 +1,7 @@
pr: 92436
summary: Add `ignore_missing_component_templates` config option
# The bot was creating `area: "Data streams, Indices APIs"` but this seems to be invalid
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dakrone I'll remove this line but maybe worth someone checks on why this is happening. It seems the bot can't handle 2 labels well (or the other way around).

Copy link
Member

Choose a reason for hiding this comment

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

That's because PRs only support a single green label, so the entry does not get duplicated in the changelog. This change would be indices APIs more than data streams (you don't have to change the labels, since you fixed this.)

@@ -505,17 +505,51 @@ public static void validateV2TemplateRequest(Metadata metadata, String name, Com
}

final Map<String, ComponentTemplate> componentTemplates = metadata.componentTemplates();
final List<String> ignoreMissingComponentTemplates = (
template.getIgnoreMissingComponentTemplates() == null? List.of():template.getIgnoreMissingComponentTemplates()
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 was going forth and back on this one. Either I check for null in getIgnoreMissingComponentTemplates and always return an empty list or do it here. It seems for non requirement params null is in many places and excepted value. Also it put a bit a challenge in many other places that expect the entry to not show up by default if it is entry. So I do the check here.

@dakrone
Copy link
Member

dakrone commented Jan 30, 2023

@elasticmachine run elasticsearch-ci/part-1

@ruflin

This comment was marked as outdated.

Copy link
Member

@dakrone dakrone left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for iterating on this @ruflin, I'll merge it in.

@dakrone dakrone merged commit 9f4d7fa into elastic:main Jan 31, 2023
@ruflin ruflin deleted the ignore-missing-component-template branch January 31, 2023 18:27
@ruflin
Copy link
Contributor Author

ruflin commented Jan 31, 2023

@dakrone Thanks for the reviews and feedback! Looking forward to my future contributions ;-)

mark-vieira pushed a commit to mark-vieira/elasticsearch that referenced this pull request Jan 31, 2023
This change introduces the configuration option `ignore_missing_component_templates` as discussed in elastic#92426 The implementation [option 6](elastic#92426 (comment)) was picked with a slight adjustment meaning no patterns are allowed.

## Implementation

During the creation of an index template, the list of component templates is checked if all component templates exist. This check is extended to skip any component templates which are listed under `ignore_missing_component_templates`. An index template that skips the check for the component template `logs-foo@custom` looks as following:


```
PUT _index_template/logs-foo
{
  "index_patterns": ["logs-foo-*"],
  "data_stream": { },
  "composed_of": ["logs-foo@package", "logs-foo@custom"],
  "ignore_missing_component_templates": ["logs-foo@custom"],
  "priority": 500
}
```

The component template `logs-foo@package` has to exist before creation. It can be created with:

```
PUT _component_template/logs-foo@custom
{
  "template": {
    "mappings": {
      "properties": {
        "host.ip": {
          "type": "ip"
        }
      }
    }
  }
}
```

## Testing

For manual testing, different scenarios can be tested. To simplify testing, the commands from `.http` file are added. Before each test run, a clean cluster is expected.

### New behaviour, missing component template

With the new config option, it must be possible to create an index template with a missing component templates without getting an error:

```
### Add logs-foo@package component template

PUT http://localhost:9200/
    _component_template/logs-foo@package
Authorization: Basic elastic password
Content-Type: application/json

{
  "template": {
    "mappings": {
      "properties": {
        "host.name": {
          "type": "keyword"
        }
      }
    }
  }
}

### Add logs-foo index template

PUT http://localhost:9200/
    _index_template/logs-foo
Authorization: Basic elastic password
Content-Type: application/json

{
  "index_patterns": ["logs-foo-*"],
  "data_stream": { },
  "composed_of": ["logs-foo@package", "logs-foo@custom"],
  "ignore_missing_component_templates": ["logs-foo@custom"],
  "priority": 500
}

### Create data stream

PUT http://localhost:9200/
    _data_stream/logs-foo-bar
Authorization: Basic elastic password
Content-Type: application/json

### Check if mappings exist

GET http://localhost:9200/
    logs-foo-bar
Authorization: Basic elastic password
Content-Type: application/json
```

It is checked if all templates could be created and data stream mappings are correct.

### Old behaviour, with all component templates

In the following, a component template is made optional but it already exists. It is checked, that it will show up in the mappings:

```
### Add logs-foo@package component template

PUT http://localhost:9200/
    _component_template/logs-foo@package
Authorization: Basic elastic password
Content-Type: application/json

{
  "template": {
    "mappings": {
      "properties": {
        "host.name": {
          "type": "keyword"
        }
      }
    }
  }
}

### Add logs-foo@custom component template

PUT http://localhost:9200/
    _component_template/logs-foo@custom
Authorization: Basic elastic password
Content-Type: application/json

{
  "template": {
    "mappings": {
      "properties": {
        "host.ip": {
          "type": "ip"
        }
      }
    }
  }
}

### Add logs-foo index template

PUT http://localhost:9200/
    _index_template/logs-foo
Authorization: Basic elastic password
Content-Type: application/json

{
  "index_patterns": ["logs-foo-*"],
  "data_stream": { },
  "composed_of": ["logs-foo@package", "logs-foo@custom"],
  "ignore_missing_component_templates": ["logs-foo@custom"],
  "priority": 500
}

### Create data stream

PUT http://localhost:9200/
    _data_stream/logs-foo-bar
Authorization: Basic elastic password
Content-Type: application/json

### Check if mappings exist

GET http://localhost:9200/
    logs-foo-bar
Authorization: Basic elastic password
Content-Type: application/json
```

### Check old behaviour

Ensure, that the old behaviour still exists when a component template is used that is not part of `ignore_missing_component_templates`: 

```
### Add logs-foo index template

PUT http://localhost:9200/
    _index_template/logs-foo
Authorization: Basic elastic password
Content-Type: application/json

{
  "index_patterns": ["logs-foo-*"],
  "data_stream": { },
  "composed_of": ["logs-foo@package", "logs-foo@custom"],
  "ignore_missing_component_templates": ["logs-foo@custom"],
  "priority": 500
}
```

Co-authored-by: Lee Hinman <dakrone@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/Data streams Data streams and their lifecycles :Data Management/Indices APIs APIs to create and manage indices and templates >enhancement external-contributor Pull request authored by a developer outside the Elasticsearch team Team:Data Management Meta label for data/management team v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants