Skip to content

Commit

Permalink
Mark legacy stack templates as deprecated (elastic#101476)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixbarny authored Nov 8, 2023
1 parent 5a2b618 commit 16cce1f
Show file tree
Hide file tree
Showing 33 changed files with 277 additions and 69 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/101476.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 101476
summary: Mark legacy stack templates as deprecated
area: Indices APIs
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Map;

public class ResourceUtils {

public static final String APM_TEMPLATE_VERSION_VARIABLE = "xpack.apmdata.template.version";

static byte[] loadVersionedResourceUTF8(String name, int version) {
return loadVersionedResourceUTF8(name, version, Map.of());
}

static byte[] loadVersionedResourceUTF8(String name, int version, Map<String, String> variables) {
try {
String content = loadResource(name);
content = TemplateUtils.replaceVariable(content, APM_TEMPLATE_VERSION_VARIABLE, String.valueOf(version));
content = TemplateUtils.replaceVariables(content, String.valueOf(version), APM_TEMPLATE_VERSION_VARIABLE, variables);
return content.getBytes(StandardCharsets.UTF_8);
} catch (IOException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public XContentType getXContentType() {

@Override
public BytesReference loadConfig() {
return new BytesArray(loadVersionedResourceUTF8("/ingest-pipelines/" + id + ".yaml", version));
return new BytesArray(loadVersionedResourceUTF8("/ingest-pipelines/" + id + ".yaml", version, variables));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
Expand All @@ -22,6 +23,7 @@ public abstract class IngestPipelineConfig {
protected final String resource;
protected final int version;
protected final String versionProperty;
protected final Map<String, String> variables;

/**
* A list of this pipeline's dependencies, for example - such referred to through a pipeline processor.
Expand All @@ -35,11 +37,23 @@ public IngestPipelineConfig(String id, String resource, int version, String vers
}

public IngestPipelineConfig(String id, String resource, int version, String versionProperty, List<String> dependencies) {
this(id, resource, version, versionProperty, dependencies, Map.of());
}

public IngestPipelineConfig(
String id,
String resource,
int version,
String versionProperty,
List<String> dependencies,
Map<String, String> variables
) {
this.id = Objects.requireNonNull(id);
this.resource = Objects.requireNonNull(resource);
this.version = version;
this.versionProperty = Objects.requireNonNull(versionProperty);
this.dependencies = dependencies;
this.variables = Objects.requireNonNull(variables);
}

public String getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.xcontent.XContentType;

import java.util.List;
import java.util.Map;

public class JsonIngestPipelineConfig extends IngestPipelineConfig {
public JsonIngestPipelineConfig(String id, String resource, int version, String versionProperty) {
Expand All @@ -22,13 +23,24 @@ public JsonIngestPipelineConfig(String id, String resource, int version, String
super(id, resource, version, versionProperty, dependencies);
}

public JsonIngestPipelineConfig(
String id,
String resource,
int version,
String versionProperty,
List<String> dependencies,
Map<String, String> variables
) {
super(id, resource, version, versionProperty, dependencies, variables);
}

@Override
public XContentType getXContentType() {
return XContentType.JSON;
}

@Override
public BytesReference loadConfig() {
return new BytesArray(TemplateUtils.loadTemplate(resource, String.valueOf(version), versionProperty));
return new BytesArray(TemplateUtils.loadTemplate(resource, String.valueOf(version), versionProperty, variables));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static void validate(String source) {
}
}

private static String replaceVariables(String input, String version, String versionProperty, Map<String, String> variables) {
public static String replaceVariables(String input, String version, String versionProperty, Map<String, String> variables) {
String template = replaceVariable(input, versionProperty, version);
for (Map.Entry<String, String> variable : variables.entrySet()) {
template = replaceVariable(template, variable.getKey(), variable.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
"_meta": {
"description": "built-in ILM policy using the hot, warm, and cold phases with a retention of 180 days",
"managed": true
}
},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
"_meta": {
"description": "built-in ILM policy using the hot and warm phases with a retention of 30 days",
"managed": true
}
},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
"_meta": {
"description": "built-in ILM policy using the hot, warm, and cold phases with a retention of 365 days",
"managed": true
}
},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
"_meta": {
"description": "built-in ILM policy using the hot and warm phases with a retention of 7 days",
"managed": true
}
},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
"_meta": {
"description": "built-in ILM policy using the hot, warm, and cold phases with a retention of 90 days",
"managed": true
}
},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@
"description": "general mapping conventions for data streams",
"managed": true
},
"version": ${xpack.stack.template.version}
"version": ${xpack.stack.template.version},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,6 @@
"description": "dynamic mappings based on ECS, installed by x-pack",
"managed": true
},
"version": ${xpack.stack.template.version}
"version": ${xpack.stack.template.version},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,6 @@
"description": "default kibana reporting template installed by elasticsearch",
"managed": true
},
"version": ${xpack.stack.template.version}
"version": ${xpack.stack.template.version},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"description": "default pipeline for the logs index template installed by x-pack",
"managed": true
},
"version": ${xpack.stack.template.version}
"version": ${xpack.stack.template.version},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@
"description": "automatic parsing of JSON log messages",
"managed": true
},
"version": ${xpack.stack.template.version}
"version": ${xpack.stack.template.version},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"_meta": {
"description": "default policy for the logs index template installed by x-pack",
"managed": true
}
},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
"description": "default mappings for the logs index template installed by x-pack",
"managed": true
},
"version": ${xpack.stack.template.version}
"version": ${xpack.stack.template.version},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"description": "default settings for the logs index template installed by x-pack",
"managed": true
},
"version": ${xpack.stack.template.version}
"version": ${xpack.stack.template.version},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"description": "default logs template installed by x-pack",
"managed": true
},
"version": ${xpack.stack.template.version}
"version": ${xpack.stack.template.version},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"_meta": {
"description": "default policy for the metrics index template installed by x-pack",
"managed": true
}
},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@
"description": "default mappings for the metrics index template installed by x-pack",
"managed": true
},
"version": ${xpack.stack.template.version}
"version": ${xpack.stack.template.version},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"description": "default settings for the metrics index template installed by x-pack",
"managed": true
},
"version": ${xpack.stack.template.version}
"version": ${xpack.stack.template.version},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"description": "default metrics template installed by x-pack",
"managed": true
},
"version": ${xpack.stack.template.version}
"version": ${xpack.stack.template.version},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"description": "default settings for the metrics index template installed by x-pack",
"managed": true
},
"version": ${xpack.stack.template.version}
"version": ${xpack.stack.template.version},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"_meta": {
"description": "default policy for the synthetics index template installed by x-pack",
"managed": true
}
},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"description": "default mappings for the synthetics index template installed by x-pack",
"managed": true
},
"version": ${xpack.stack.template.version}
"version": ${xpack.stack.template.version},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"description": "default settings for the synthetics index template installed by x-pack",
"managed": true
},
"version": ${xpack.stack.template.version}
"version": ${xpack.stack.template.version},
"deprecated": ${xpack.stack.template.deprecated}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"description": "default synthetics template installed by x-pack",
"managed": true
},
"version": ${xpack.stack.template.version}
"version": ${xpack.stack.template.version},
"deprecated": ${xpack.stack.template.deprecated}
}
Loading

0 comments on commit 16cce1f

Please sign in to comment.