Skip to content

Commit d0ac40f

Browse files
authored
[Profiling] Fix NullPointerExceptions by accepting dotted field names (#124506) (#124622)
* [Profiling] Fix NullPointerExceptions by accepting dotted field names Profiling uses synthetic source and thus expects nested field names in query responses. With 8.17+, synthetic source is available only to Enterprise (or higher) subscriptions, so that smaller subscriptions have dotted field names in query responses. The profiling plugin relies on nested field names and runs into NullPointerExceptions if these are not found. This PR fixes the NullPointerExceptions that could happen with dotted field names. * Evaluate source only once (cleanup) --------- Signed-off-by: Tim Rühsen <[email protected]>
1 parent 4735683 commit d0ac40f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/action/StackTrace.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,15 @@ static String getFileIDFromStackFrameID(String frameID) {
184184

185185
public static StackTrace fromSource(Map<String, Object> source) {
186186
String inputFrameIDs = ObjectPath.eval(PATH_FRAME_IDS, source);
187+
if (inputFrameIDs == null) {
188+
// If synthetic source is disabled, fallback to dotted field names.
189+
inputFrameIDs = (String) source.get("Stacktrace.frame.ids");
190+
}
187191
String inputFrameTypes = ObjectPath.eval(PATH_FRAME_TYPES, source);
192+
if (inputFrameTypes == null) {
193+
// If synthetic source is disabled, fallback to dotted field names.
194+
inputFrameTypes = (String) source.get("Stacktrace.frame.types");
195+
}
188196
int countsFrameIDs = inputFrameIDs.length() / BASE64_FRAME_ID_LENGTH;
189197

190198
String[] fileIDs = new String[countsFrameIDs];

x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/action/TransportGetStackTracesAction.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,12 @@ public void onExecutableDetailsResponse(MultiGetResponse multiGetItemResponses)
796796
if (executable.getResponse().isExists()) {
797797
// Duplicates are expected as we query multiple indices - do a quick pre-check before we deserialize a response
798798
if (executables.containsKey(executable.getId()) == false) {
799-
String fileName = ObjectPath.eval(PATH_FILE_NAME, executable.getResponse().getSource());
799+
Map<String, Object> source = executable.getResponse().getSource();
800+
String fileName = ObjectPath.eval(PATH_FILE_NAME, source);
801+
if (fileName == null) {
802+
// If synthetic source is disabled, read from dotted field names.
803+
fileName = (String) source.get("Executable.file.name");
804+
}
800805
if (fileName != null) {
801806
executables.putIfAbsent(executable.getId(), fileName);
802807
} else {

0 commit comments

Comments
 (0)