-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
x-pack/plugin/apm: introduce x-pack-apm plugin #97546
Merged
Merged
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
2aebfcc
x-pack/plugin/apm: introduce x-pack-apm plugin
axw cc750ad
Dependency fix and tests
eyalkoren 30d1541
Merge remote-tracking branch 'upstream/main' into apm-data-streams
eyalkoren 2c5bb0b
Restore addition to ESRestTestCase
eyalkoren 1c4aa5c
Replace IngestPipelineConfig instantiation
eyalkoren 103f39d
Update DataStreamUpgradeRestIT to expect logs-apm.error
eyalkoren 2775f2b
Adding rollover functionality
eyalkoren 72e44d9
Extend basic rollover funtionality tests
eyalkoren 36b7eae
Start adding integration test
eyalkoren 338ed88
Hide rollup data streams
axw d766a2b
Apm ingest fixes
axw 5b10dd4
Fix error.grouping_name script
axw 3322b05
Only set event.ingested for traces-apm.sampled
axw 7a7589c
Enabling APMRolloverIT
eyalkoren dca89e5
Merge remote-tracking branch 'axw/apm-data-streams' into apm-data-str…
eyalkoren eae5849
Spotless...
eyalkoren f6ec867
Assertion change
eyalkoren bac147f
Wait a bit before assertBusy
eyalkoren db19f78
Adjust template and pipeline names to convention
axw d0172bb
Merge remote-tracking branch 'upstream/main' into apm-data-streams
eyalkoren 7c80c37
No need for manual cluster change events anymore
eyalkoren 46313c1
Fix test
eyalkoren 7744a3c
Merge remote-tracking branch 'upstream/main' into apm-data-streams
eyalkoren bf6444a
Lower template priority to 110
axw c926324
Add logging
eyalkoren 93d425b
Remove explicit timeout for rollovers
eyalkoren 437587e
Merge remote-tracking branch 'axw/apm-data-streams' into apm-data-str…
eyalkoren e26e06b
Add _meta to component templates too
axw 1b750e9
Increase template priorities to 140
axw 89fb221
Test multiple index template upgrades with rollovers
eyalkoren 665dc9d
Enfore correct component template versions
eyalkoren 22404af
Merge remote-tracking branch 'axw/apm-data-streams' into apm-data-str…
eyalkoren 683d223
Rename to x-pack-apm-data, default to disabled
axw 1385ae4
Fix checkstyle
axw b2f4424
Fix more checkstyle
axw e6ced72
Fix even more linting issues
axw e761177
Adjust test to disabled by default
eyalkoren 3366b23
remove todo
eyalkoren 70bf9bf
Fixing test
eyalkoren 8cc4160
Refactor leftovers
eyalkoren 41f2a3a
Merge remote-tracking branch 'upstream/main' into apm-data-streams
eyalkoren 808af05
Fix constant keyword mapping conflict
eyalkoren 873baa0
Merge remote-tracking branch 'upstream/main' into HEAD
eyalkoren 7051040
Fix after merge
eyalkoren 82d8728
Comment fixes
eyalkoren 828f68b
Rename ApmIngestPipelineConfig to YamlIngestPipelineConfig
eyalkoren 83a60d7
Always return a registry
eyalkoren fc045e7
spotless, what else
eyalkoren 75a9a83
Add rollover integration test to core
eyalkoren cbc678b
Remove APMRolloverIT
eyalkoren d832ac6
Merge remote-tracking branch 'upstream/main' into apm-data-streams
eyalkoren 44f860e
Merge remote-tracking branch 'upstream/main' into apm-data-streams
eyalkoren f878fc5
Refactor in renamed components
eyalkoren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## APM plugin | ||
|
||
The APM plugin installs index templates, component templates, and ingest pipelines for Elastic APM. | ||
|
||
All resources are defined as YAML under [src/main/resources](src/main/resources). | ||
|
||
The APM index templates rely on mappings from `x-pack-core`. | ||
See [x-pack/plugin/core/src/main/resources](../core/src/main/resources). | ||
|
||
## Testing | ||
|
||
## Unit testing | ||
|
||
Java unit tests cover basic, low-level details of the plugin, such as the parsing and loading of resources. | ||
These can be run with: | ||
|
||
``` | ||
./gradlew x-pack:plugin:apm:test | ||
``` | ||
|
||
## Integration testing | ||
|
||
The index templates and ingest pipeline functionality is tested using YAML REST tests. | ||
These can be run with: | ||
|
||
``` | ||
./gradlew x-pack:plugin:apm:yamlRestTest | ||
``` | ||
|
||
Refer to the [rest-api-spec documentation](../../../rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/README.asciidoc) | ||
for information about writing YAML REST tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
apply plugin: 'elasticsearch.internal-es-plugin' | ||
apply plugin: 'elasticsearch.internal-yaml-rest-test' | ||
|
||
esplugin { | ||
name 'x-pack-apm' | ||
description 'The APM plugin defines APM data streams and ingest pipelines.' | ||
classname 'org.elasticsearch.xpack.apm.APMPlugin' | ||
extendedPlugins = ['x-pack-core'] | ||
} | ||
|
||
dependencies { | ||
compileOnly project(path: xpackModule('core')) | ||
testImplementation(testArtifact(project(xpackModule('core')))) | ||
clusterModules project(':modules:data-streams') | ||
clusterModules project(':modules:ingest-common') | ||
clusterModules project(':modules:ingest-geoip') | ||
clusterModules project(':modules:ingest-user-agent') | ||
clusterModules project(':modules:mapper-extras') | ||
clusterModules project(xpackModule('analytics')) | ||
clusterModules project(xpackModule('ilm')) | ||
clusterModules project(xpackModule('mapper-aggregate-metric')) | ||
clusterModules project(xpackModule('mapper-constant-keyword')) | ||
clusterModules project(xpackModule('stack')) | ||
clusterModules project(xpackModule('wildcard')) | ||
} |
168 changes: 168 additions & 0 deletions
168
x-pack/plugin/apm/src/main/java/org/elasticsearch/xpack/apm/APMIndexTemplateRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.apm; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.action.ingest.PutPipelineRequest; | ||
import org.elasticsearch.client.internal.Client; | ||
import org.elasticsearch.cluster.metadata.ComponentTemplate; | ||
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.bytes.BytesArray; | ||
import org.elasticsearch.common.io.Streams; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.xcontent.XContentHelper; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.xcontent.XContentParserConfiguration; | ||
import org.elasticsearch.xcontent.XContentType; | ||
import org.elasticsearch.xcontent.yaml.YamlXContent; | ||
import org.elasticsearch.xpack.core.ClientHelper; | ||
import org.elasticsearch.xpack.core.template.IndexTemplateRegistry; | ||
import org.elasticsearch.xpack.core.template.IngestPipelineConfig; | ||
import org.elasticsearch.xpack.core.template.TemplateUtils; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Creates all index templates and ingest pipelines that are required for using Elastic APM. | ||
*/ | ||
public class APMIndexTemplateRegistry extends IndexTemplateRegistry { | ||
private static final Logger logger = LogManager.getLogger(APMIndexTemplateRegistry.class); | ||
|
||
// TODO(axw) when the template version is updated, data streams using the old | ||
// version should be rolled over after upgrading. Ideally this would be done | ||
// automatically: https://github.com/elastic/elasticsearch/issues/96521 | ||
|
||
public static final String APM_TEMPLATE_VERSION_VARIABLE = "xpack.apm.template.version"; | ||
|
||
private final Map<String, ComponentTemplate> componentTemplates; | ||
private final Map<String, ComposableIndexTemplate> composableIndexTemplates; | ||
private final List<IngestPipelineConfig> ingestPipelines; | ||
|
||
@SuppressWarnings("unchecked") | ||
public APMIndexTemplateRegistry( | ||
Settings nodeSettings, | ||
ClusterService clusterService, | ||
ThreadPool threadPool, | ||
Client client, | ||
NamedXContentRegistry xContentRegistry | ||
) { | ||
super(nodeSettings, clusterService, threadPool, client, xContentRegistry); | ||
|
||
try { | ||
final Map<String, Object> apmResources = XContentHelper.convertToMap( | ||
YamlXContent.yamlXContent, | ||
loadResource("/resources.yaml"), | ||
false | ||
); | ||
final int version = ((Number) apmResources.get("version")).intValue(); | ||
final List<Object> componentTemplateNames = (List<Object>) apmResources.get("component-templates"); | ||
final List<Object> indexTemplateNames = (List<Object>) apmResources.get("index-templates"); | ||
final List<Object> ingestPipelineNames = (List<Object>) apmResources.get("ingest-pipelines"); | ||
|
||
componentTemplates = componentTemplateNames.stream() | ||
.map(o -> (String) o) | ||
.collect(Collectors.toMap(name -> name, name -> loadComponentTemplate(name, version))); | ||
composableIndexTemplates = indexTemplateNames.stream() | ||
.map(o -> (String) o) | ||
.collect(Collectors.toMap(name -> name, name -> loadIndexTemplate(name, version))); | ||
ingestPipelines = ingestPipelineNames.stream() | ||
.map(o -> (String) o) | ||
.map(name -> loadIngestPipeline(name, version)) | ||
.collect(Collectors.toList()); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public void close() { | ||
clusterService.removeListener(this); | ||
} | ||
|
||
@Override | ||
protected String getOrigin() { | ||
return ClientHelper.APM_ORIGIN; | ||
} | ||
|
||
@Override | ||
protected boolean requiresMasterNode() { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected Map<String, ComponentTemplate> getComponentTemplateConfigs() { | ||
return componentTemplates; | ||
} | ||
|
||
@Override | ||
protected Map<String, ComposableIndexTemplate> getComposableTemplateConfigs() { | ||
return composableIndexTemplates; | ||
} | ||
|
||
@Override | ||
protected List<IngestPipelineConfig> getIngestPipelines() { | ||
return ingestPipelines; | ||
} | ||
|
||
private static ComponentTemplate loadComponentTemplate(String name, int version) { | ||
try { | ||
final byte[] content = loadVersionedResourceUTF8("/component-templates/" + name + ".yaml", version); | ||
return ComponentTemplate.parse(YamlXContent.yamlXContent.createParser(XContentParserConfiguration.EMPTY, content)); | ||
} catch (Exception e) { | ||
throw new RuntimeException("failed to load APM component template: " + name, e); | ||
} | ||
} | ||
|
||
private static ComposableIndexTemplate loadIndexTemplate(String name, int version) { | ||
try { | ||
final byte[] content = loadVersionedResourceUTF8("/index-templates/" + name + ".yaml", version); | ||
return ComposableIndexTemplate.parse(YamlXContent.yamlXContent.createParser(XContentParserConfiguration.EMPTY, content)); | ||
} catch (Exception e) { | ||
throw new RuntimeException("failed to load APM index template: " + name, e); | ||
} | ||
} | ||
|
||
private static IngestPipelineConfig loadIngestPipeline(String name, int version) { | ||
return new IngestPipelineConfig( | ||
name, | ||
version, | ||
Collections.emptyList(), | ||
() -> new PutPipelineRequest( | ||
name, | ||
new BytesArray(loadVersionedResourceUTF8("/ingest-pipelines/" + name + ".yaml", version)), | ||
XContentType.YAML | ||
) | ||
); | ||
} | ||
|
||
private static byte[] loadVersionedResourceUTF8(String name, int version) { | ||
try { | ||
String content = loadResource(name); | ||
content = TemplateUtils.replaceVariable(content, APM_TEMPLATE_VERSION_VARIABLE, String.valueOf(version)); | ||
return content.getBytes(StandardCharsets.UTF_8); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static String loadResource(String name) throws IOException { | ||
InputStream is = APMIndexTemplateRegistry.class.getResourceAsStream(name); | ||
if (is == null) { | ||
throw new IOException("Resource [" + name + "] not found in classpath."); | ||
} | ||
return Streams.readFully(is).utf8ToString(); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
x-pack/plugin/apm/src/main/java/org/elasticsearch/xpack/apm/APMPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.apm; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.lucene.util.SetOnce; | ||
import org.elasticsearch.client.internal.Client; | ||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.cluster.routing.allocation.AllocationService; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.env.Environment; | ||
import org.elasticsearch.env.NodeEnvironment; | ||
import org.elasticsearch.indices.IndicesService; | ||
import org.elasticsearch.plugins.ActionPlugin; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.repositories.RepositoriesService; | ||
import org.elasticsearch.script.ScriptService; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.tracing.Tracer; | ||
import org.elasticsearch.watcher.ResourceWatcherService; | ||
import org.elasticsearch.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.xpack.core.XPackSettings; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
public class APMPlugin extends Plugin implements ActionPlugin { | ||
private static final Logger logger = LogManager.getLogger(APMPlugin.class); | ||
private final Settings settings; | ||
private final boolean enabled; | ||
|
||
private final SetOnce<APMIndexTemplateRegistry> registry = new SetOnce<>(); | ||
|
||
public APMPlugin(Settings settings) { | ||
this.settings = settings; | ||
this.enabled = XPackSettings.PROFILING_ENABLED.get(settings); | ||
} | ||
|
||
@Override | ||
public Collection<Object> createComponents( | ||
Client client, | ||
ClusterService clusterService, | ||
ThreadPool threadPool, | ||
ResourceWatcherService resourceWatcherService, | ||
ScriptService scriptService, | ||
NamedXContentRegistry xContentRegistry, | ||
Environment environment, | ||
NodeEnvironment nodeEnvironment, | ||
NamedWriteableRegistry namedWriteableRegistry, | ||
IndexNameExpressionResolver indexNameExpressionResolver, | ||
Supplier<RepositoriesService> repositoriesServiceSupplier, | ||
Tracer tracer, | ||
AllocationService allocationService, | ||
IndicesService indicesService | ||
) { | ||
logger.info("APM is {}", enabled ? "enabled" : "disabled"); | ||
registry.set(new APMIndexTemplateRegistry(settings, clusterService, threadPool, client, xContentRegistry)); | ||
if (enabled) { | ||
registry.get().initialize(); | ||
return List.of(registry.get()); | ||
} else { | ||
return Collections.emptyList(); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
registry.get().close(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
x-pack/plugin/apm/src/main/resources/component-templates/apm-retention-10d.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
version: ${xpack.apm.template.version} | ||
template: | ||
lifecycle: | ||
data_retention: "10d" |
5 changes: 5 additions & 0 deletions
5
x-pack/plugin/apm/src/main/resources/component-templates/apm-retention-180d.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
version: ${xpack.apm.template.version} | ||
template: | ||
lifecycle: | ||
data_retention: "180d" |
5 changes: 5 additions & 0 deletions
5
x-pack/plugin/apm/src/main/resources/component-templates/apm-retention-390d.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
version: ${xpack.apm.template.version} | ||
template: | ||
lifecycle: | ||
data_retention: "390d" |
5 changes: 5 additions & 0 deletions
5
x-pack/plugin/apm/src/main/resources/component-templates/apm-retention-90d.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
version: ${xpack.apm.template.version} | ||
template: | ||
lifecycle: | ||
data_retention: "90d" |
23 changes: 23 additions & 0 deletions
23
x-pack/plugin/apm/src/main/resources/component-templates/apm.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
version: ${xpack.apm.template.version} | ||
template: | ||
settings: | ||
index: | ||
default_pipeline: apm | ||
sort: | ||
field: "@timestamp" | ||
order: desc | ||
mappings: | ||
dynamic: true | ||
dynamic_templates: | ||
- numeric_labels: | ||
path_match: numeric_labels.* | ||
mapping: | ||
type: scaled_float | ||
scaling_factor: 1000000 | ||
properties: | ||
data_stream.type: | ||
type: constant_keyword | ||
data_stream.dataset: | ||
type: constant_keyword | ||
data_stream.namespace: | ||
type: constant_keyword |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for reviewers
IMO this is a must have, so the apm-server team can make changes to templates and ingest pipelines, and review within the team without any cross-team coordination overhead.