Skip to content

Commit c0efcd0

Browse files
authored
[Profiling] Fix NullPointerExceptions by accepting dotted field names (#124506)
* [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. Signed-off-by: Tim Rühsen <[email protected]> * Evaluate source only once (cleanup) --------- Signed-off-by: Tim Rühsen <[email protected]>
1 parent 49f7cfb commit c0efcd0

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
@@ -790,7 +790,12 @@ public void onExecutableDetailsResponse(MultiGetResponse multiGetItemResponses)
790790
if (executable.getResponse().isExists()) {
791791
// Duplicates are expected as we query multiple indices - do a quick pre-check before we deserialize a response
792792
if (executables.containsKey(executable.getId()) == false) {
793-
String fileName = ObjectPath.eval(PATH_FILE_NAME, executable.getResponse().getSource());
793+
Map<String, Object> source = executable.getResponse().getSource();
794+
String fileName = ObjectPath.eval(PATH_FILE_NAME, source);
795+
if (fileName == null) {
796+
// If synthetic source is disabled, read from dotted field names.
797+
fileName = (String) source.get("Executable.file.name");
798+
}
794799
if (fileName != null) {
795800
executables.putIfAbsent(executable.getId(), fileName);
796801
} else {

0 commit comments

Comments
 (0)