Skip to content

Commit 90be61a

Browse files
authored
update generated properties reference (#4065)
1 parent e382712 commit 90be61a

File tree

6 files changed

+85
-226
lines changed

6 files changed

+85
-226
lines changed

apm-agent-builds/apm-agent/src/test/java/co/elastic/apm/agent/configuration/ConfigurationExporter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static void main(String[] args) throws Exception {
4444
ConfigurationRegistry configurationRegistry = ConfigurationRegistry.builder()
4545
.optionProviders(ServiceLoader.load(ConfigurationOptionProvider.class))
4646
.build();
47-
Path path = Paths.get("docs/configuration.asciidoc");
47+
Path path = Paths.get("docs/reference/config-reference-properties-file.md");
4848
if (!path.toFile().canWrite()) {
4949
throw new IllegalStateException(path + " does not exist");
5050
}

apm-agent-builds/apm-agent/src/test/java/co/elastic/apm/agent/configuration/ConfigurationExporterTest.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import freemarker.template.TemplateExceptionHandler;
3030
import org.junit.jupiter.api.AfterEach;
3131
import org.junit.jupiter.api.BeforeEach;
32-
import org.junit.jupiter.api.Disabled;
3332
import org.junit.jupiter.api.Test;
3433
import org.stagemonitor.configuration.ConfigurationOption;
3534
import org.stagemonitor.configuration.ConfigurationOptionProvider;
@@ -41,6 +40,8 @@
4140
import java.nio.file.Files;
4241
import java.nio.file.Path;
4342
import java.nio.file.Paths;
43+
import java.util.ArrayList;
44+
import java.util.Arrays;
4445
import java.util.Iterator;
4546
import java.util.List;
4647
import java.util.Map;
@@ -51,6 +52,7 @@
5152
import java.util.stream.Collectors;
5253

5354
import static org.assertj.core.api.Assertions.assertThat;
55+
import static org.assertj.core.api.Assertions.fail;
5456
import static org.mockito.Mockito.doReturn;
5557
import static org.mockito.Mockito.mock;
5658

@@ -86,7 +88,7 @@ class ConfigurationExporterTest {
8688

8789
@BeforeEach
8890
void setUp() {
89-
renderedDocumentationPath = Paths.get("../../docs/configuration.asciidoc");
91+
renderedDocumentationPath = Paths.get("../../docs/reference/config-reference-properties-file.md");
9092
ElasticApmTracer tracer = mock(ElasticApmTracer.class);
9193
doReturn(tracer).when(tracer).require(ElasticApmTracer.class);
9294
doReturn(ElasticApmTracer.TracerState.UNINITIALIZED).when(tracer).getState();
@@ -108,20 +110,33 @@ void tearDown() {
108110
* Since we allow a limited number of unit-test failures, this test would have always passed without this configuration.
109111
*/
110112
@Test
111-
@Disabled("Needs migration or update for new docs system")
112113
void testGeneratedConfigurationDocsAreUpToDate() throws IOException, TemplateException {
113114
String renderedDocumentation = renderDocumentation(configurationRegistry);
114-
String expected = new String(Files.readAllBytes(this.renderedDocumentationPath), StandardCharsets.UTF_8);
115+
116+
// trim EOL whitespace
117+
List<String> lines = new ArrayList<>(Arrays.asList(renderedDocumentation.split("\n")));
118+
for (int i = 0; i < lines.size(); i++) {
119+
lines.set(i, lines.get(i).replaceAll("\\s+$", ""));
120+
}
121+
// add extra empty line at end of file
122+
lines.add("");
123+
renderedDocumentation = String.join("\n", lines);
115124

116125
if (Boolean.parseBoolean(System.getProperty("elastic.apm.overwrite.config.docs", Boolean.TRUE.toString()))) {
117126
// unless explicitly disabled (e.g. on CI) overwrite the current documentation
118127
Files.write(renderedDocumentationPath, renderedDocumentation.getBytes(StandardCharsets.UTF_8));
119128
}
120129

130+
if (!Files.exists(this.renderedDocumentationPath)) {
131+
fail("rendered documentation file does not exists %s", this.renderedDocumentationPath.toAbsolutePath());
132+
}
133+
134+
String expected = new String(Files.readAllBytes(this.renderedDocumentationPath), StandardCharsets.UTF_8);
135+
121136
assertThat(renderedDocumentation)
122137
.withFailMessage("The rendered configuration documentation (/docs/configuration.asciidoc) is not up-to-date.\n" +
123138
"If you see this error on CI, it means you have to execute the tests locally " +
124-
"(./mvnw -Dsurefire.failIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=false -Dtest=ConfigurationExporterTest -pl apm-agent -am clean test) " +
139+
"(./mvnw -Dsurefire.failIfNoTests=false -Dsurefire.failIfNoSpecifiedTests=false -Dtest=ConfigurationExporterTest -pl apm-agent-builds/apm-agent -am clean test) " +
125140
"or on Windows(.\\mvnw \"-Dsurefire.failIfNoTests=false\" \"-Dsurefire.failIfNoSpecifiedTests=false\" -Dtest=ConfigurationExporterTest -pl apm-agent-builds/apm-agent -am clean test) " +
126141
"which will update the rendered docs.\n" +
127142
"If you see this error while running the tests locally, there's nothing more to do - the rendered docs have been updated " +
@@ -136,13 +151,11 @@ static String renderDocumentation(ConfigurationRegistry configurationRegistry) t
136151
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
137152
cfg.setLogTemplateExceptions(false);
138153

139-
Template temp = cfg.getTemplate("configuration.asciidoc.ftl");
154+
// trim EOL whitespace
155+
cfg.setWhitespaceStripping(true);
156+
157+
Template temp = cfg.getTemplate("config-reference-properties-file.md.ftl");
140158
StringWriter tempRenderedFile = new StringWriter();
141-
tempRenderedFile.write("////\n" +
142-
"This file is auto generated\n" +
143-
"\n" +
144-
"Please only make changes in configuration.asciidoc.ftl\n" +
145-
"////\n");
146159
final List<ConfigurationOption<?>> nonInternalOptions = configurationRegistry.getConfigurationOptionsByCategory()
147160
.values()
148161
.stream()
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
mapped_pages:
3+
- https://www.elastic.co/guide/en/apm/agent/java/current/config-reference-properties-file.html
4+
---
5+
6+
# Property file reference [config-reference-properties-file]
7+
8+
```properties
9+
<#list config as category, options>
10+
############################################
11+
# ${category?right_pad(40)} #
12+
############################################
13+
14+
<#list options as option>
15+
<#if !option.tags?seq_contains("internal")>
16+
<#if option.label?has_content>
17+
# ${option.label}
18+
#
19+
</#if>
20+
# ${option.description?replace("\n", "\n# ", "r")}
21+
#
22+
<#if option.validOptions?has_content>
23+
# Valid options: <#list option.validOptionsLabelMap?values as validOption>${validOption}<#if validOption_has_next>, </#if></#list>
24+
</#if>
25+
# ${option.dynamic?then("This setting can be changed at runtime",
26+
"This setting can not be changed at runtime. Changes require a restart of the application.")}
27+
# Type: ${option.valueType?matches("List|Collection")?then("comma separated list", option.valueType)}
28+
<#if option.valueType?matches("TimeDuration")>
29+
<#if option.valueConverter.canUseMicros>
30+
# Supports the duration suffixes us, ms, s and m. Example: ${option.defaultValueAsString}.
31+
<#else>
32+
# Supports the duration suffixes ms, s and m. Example: ${option.defaultValueAsString}.
33+
</#if>
34+
</#if>
35+
# Default value: ${option.key?matches("service_name")?then('Auto-detected based on the rules described above', option.defaultValueAsString!)}
36+
#
37+
# ${option.key}=${option.key?matches("service_name")?then('', option.defaultValueAsString!)}
38+
39+
</#if>
40+
</#list>
41+
</#list>
42+
```

apm-agent-builds/apm-agent/src/test/resources/configuration.asciidoc.ftl

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

apm-agent-core/src/main/java/co/elastic/apm/agent/configuration/CoreConfigurationImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ public String toSafeString(List<WildcardMatcher> value) {
636636
"\n" +
637637
"A few examples:\n" +
638638
"\n" +
639-
" - `org.example.*` added[1.4.0,Omitting the method is possible since 1.4.0]\n" +
639+
" - `org.example.*` added:[1.4.0,Omitting the method is possible since 1.4.0]\n" +
640640
" - `org.example.*#*` (before 1.4.0, you need to specify a method matcher)\n" +
641641
" - `org.example.MyClass#myMethod`\n" +
642642
" - `org.example.MyClass#myMethod()`\n" +

0 commit comments

Comments
 (0)