Skip to content

Commit

Permalink
Use index prefix for template index pattern in ElasticMeterRegistry (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye authored Sep 17, 2020
1 parent 2f6558d commit 17f5210
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -90,9 +91,9 @@ public class ElasticMeterRegistry extends StepMeterRegistry {
" \"type\": \"double\"\n" +
" }\n" +
"}";
private static final String TEMPLATE_BODY_BEFORE_VERSION_7 = "{\"template\":\"metrics*\",\"mappings\":{\"_default_\":{\"_all\":{\"enabled\":false}," + TEMPLATE_PROPERTIES + "}}}";
private static final String TEMPLATE_BODY_AFTER_VERSION_7 = "{\n" +
" \"index_patterns\": [\"metrics*\"],\n" +
private static final Function<String, String> TEMPLATE_BODY_BEFORE_VERSION_7 = (indexPrefix) -> "{\"template\":\"" + indexPrefix + "*\",\"mappings\":{\"_default_\":{\"_all\":{\"enabled\":false}," + TEMPLATE_PROPERTIES + "}}}";
private static final Function<String, String> TEMPLATE_BODY_AFTER_VERSION_7 = (indexPrefix) -> "{\n" +
" \"index_patterns\": [\"" + indexPrefix + "*\"],\n" +
" \"mappings\": {\n" +
" \"_source\": {\n" +
" \"enabled\": false\n" +
Expand Down Expand Up @@ -180,7 +181,7 @@ private void createIndexTemplateIfNeeded() {
}

private String getTemplateBody() {
return majorVersion < 7 ? TEMPLATE_BODY_BEFORE_VERSION_7 : TEMPLATE_BODY_AFTER_VERSION_7;
return majorVersion < 7 ? TEMPLATE_BODY_BEFORE_VERSION_7.apply(config.index()) : TEMPLATE_BODY_AFTER_VERSION_7.apply(config.index());
}

@Override
Expand Down

0 comments on commit 17f5210

Please sign in to comment.