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

[plugin/apm-data] Allow fallback of templates to template-resources #112614

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ composed_of:
- apm@settings
- apm-10d@lifecycle
- logs-apm@settings
- logs-apm.app-fallback@lifecycle
- logs@custom
- logs-apm.app@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ composed_of:
- apm-10d@lifecycle
- logs-apm@settings
- logs-apm.error@mappings
- logs-apm.error-fallback@lifecycle
- logs@custom
- logs-apm.error@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ composed_of:
- apm-90d@lifecycle
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.app-fallback@lifecycle
- metrics@custom
- metrics-apm.app@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ composed_of:
- apm-90d@lifecycle
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.internal-fallback@lifecycle
- metrics@custom
- metrics-apm.internal@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_destination@mappings
- metrics-apm.service_destination.10m-fallback@lifecycle
- metrics@custom
- metrics-apm.service_destination.10m@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_destination@mappings
- metrics-apm.service_destination.1m-fallback@lifecycle
- metrics@custom
- metrics-apm.service_destination.1m@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_destination@mappings
- metrics-apm.service_destination.60m-fallback@lifecycle
- metrics@custom
- metrics-apm.service_destination.60m@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_summary@mappings
- metrics-apm.service_summary.10m-fallback@lifecycle
- metrics@custom
- metrics-apm.service_summary.10m@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_summary@mappings
- metrics-apm.service_summary.1m-fallback@lifecycle
- metrics@custom
- metrics-apm.service_summary.1m@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_summary@mappings
- metrics-apm.service_summary.60m-fallback@lifecycle
- metrics@custom
- metrics-apm.service_summary.60m@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_transaction@mappings
- metrics-apm.service_transaction.10m-fallback@lifecycle
- metrics@custom
- metrics-apm.service_transaction.10m@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_transaction@mappings
- metrics-apm.service_transaction.1m-fallback@lifecycle
- metrics@custom
- metrics-apm.service_transaction.1m@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.service_transaction@mappings
- metrics-apm.service_transaction.60m-fallback@lifecycle
- metrics@custom
- metrics-apm.service_transaction.60m@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.transaction@mappings
- metrics-apm.transaction.10m-fallback@lifecycle
- metrics@custom
- metrics-apm.transaction.10m@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.transaction@mappings
- metrics-apm.transaction.1m-fallback@lifecycle
- metrics@custom
- metrics-apm.transaction.1m@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ composed_of:
- metrics-apm@mappings
- metrics-apm@settings
- metrics-apm.transaction@mappings
- metrics-apm.transaction.60m-fallback@lifecycle
- metrics@custom
- metrics-apm.transaction.60m@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ composed_of:
- apm-90d@lifecycle
- traces-apm@mappings
- traces-apm.rum@mappings
- traces-apm.rum-fallback@lifecycle
- traces@custom
- traces-apm.rum@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ composed_of:
- traces@mappings
- apm@mappings
- apm@settings
- traces-apm.sampled-fallback@lifecycle
- traces@custom
- traces-apm.sampled@custom
- ecs@mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ composed_of:
- apm@settings
- apm-10d@lifecycle
- traces-apm@mappings
- traces-apm-fallback@lifecycle
- traces@custom
- traces-apm@custom
- ecs@mappings
Expand Down
20 changes: 20 additions & 0 deletions x-pack/plugin/apm-data/src/main/resources/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ component-templates:
- metrics-apm.transaction@mappings
- traces-apm@mappings
- traces-apm.rum@mappings
# Fallback to ILM if DSL configurations are not present
- logs-apm.app-fallback@lifecycle
- logs-apm.error-fallback@lifecycle
- metrics-apm.app-fallback@lifecycle
- metrics-apm.internal-fallback@lifecycle
- metrics-apm.service_destination.10m-fallback@lifecycle
- metrics-apm.service_destination.1m-fallback@lifecycle
- metrics-apm.service_destination.60m-fallback@lifecycle
- metrics-apm.service_summary.10m-fallback@lifecycle
- metrics-apm.service_summary.1m-fallback@lifecycle
- metrics-apm.service_summary.60m-fallback@lifecycle
- metrics-apm.service_transaction.10m-fallback@lifecycle
- metrics-apm.service_transaction.1m-fallback@lifecycle
- metrics-apm.service_transaction.60m-fallback@lifecycle
- metrics-apm.transaction.10m-fallback@lifecycle
- metrics-apm.transaction.1m-fallback@lifecycle
- metrics-apm.transaction.60m-fallback@lifecycle
- traces-apm-fallback@lifecycle
- traces-apm.rum-fallback@lifecycle
- traces-apm.sampled-fallback@lifecycle

index-templates:
- logs-apm.app@template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

package org.elasticsearch.xpack.core.template;

import org.elasticsearch.xpack.core.template.resources.TemplateResources;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Map;

public class ResourceUtils {

static byte[] loadVersionedResourceUTF8(Class<?> clazz, String name, int version, String versionProperty) {
return loadVersionedResourceUTF8(clazz, name, version, versionProperty, Map.of());
}
Expand All @@ -25,16 +28,19 @@ static byte[] loadVersionedResourceUTF8(
Map<String, String> variables
) {
try {
String content = loadResource(clazz, name);
String content = loadResourceWithFallback(clazz, name);
content = TemplateUtils.replaceVariables(content, String.valueOf(version), versionProperty, variables);
return content.getBytes(StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static String loadResource(Class<?> clazz, String name) throws IOException {
static String loadResourceWithFallback(Class<?> clazz, String name) throws IOException {
InputStream is = clazz.getResourceAsStream(name);
if (is == null) {
is = TemplateResources.class.getResourceAsStream("/"+clazz.getPackageName()+name);
}
if (is == null) {
throw new IOException("Resource [" + name + "] not found in classpath.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.util.Optional;
import java.util.stream.Collectors;

import static org.elasticsearch.xpack.core.template.ResourceUtils.loadResource;
import static org.elasticsearch.xpack.core.template.ResourceUtils.loadResourceWithFallback;
import static org.elasticsearch.xpack.core.template.ResourceUtils.loadVersionedResourceUTF8;

/**
Expand Down Expand Up @@ -64,7 +64,7 @@ public YamlTemplateRegistry(
try {
final Map<String, Object> resources = XContentHelper.convertToMap(
YamlXContent.yamlXContent,
loadResource(this.getClass(), "/resources.yaml"),
loadResourceWithFallback(this.getClass(), "/resources.yaml"),
false
);
version = (((Number) resources.get("version")).intValue());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: ${xpack.apmdata.template.version}
_meta:
description: Fallback to ILM policy for logs-apm.app if DSL not defined
managed: true
template:
settings:
index:
lifecycle:
name: logs-apm.app_logs-default_policy
prefer_ilm: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: ${xpack.apmdata.template.version}
_meta:
description: Fallback to ILM policy for logs-apm.error if DSL not defined
managed: true
template:
settings:
index:
lifecycle:
name: logs-apm.error_logs-default_policy
prefer_ilm: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: ${xpack.apmdata.template.version}
_meta:
description: Fallback to ILM policy for metrics-apm.app if DSL not defined
managed: true
template:
settings:
index:
lifecycle:
name: metrics-apm.app_metrics-default_policy
prefer_ilm: false
11 changes: 11 additions & 0 deletions ...sticsearch.xpack.apmdata/component-templates/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: ${xpack.apmdata.template.version}
_meta:
description: Fallback to ILM policy for metrics-apm.internal if DSL not defined
managed: true
template:
settings:
index:
lifecycle:
name: metrics-apm.internal_metrics-default_policy
prefer_ilm: false
11 changes: 11 additions & 0 deletions ...k.apmdata/component-templates/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: ${xpack.apmdata.template.version}
_meta:
description: Fallback to ILM policy for metrics-apm.service_destination.10m if DSL not defined
managed: true
template:
settings:
index:
lifecycle:
name: metrics-apm.service_destination_10m_metrics-default_policy
prefer_ilm: false
11 changes: 11 additions & 0 deletions ...ck.apmdata/component-templates/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: ${xpack.apmdata.template.version}
_meta:
description: Fallback to ILM policy for metrics-apm.service_destination.1m if DSL not defined
managed: true
template:
settings:
index:
lifecycle:
name: metrics-apm.service_destination_1m_metrics-default_policy
prefer_ilm: false
11 changes: 11 additions & 0 deletions ...k.apmdata/component-templates/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: ${xpack.apmdata.template.version}
_meta:
description: Fallback to ILM policy for metrics-apm.service_destination.60m if DSL not defined
managed: true
template:
settings:
index:
lifecycle:
name: metrics-apm.service_destination_60m_metrics-default_policy
prefer_ilm: false
11 changes: 11 additions & 0 deletions ...xpack.apmdata/component-templates/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: ${xpack.apmdata.template.version}
_meta:
description: Fallback to ILM policy for metrics-apm.service_summary.10m if DSL not defined
managed: true
template:
settings:
index:
lifecycle:
name: metrics-apm.service_summary_10m_metrics-default_policy
prefer_ilm: false
11 changes: 11 additions & 0 deletions ....xpack.apmdata/component-templates/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: ${xpack.apmdata.template.version}
_meta:
description: Fallback to ILM policy for metrics-apm.service_summary.1m if DSL not defined
managed: true
template:
settings:
index:
lifecycle:
name: metrics-apm.service_summary_1m_metrics-default_policy
prefer_ilm: false
11 changes: 11 additions & 0 deletions ...xpack.apmdata/component-templates/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: ${xpack.apmdata.template.version}
_meta:
description: Fallback to ILM policy for metrics-apm.service_summary.60m if DSL not defined
managed: true
template:
settings:
index:
lifecycle:
name: metrics-apm.service_summary_60m_metrics-default_policy
prefer_ilm: false
11 changes: 11 additions & 0 deletions ...k.apmdata/component-templates/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: ${xpack.apmdata.template.version}
_meta:
description: Fallback to ILM policy for metrics-apm.service_transaction.10m if DSL not defined
managed: true
template:
settings:
index:
lifecycle:
name: metrics-apm.service_transaction_10m_metrics-default_policy
prefer_ilm: false
11 changes: 11 additions & 0 deletions ...ck.apmdata/component-templates/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: ${xpack.apmdata.template.version}
_meta:
description: Fallback to ILM policy for metrics-apm.service_transaction.1m if DSL not defined
managed: true
template:
settings:
index:
lifecycle:
name: metrics-apm.service_transaction_1m_metrics-default_policy
prefer_ilm: false
11 changes: 11 additions & 0 deletions ...k.apmdata/component-templates/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: ${xpack.apmdata.template.version}
_meta:
description: Fallback to ILM policy for metrics-apm.service_transaction.60m if DSL not defined
managed: true
template:
settings:
index:
lifecycle:
name: metrics-apm.service_transaction_60m_metrics-default_policy
prefer_ilm: false
Loading