Skip to content

Commit df4fcc7

Browse files
Add descriptions for special input parameters in Configuration Docs (#1423)
* Add descriptions for special Input parameters * Add javadocs for new attribute
1 parent 8a59be6 commit df4fcc7

File tree

5 files changed

+79
-21
lines changed

5 files changed

+79
-21
lines changed

components/inspectit-ocelot-configdocsgenerator/src/main/java/inspectit/ocelot/configdocsgenerator/ConfigDocsGenerator.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.io.IOException;
2222
import java.lang.reflect.Field;
2323
import java.util.*;
24+
import java.util.regex.Matcher;
25+
import java.util.regex.Pattern;
2426
import java.util.stream.Collectors;
2527

2628
/**
@@ -29,6 +31,26 @@
2931
*/
3032
public class ConfigDocsGenerator {
3133

34+
/**
35+
* Map of descriptions for special input parameters.
36+
*/
37+
Map<String, String> specialInputDescriptions = new HashMap<String, String>() {{
38+
put("_methodName", "The name of the instrumented method within which this action is getting executed.");
39+
put("_class", "The class declaring the instrumented method within which this action is getting executed.");
40+
put("_parameterTypes", "The types of the parameters which the instrumented method declares for which the action is executed.");
41+
put("_this", "The this-instance in the context of the instrumented method within which this action is getting executed.");
42+
put("_args", "The arguments with which the instrumented method was called within which this action is getting executed. The arguments are boxed if necessary and packed into an array.");
43+
put("_returnValue", "The value returned by the instrumented method within which this action is getting executed. If the method terminated with an exception or the action is executed in the entry phase this is null.");
44+
put("_thrown", "The exception thrown by the instrumented method within which this action is getting executed. If the method returned normally or the action is executed in the entry phase this is null.");
45+
put("_context", "Gives direct read and write access to the current context. Can be used to implement custom data propagation.");
46+
put("_attachments", "Allows you to attach values to objects instead of to the control flow, as done via _context.");
47+
}};
48+
49+
/**
50+
* Map of descriptions for special input parameters that can have different names matching a regex.
51+
*/
52+
Map<String, String> specialInputDescriptionsRegex = Collections.singletonMap("_arg\\d", "The _argN-th argument with which the instrumented method was called within which this action is getting executed.");
53+
3254
/**
3355
* Generates a ConfigDocumentation from a YAML String describing an {@link InspectitConfig}.
3456
*
@@ -163,7 +185,27 @@ private List<ActionDocs> generateActionDocs(Map<String, GenericActionSettings> a
163185
Map<String, String> inputTypes = actionSettings.getInput();
164186

165187
for (String inputName : inputTypes.keySet()) {
166-
inputs.add(new ActionInputDocs(inputName, inputTypes.get(inputName), inputDescriptions.getOrDefault(inputName, "")));
188+
String inputDescription = "";
189+
190+
if (inputName.startsWith("_")) {
191+
192+
if (specialInputDescriptions.containsKey(inputName)) {
193+
inputDescription = specialInputDescriptions.get(inputName);
194+
195+
} else {
196+
for (String inputNameRegex : specialInputDescriptionsRegex.keySet()) {
197+
Pattern pattern = Pattern.compile(inputNameRegex);
198+
Matcher matcher = pattern.matcher(inputName);
199+
if (matcher.matches()) {
200+
inputDescription = specialInputDescriptionsRegex.get(inputNameRegex);
201+
}
202+
}
203+
}
204+
} else {
205+
inputDescription = inputDescriptions.getOrDefault(inputName, "");
206+
}
207+
208+
inputs.add(new ActionInputDocs(inputName, inputTypes.get(inputName), inputDescription));
167209
}
168210
inputs.sort(Comparator.comparing(ActionInputDocs::getName));
169211

components/inspectit-ocelot-configdocsgenerator/src/test/java/inspectit/ocelot/configdocsgenerator/ConfigDocsGeneratorTest.java

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,21 @@ private static void createDocObjects() {
6161
// doc-key
6262
List<ActionInputDocs> inputs1 = new ArrayList<>();
6363

64-
ActionInputDocs actionInputDocsMock = Mockito.mock(ActionInputDocs.class);
65-
when(actionInputDocsMock.getName()).thenReturn("value");
66-
when(actionInputDocsMock.getType()).thenReturn("Object");
67-
when(actionInputDocsMock.getDescription()).thenReturn("Object to be printed");
68-
inputs1.add(actionInputDocsMock);
64+
ActionInputDocs actionInputDocsMock1 = Mockito.mock(ActionInputDocs.class);
65+
when(actionInputDocsMock1.getName()).thenReturn("_arg1");
66+
when(actionInputDocsMock1.getType()).thenReturn("Object");
67+
when(actionInputDocsMock1.getDescription()).thenReturn("The _argN-th argument with which the instrumented method was called within which this action is getting executed.");
68+
inputs1.add(actionInputDocsMock1);
69+
ActionInputDocs actionInputDocsMock2 = Mockito.mock(ActionInputDocs.class);
70+
when(actionInputDocsMock2.getName()).thenReturn("_attachments");
71+
when(actionInputDocsMock2.getType()).thenReturn("ObjectAttachments");
72+
when(actionInputDocsMock2.getDescription()).thenReturn("Allows you to attach values to objects instead of to the control flow, as done via _context.");
73+
inputs1.add(actionInputDocsMock2);
74+
ActionInputDocs actionInputDocsMock3 = Mockito.mock(ActionInputDocs.class);
75+
when(actionInputDocsMock3.getName()).thenReturn("value");
76+
when(actionInputDocsMock3.getType()).thenReturn("Object");
77+
when(actionInputDocsMock3.getDescription()).thenReturn("Object to be printed");
78+
inputs1.add(actionInputDocsMock3);
6979

7080
actionWithDocInYaml = Mockito.mock(ActionDocs.class);
7181
when(actionWithDocInYaml.getName()).thenReturn("a_debug_println");
@@ -78,17 +88,17 @@ private static void createDocObjects() {
7888
// Create a sample ActionDoc object where there was no documentation values in the YAML
7989
List<ActionInputDocs> inputs2 = new ArrayList<>();
8090

81-
ActionInputDocs actionInputDocsMock2 = Mockito.mock(ActionInputDocs.class);
82-
when(actionInputDocsMock2.getName()).thenReturn("a");
83-
when(actionInputDocsMock2.getType()).thenReturn("Object");
84-
when(actionInputDocsMock2.getDescription()).thenReturn("");
85-
inputs2.add(actionInputDocsMock2);
91+
ActionInputDocs actionInputDocsMock4 = Mockito.mock(ActionInputDocs.class);
92+
when(actionInputDocsMock4.getName()).thenReturn("a");
93+
when(actionInputDocsMock4.getType()).thenReturn("Object");
94+
when(actionInputDocsMock4.getDescription()).thenReturn("");
95+
inputs2.add(actionInputDocsMock4);
8696

87-
ActionInputDocs actionInputDocsMock3 = Mockito.mock(ActionInputDocs.class);
88-
when(actionInputDocsMock3.getName()).thenReturn("b");
89-
when(actionInputDocsMock3.getType()).thenReturn("Object");
90-
when(actionInputDocsMock3.getDescription()).thenReturn("");
91-
inputs2.add(actionInputDocsMock3);
97+
ActionInputDocs actionInputDocsMock5 = Mockito.mock(ActionInputDocs.class);
98+
when(actionInputDocsMock5.getName()).thenReturn("b");
99+
when(actionInputDocsMock5.getType()).thenReturn("Object");
100+
when(actionInputDocsMock5.getDescription()).thenReturn("");
101+
inputs2.add(actionInputDocsMock5);
92102

93103
actionWithoutDocInYaml = Mockito.mock(ActionDocs.class);
94104
when(actionWithoutDocInYaml.getName()).thenReturn("a_debug_println_2");
@@ -345,4 +355,4 @@ void loadAll() throws IOException {
345355
}
346356
}
347357

348-
}
358+
}

components/inspectit-ocelot-configdocsgenerator/src/test/resources/ConfigDocGeneratorTest/actionWithDocInYaml.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ inspectit:
1111
since: '1.0'
1212
input:
1313
value: Object
14+
_arg1: Object
15+
_attachments: ObjectAttachments
1416
is-void: true
15-
value: System.out.println(value);
17+
value: System.out.println(value);

components/inspectit-ocelot-configdocsgenerator/src/test/resources/ConfigDocGeneratorTest/all.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ inspectit:
2121
since: '1.0'
2222
input:
2323
value: Object
24+
_arg1: Object
25+
_attachments: ObjectAttachments
2426
is-void: true
2527
value: System.out.println(value);
2628

@@ -38,7 +40,7 @@ inspectit:
3840
- name: executeUpdate
3941
advanced:
4042
instrument-only-inherited-methods: true
41-
43+
4244
rules:
4345
r_tracing_global_attributes:
4446
exit:
@@ -92,4 +94,4 @@ inspectit:
9294
enabled: ${inspectit.metrics.disk.enabled.free}
9395
type: LONG
9496
unit: bytes
95-
description: free disk space
97+
description: free disk space

components/inspectit-ocelot-configdocsgenerator/src/test/resources/ConfigDocGeneratorTest/multipleActions.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@ inspectit:
2121
since: '1.0'
2222
input:
2323
value: Object
24+
_arg1: Object
25+
_attachments: ObjectAttachments
2426
is-void: true
25-
value: System.out.println(value);
27+
value: System.out.println(value);

0 commit comments

Comments
 (0)