Skip to content

Commit 4e1a84c

Browse files
gregkalaposfelixbarnycarsoniplahsivjaraxw
authored
x-pack/plugin/otel: introduce x-pack-otel plugin (elastic#111091)
* Add YamlTemplateRegistry and OtelIndexTemplateRegistry with resource YAML files * Fix traces-otel template * Adding first yml tests * Base APMIndexTemplateRegistry on YamlTemplateRegistry * Update OTelPlugin.java * Update APMIndexTemplateRegistry.java * Update YamlIngestPipelineConfig.java * Adding traces tests * Update x-pack/plugin/otel-data/src/main/resources/component-templates/[email protected] Co-authored-by: Felix Barnsteiner <[email protected]> * Add mapper-version * Fix code-style * Rename `status.status_code` to `status.code` * Update [email protected] Revert back to date due to missing support in ES|QL for date_nanos * Move dynamic_templates to metrics@mappings in core * Run gradlew :x-pack:plugin:core:spotlessApply * Update x-pack/plugin/otel-data/src/main/resources/component-templates/[email protected] Co-authored-by: Carson Ip <[email protected]> * Update 20_metic_tests.yml Workaround for TSDB timestamp issue: we push a custom template with higher priority and set time_series.start_time. * Update CODEOWNERS Adding obs-ds-intake-services as owner of the new otel-data plugin. Since we had some changes, also updating the owner of apm-data to the same team. * Change dynamic: strict to false * Skip "Reject invalid top level field" test * Update 20_metic_tests.yml * Add boolean as dimension test (skipping it for now) * Add booleans_to_keywords and enable corresponding test * Remove processor.event top level mapping Reason: for metrics and logs we can rely on the name of the datastream. For spans vs. transactions there are other fields we can use. * Remove booleans_to_keywords Because booleans are supported now as dimension on TSDB * Add alias service.language.name -> telemetry.sdk.language * cleanup * Update README.md * Update README.md * Update docs/changelog/111091.yaml * Move traces@settings and traces@mappings to core * Update [email protected] * Review feedback * Adapt `match` style in tests * Update docs/changelog/111091.yaml * Apply suggestions from code review Co-authored-by: Vishal Raj <[email protected]> * Update x-pack/plugin/otel-data/src/main/resources/component-templates/[email protected] Co-authored-by: Carson Ip <[email protected]> * Changing trace_flags to long Related discussion: elastic#111091 (comment) * Remove trace_flags see: elastic/opentelemetry-dev#368 (review) * Apply suggestions from code review Co-authored-by: Andrew Wilkins <[email protected]> * Review feedback * Add store_array_source for span links * Define constant `data_stream.type` in `template.yaml`s * Create package-info.java * Move ecs-tsdb@mappings to index template Add test to verify that @Custom template can add dynamic templates with a higher precedence * Update [email protected] Remove summary_gauge and summary_counter since they are covered by summary_metrics * Move clusterService.getClusterSettings().addSettingsUpdateConsumer to registry * Fix code-style * Update x-pack/plugin/otel-data/src/yamlRestTest/resources/rest-api-spec/test/20_logs.tests.yml Co-authored-by: Felix Barnsteiner <[email protected]> * Enable logsdb * Update [email protected] No lifecycle needed for OTel at this point --------- Co-authored-by: Felix Barnsteiner <[email protected]> Co-authored-by: Carson Ip <[email protected]> Co-authored-by: Vishal Raj <[email protected]> Co-authored-by: Andrew Wilkins <[email protected]> Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Felix Barnsteiner <[email protected]>
1 parent 1222496 commit 4e1a84c

File tree

39 files changed

+1480
-219
lines changed

39 files changed

+1480
-219
lines changed

.github/CODEOWNERS

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ libs/logstash-bridge @elastic/logstash
2727
x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/store/KibanaOwnedReservedRoleDescriptors.java @elastic/kibana-security
2828

2929
# APM Data index templates, etc.
30-
x-pack/plugin/apm-data/src/main/resources @elastic/apm-server
31-
x-pack/plugin/apm-data/src/yamlRestTest/resources @elastic/apm-server
30+
x-pack/plugin/apm-data/src/main/resources @elastic/obs-ds-intake-services
31+
x-pack/plugin/apm-data/src/yamlRestTest/resources @elastic/obs-ds-intake-services
32+
33+
# OTel
34+
x-pack/plugin/otel-data/src/main/resources @elastic/obs-ds-intake-services
35+
x-pack/plugin/otel-data/src/yamlRestTest/resources @elastic/obs-ds-intake-services
3236

3337
# Delivery
3438
gradle @elastic/es-delivery

docs/changelog/111091.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 111091
2+
summary: "X-pack/plugin/otel: introduce x-pack-otel plugin"
3+
area: Data streams
4+
type: feature
5+
issues: []

x-pack/plugin/apm-data/src/main/java/org/elasticsearch/xpack/apmdata/APMIndexTemplateRegistry.java

Lines changed: 15 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -7,53 +7,24 @@
77

88
package org.elasticsearch.xpack.apmdata;
99

10-
import org.apache.logging.log4j.LogManager;
11-
import org.apache.logging.log4j.Logger;
1210
import org.elasticsearch.client.internal.Client;
13-
import org.elasticsearch.cluster.ClusterChangedEvent;
14-
import org.elasticsearch.cluster.metadata.ComponentTemplate;
15-
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
1611
import org.elasticsearch.cluster.service.ClusterService;
1712
import org.elasticsearch.common.settings.Settings;
18-
import org.elasticsearch.common.xcontent.XContentHelper;
19-
import org.elasticsearch.core.Nullable;
2013
import org.elasticsearch.features.FeatureService;
21-
import org.elasticsearch.features.NodeFeature;
2214
import org.elasticsearch.threadpool.ThreadPool;
2315
import org.elasticsearch.xcontent.NamedXContentRegistry;
24-
import org.elasticsearch.xcontent.XContentParserConfiguration;
25-
import org.elasticsearch.xcontent.yaml.YamlXContent;
2616
import org.elasticsearch.xpack.core.ClientHelper;
27-
import org.elasticsearch.xpack.core.template.IndexTemplateRegistry;
28-
import org.elasticsearch.xpack.core.template.IngestPipelineConfig;
17+
import org.elasticsearch.xpack.core.template.YamlTemplateRegistry;
2918

30-
import java.io.IOException;
31-
import java.util.Collections;
32-
import java.util.List;
33-
import java.util.Map;
34-
import java.util.stream.Collectors;
35-
36-
import static org.elasticsearch.xpack.apmdata.ResourceUtils.APM_TEMPLATE_VERSION_VARIABLE;
37-
import static org.elasticsearch.xpack.apmdata.ResourceUtils.loadResource;
38-
import static org.elasticsearch.xpack.apmdata.ResourceUtils.loadVersionedResourceUTF8;
19+
import static org.elasticsearch.xpack.apmdata.APMPlugin.APM_DATA_REGISTRY_ENABLED;
3920

4021
/**
4122
* Creates all index templates and ingest pipelines that are required for using Elastic APM.
4223
*/
43-
public class APMIndexTemplateRegistry extends IndexTemplateRegistry {
44-
private static final Logger logger = LogManager.getLogger(APMIndexTemplateRegistry.class);
45-
// this node feature is a redefinition of {@link DataStreamFeatures#DATA_STREAM_LIFECYCLE} and it's meant to avoid adding a
46-
// dependency to the data-streams module just for this
47-
public static final NodeFeature DATA_STREAM_LIFECYCLE = new NodeFeature("data_stream.lifecycle");
48-
private final int version;
24+
public class APMIndexTemplateRegistry extends YamlTemplateRegistry {
4925

50-
private final Map<String, ComponentTemplate> componentTemplates;
51-
private final Map<String, ComposableIndexTemplate> composableIndexTemplates;
52-
private final List<IngestPipelineConfig> ingestPipelines;
53-
private final FeatureService featureService;
54-
private volatile boolean enabled;
26+
public static final String APM_TEMPLATE_VERSION_VARIABLE = "xpack.apmdata.template.version";
5527

56-
@SuppressWarnings("unchecked")
5728
public APMIndexTemplateRegistry(
5829
Settings nodeSettings,
5930
ClusterService clusterService,
@@ -62,133 +33,29 @@ public APMIndexTemplateRegistry(
6233
NamedXContentRegistry xContentRegistry,
6334
FeatureService featureService
6435
) {
65-
super(nodeSettings, clusterService, threadPool, client, xContentRegistry);
66-
67-
try {
68-
final Map<String, Object> apmResources = XContentHelper.convertToMap(
69-
YamlXContent.yamlXContent,
70-
loadResource("/resources.yaml"),
71-
false
72-
);
73-
version = (((Number) apmResources.get("version")).intValue());
74-
final List<Object> componentTemplateNames = (List<Object>) apmResources.get("component-templates");
75-
final List<Object> indexTemplateNames = (List<Object>) apmResources.get("index-templates");
76-
final List<Object> ingestPipelineConfigs = (List<Object>) apmResources.get("ingest-pipelines");
77-
78-
componentTemplates = componentTemplateNames.stream()
79-
.map(o -> (String) o)
80-
.collect(Collectors.toMap(name -> name, name -> loadComponentTemplate(name, version)));
81-
composableIndexTemplates = indexTemplateNames.stream()
82-
.map(o -> (String) o)
83-
.collect(Collectors.toMap(name -> name, name -> loadIndexTemplate(name, version)));
84-
ingestPipelines = ingestPipelineConfigs.stream().map(o -> (Map<String, Map<String, Object>>) o).map(map -> {
85-
Map.Entry<String, Map<String, Object>> pipelineConfig = map.entrySet().iterator().next();
86-
return loadIngestPipeline(pipelineConfig.getKey(), version, (List<String>) pipelineConfig.getValue().get("dependencies"));
87-
}).collect(Collectors.toList());
88-
this.featureService = featureService;
89-
} catch (IOException e) {
90-
throw new RuntimeException(e);
91-
}
92-
}
93-
94-
public int getVersion() {
95-
return version;
96-
}
97-
98-
void setEnabled(boolean enabled) {
99-
logger.info("APM index template registry is {}", enabled ? "enabled" : "disabled");
100-
this.enabled = enabled;
101-
}
102-
103-
public boolean isEnabled() {
104-
return enabled;
105-
}
106-
107-
public void close() {
108-
clusterService.removeListener(this);
109-
}
110-
111-
@Override
112-
protected String getOrigin() {
113-
return ClientHelper.APM_ORIGIN;
114-
}
115-
116-
@Override
117-
protected boolean isClusterReady(ClusterChangedEvent event) {
118-
// Ensure current version of the components are installed only after versions that support data stream lifecycle
119-
// due to the use of the feature in all the `@lifecycle` component templates
120-
return featureService.clusterHasFeature(event.state(), DATA_STREAM_LIFECYCLE);
36+
super(nodeSettings, clusterService, threadPool, client, xContentRegistry, featureService);
12137
}
12238

12339
@Override
124-
protected boolean requiresMasterNode() {
125-
return true;
40+
public String getName() {
41+
return "apm";
12642
}
12743

12844
@Override
129-
protected Map<String, ComponentTemplate> getComponentTemplateConfigs() {
130-
if (enabled) {
131-
return componentTemplates;
132-
} else {
133-
return Map.of();
45+
public void initialize() {
46+
super.initialize();
47+
if (isEnabled()) {
48+
clusterService.getClusterSettings().addSettingsUpdateConsumer(APM_DATA_REGISTRY_ENABLED, this::setEnabled);
13449
}
13550
}
13651

13752
@Override
138-
protected Map<String, ComposableIndexTemplate> getComposableTemplateConfigs() {
139-
if (enabled) {
140-
return composableIndexTemplates;
141-
} else {
142-
return Map.of();
143-
}
144-
}
145-
146-
@Override
147-
protected List<IngestPipelineConfig> getIngestPipelines() {
148-
if (enabled) {
149-
return ingestPipelines;
150-
} else {
151-
return Collections.emptyList();
152-
}
153-
}
154-
155-
private static ComponentTemplate loadComponentTemplate(String name, int version) {
156-
try {
157-
final byte[] content = loadVersionedResourceUTF8("/component-templates/" + name + ".yaml", version);
158-
try (var parser = YamlXContent.yamlXContent.createParser(XContentParserConfiguration.EMPTY, content)) {
159-
return ComponentTemplate.parse(parser);
160-
}
161-
} catch (Exception e) {
162-
throw new RuntimeException("failed to load APM Ingest plugin's component template: " + name, e);
163-
}
164-
}
165-
166-
private static ComposableIndexTemplate loadIndexTemplate(String name, int version) {
167-
try {
168-
final byte[] content = loadVersionedResourceUTF8("/index-templates/" + name + ".yaml", version);
169-
try (var parser = YamlXContent.yamlXContent.createParser(XContentParserConfiguration.EMPTY, content)) {
170-
return ComposableIndexTemplate.parse(parser);
171-
}
172-
} catch (Exception e) {
173-
throw new RuntimeException("failed to load APM Ingest plugin's index template: " + name, e);
174-
}
175-
}
176-
177-
private static IngestPipelineConfig loadIngestPipeline(String name, int version, @Nullable List<String> dependencies) {
178-
if (dependencies == null) {
179-
dependencies = Collections.emptyList();
180-
}
181-
return new YamlIngestPipelineConfig(
182-
name,
183-
"/ingest-pipelines/" + name + ".yaml",
184-
version,
185-
APM_TEMPLATE_VERSION_VARIABLE,
186-
dependencies
187-
);
53+
protected String getVersionProperty() {
54+
return APM_TEMPLATE_VERSION_VARIABLE;
18855
}
18956

19057
@Override
191-
protected boolean applyRolloverAfterTemplateV2Upgrade() {
192-
return true;
58+
protected String getOrigin() {
59+
return ClientHelper.APM_ORIGIN;
19360
}
19461
}

x-pack/plugin/apm-data/src/main/java/org/elasticsearch/xpack/apmdata/APMPlugin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public Collection<?> createComponents(PluginServices services) {
6060
if (enabled) {
6161
APMIndexTemplateRegistry registryInstance = registry.get();
6262
registryInstance.setEnabled(APM_DATA_REGISTRY_ENABLED.get(settings));
63-
clusterService.getClusterSettings().addSettingsUpdateConsumer(APM_DATA_REGISTRY_ENABLED, registryInstance::setEnabled);
6463
registryInstance.initialize();
6564
}
6665
return Collections.emptyList();

x-pack/plugin/apm-data/src/main/java/org/elasticsearch/xpack/apmdata/ResourceUtils.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

x-pack/plugin/apm-data/src/main/resources/component-templates/[email protected]

Lines changed: 0 additions & 11 deletions
This file was deleted.

x-pack/plugin/apm-data/src/main/resources/resources.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ component-templates:
2323
- metrics-apm.service_summary@mappings
2424
- metrics-apm.service_transaction@mappings
2525
- metrics-apm.transaction@mappings
26-
- traces@mappings
2726
- traces-apm@mappings
2827
- traces-apm.rum@mappings
2928

x-pack/plugin/apm-data/src/test/java/org/elasticsearch/xpack/apmdata/APMIndexTemplateRegistryTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
public class APMIndexTemplateRegistryTests extends ESTestCase {
7676
private APMIndexTemplateRegistry apmIndexTemplateRegistry;
7777
private StackTemplateRegistryAccessor stackTemplateRegistryAccessor;
78-
private ClusterService clusterService;
7978
private ThreadPool threadPool;
8079
private VerifyingClient client;
8180

@@ -89,7 +88,7 @@ public void createRegistryAndClient() {
8988

9089
threadPool = new TestThreadPool(this.getClass().getName());
9190
client = new VerifyingClient(threadPool);
92-
clusterService = ClusterServiceUtils.createClusterService(threadPool, clusterSettings);
91+
ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool, clusterSettings);
9392
FeatureService featureService = new FeatureService(List.of(new DataStreamFeatures()));
9493
stackTemplateRegistryAccessor = new StackTemplateRegistryAccessor(
9594
new StackTemplateRegistry(Settings.EMPTY, clusterService, threadPool, client, NamedXContentRegistry.EMPTY, featureService)

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ClientHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ private static String maybeRewriteSingleAuthenticationHeaderForVersion(
194194
public static final String CONNECTORS_ORIGIN = "connectors";
195195
public static final String INFERENCE_ORIGIN = "inference";
196196
public static final String APM_ORIGIN = "apm";
197+
public static final String OTEL_ORIGIN = "otel";
197198

198199
private ClientHelper() {}
199200

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackSettings.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ public Iterator<Setting<?>> settings() {
9393
/** Setting for enabling or disabling APM Data. Defaults to true. */
9494
public static final Setting<Boolean> APM_DATA_ENABLED = Setting.boolSetting("xpack.apm_data.enabled", true, Setting.Property.NodeScope);
9595

96+
/** Setting for enabling or disabling OTel Data. Defaults to true. */
97+
public static final Setting<Boolean> OTEL_DATA_ENABLED = Setting.boolSetting(
98+
"xpack.otel_data.enabled",
99+
true,
100+
Setting.Property.NodeScope
101+
);
102+
96103
/** Setting for enabling or disabling enterprise search. Defaults to true. */
97104
public static final Setting<Boolean> ENTERPRISE_SEARCH_ENABLED = Setting.boolSetting(
98105
"xpack.ent_search.enabled",

0 commit comments

Comments
 (0)