Skip to content

Commit

Permalink
apm-data: fix @custom component templates
Browse files Browse the repository at this point in the history
Use `<data_stream.type>@custom` instead of `apm@custom`.
This is an enhancement over what Fleet sets up; it is
an additive improvement in the direction of
elastic#97664.

The rollup data streams' `@custom` component templates
now include the duration, like what Fleet sets up.

Add a YAML REST test, and a unit test ensuring consistency
across the index templates.
  • Loading branch information
axw committed Jan 10, 2024
1 parent f693d38 commit 8c8b0b9
Show file tree
Hide file tree
Showing 21 changed files with 184 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ composed_of:
- apm@mappings
- apm@settings
- apm-10d@lifecycle
- apm@custom
- logs@custom
- logs-apm.app@custom
- ecs@mappings
ignore_missing_component_templates:
- logs@custom
- logs-apm.app@custom
- apm@custom
template:
settings:
index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ composed_of:
- apm@settings
- apm-10d@lifecycle
- logs-apm.error@mappings
- apm@custom
- logs@custom
- logs-apm.error@custom
- ecs@mappings
ignore_missing_component_templates:
- logs@custom
- logs-apm.error@custom
- apm@custom
template:
mappings:
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ composed_of:
- apm-90d@lifecycle
- metrics-apm@mappings
- metrics-apm@settings
- apm@custom
- metrics@custom
- metrics-apm.app@custom
- ecs@mappings
ignore_missing_component_templates:
- apm@custom
- metrics@custom
- metrics-apm.app@custom
template:
settings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ composed_of:
- apm-90d@lifecycle
- metrics-apm@mappings
- metrics-apm@settings
- apm@custom
- metrics@custom
- metrics-apm.internal@custom
- ecs@mappings
ignore_missing_component_templates:
- apm@custom
- metrics@custom
- metrics-apm.internal@custom
template:
settings:
Expand Down
8 changes: 4 additions & 4 deletions ...data/src/main/resources/index-templates/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_destination@mappings
- apm@custom
- metrics-apm.service_destination@custom
- metrics@custom
- metrics-apm.service_destination.10m@custom
- ecs@mappings
ignore_missing_component_templates:
- apm@custom
- metrics-apm.service_destination@custom
- metrics@custom
- metrics-apm.service_destination.10m@custom
template:
settings:
index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_destination@mappings
- apm@custom
- metrics-apm.service_destination@custom
- metrics@custom
- metrics-apm.service_destination.1m@custom
- ecs@mappings
ignore_missing_component_templates:
- apm@custom
- metrics-apm.service_destination@custom
- metrics@custom
- metrics-apm.service_destination.1m@custom
template:
settings:
index:
Expand Down
8 changes: 4 additions & 4 deletions ...data/src/main/resources/index-templates/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_destination@mappings
- apm@custom
- metrics-apm.service_destination@custom
- metrics@custom
- metrics-apm.service_destination.60m@custom
- ecs@mappings
ignore_missing_component_templates:
- apm@custom
- metrics-apm.service_destination@custom
- metrics@custom
- metrics-apm.service_destination.60m@custom
template:
settings:
index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_summary@mappings
- apm@custom
- metrics-apm.service_summary@custom
- metrics@custom
- metrics-apm.service_summary.10m@custom
- ecs@mappings
ignore_missing_component_templates:
- apm@custom
- metrics-apm.service_summary@custom
- metrics@custom
- metrics-apm.service_summary.10m@custom
template:
settings:
index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_summary@mappings
- apm@custom
- metrics-apm.service_summary@custom
- metrics@custom
- metrics-apm.service_summary.1m@custom
- ecs@mappings
ignore_missing_component_templates:
- apm@custom
- metrics-apm.service_summary@custom
- metrics@custom
- metrics-apm.service_summary.1m@custom
template:
settings:
index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_summary@mappings
- apm@custom
- metrics-apm.service_summary@custom
- metrics@custom
- metrics-apm.service_summary.60m@custom
- ecs@mappings
ignore_missing_component_templates:
- apm@custom
- metrics-apm.service_summary@custom
- metrics@custom
- metrics-apm.service_summary.60m@custom
template:
settings:
index:
Expand Down
8 changes: 4 additions & 4 deletions ...data/src/main/resources/index-templates/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_transaction@mappings
- apm@custom
- metrics-apm.service_transaction@custom
- metrics@custom
- metrics-apm.service_transaction.10m@custom
- ecs@mappings
ignore_missing_component_templates:
- apm@custom
- metrics-apm.service_transaction@custom
- metrics@custom
- metrics-apm.service_transaction.10m@custom
template:
settings:
index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_transaction@mappings
- apm@custom
- metrics-apm.service_transaction@custom
- metrics@custom
- metrics-apm.service_transaction.1m@custom
- ecs@mappings
ignore_missing_component_templates:
- apm@custom
- metrics-apm.service_transaction@custom
- metrics@custom
- metrics-apm.service_transaction.1m@custom
template:
settings:
index:
Expand Down
8 changes: 4 additions & 4 deletions ...data/src/main/resources/index-templates/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_transaction@mappings
- apm@custom
- metrics-apm.service_transaction@custom
- metrics@custom
- metrics-apm.service_transaction.60m@custom
- ecs@mappings
ignore_missing_component_templates:
- apm@custom
- metrics-apm.service_transaction@custom
- metrics@custom
- metrics-apm.service_transaction.60m@custom
template:
settings:
index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.transaction@mappings
- apm@custom
- metrics-apm.transaction@custom
- metrics@custom
- metrics-apm.transaction.10m@custom
- ecs@mappings
ignore_missing_component_templates:
- apm@custom
- metrics-apm.transaction@custom
- metrics@custom
- metrics-apm.transaction.10m@custom
template:
settings:
index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.transaction@mappings
- apm@custom
- metrics-apm.transaction@custom
- metrics@custom
- metrics-apm.transaction.1m@custom
- ecs@mappings
ignore_missing_component_templates:
- apm@custom
- metrics-apm.transaction@custom
- metrics@custom
- metrics-apm.transaction.1m@custom
template:
settings:
index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.transaction@mappings
- apm@custom
- metrics-apm.transaction@custom
- metrics@custom
- metrics-apm.transaction.60m@custom
- ecs@mappings
ignore_missing_component_templates:
- apm@custom
- metrics-apm.transaction@custom
- metrics@custom
- metrics-apm.transaction.60m@custom
template:
settings:
index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ composed_of:
- apm-90d@lifecycle
- traces-apm@mappings
- traces-apm.rum@mappings
- apm@custom
- traces-apm@custom
- traces@custom
- traces-apm.rum@custom
- ecs@mappings
ignore_missing_component_templates:
- traces@custom
- traces-apm.rum@custom
- traces-apm@custom
- apm@custom
template:
settings:
index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ composed_of:
- traces@mappings
- apm@mappings
- apm@settings
- apm@custom
- traces@custom
- traces-apm.sampled@custom
- ecs@mappings
ignore_missing_component_templates:
- apm@custom
- traces@custom
- traces-apm.sampled@custom
template:
lifecycle:
data_retention: 1h
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ composed_of:
- apm@settings
- apm-10d@lifecycle
- traces-apm@mappings
- apm@custom
- traces@custom
- traces-apm@custom
- ecs@mappings
ignore_missing_component_templates:
- traces@custom
- traces-apm@custom
- apm@custom
template:
settings:
index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@
import java.util.stream.Collectors;

import static org.elasticsearch.xpack.core.XPackSettings.APM_DATA_ENABLED;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isIn;
import static org.hamcrest.Matchers.not;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
Expand Down Expand Up @@ -249,6 +251,48 @@ public void testIndexTemplates() throws Exception {
assertThat(actualInstalledIngestPipelines.get(), equalTo(0));
}

public void testIndexTemplateConventions() throws Exception {
for (Map.Entry<String, ComposableIndexTemplate> entry : apmIndexTemplateRegistry.getComposableTemplateConfigs().entrySet()) {
final String name = entry.getKey();
final int atIndex = name.lastIndexOf('@');
assertThat(atIndex, not(equalTo(-1)));
assertThat(name.substring(atIndex + 1), equalTo("template"));

final String dataStreamType = name.substring(0, name.indexOf('-'));
assertThat(dataStreamType, isIn(List.of("logs", "metrics", "traces")));

final ComposableIndexTemplate template = entry.getValue();
assertThat(template.indexPatterns().size(), equalTo(1));

final String namePrefix = name.substring(0, atIndex);
switch (namePrefix) {
case "logs-apm.app", "metrics-apm.app":
// These two data streams have a service-specific dataset.
assertThat(template.indexPatterns().get(0), equalTo(namePrefix + ".*-*"));
break;
default:
assertThat(template.indexPatterns().get(0), equalTo(namePrefix + "-*"));
break;
}

// Each index template should be composed of the following optional component templates:
// <data_stream.type>@custom
// <data_stream.type>-<data_stream.dataset>@custom
final List<String> optionalComponentTemplates = template.composedOf()
.stream()
.filter(t -> template.getIgnoreMissingComponentTemplates().contains(t))
.toList();
assertThat(optionalComponentTemplates, containsInAnyOrder(namePrefix + "@custom", dataStreamType + "@custom"));

// There should be no required custom component templates.
final List<String> requiredCustomComponentTemplates = template.getRequiredComponentTemplates()
.stream()
.filter(t -> t.endsWith("@custom"))
.toList();
assertThat(requiredCustomComponentTemplates, empty());
}
}

private Map<String, ComponentTemplate> getIndependentComponentTemplateConfigs() {
return apmIndexTemplateRegistry.getComponentTemplateConfigs().entrySet().stream().filter(template -> {
Settings settings = template.getValue().template().settings();
Expand Down
Loading

0 comments on commit 8c8b0b9

Please sign in to comment.