Skip to content

Commit

Permalink
Use all profiling events on startup
Browse files Browse the repository at this point in the history
With this commit we use `profiling-events-all` to query profiling events
if the appropriate index for a sample count is not present yet. This can
happen on cluster startup when only a few events have been accumulated
because additional indices are only created when there are enough
events. This aligns behavior of the Elasticsearch plugin with the Kibana
plugin.

Relates elastic#91640
  • Loading branch information
danielmitterdorfer committed Dec 5, 2022
1 parent 22f54f6 commit 2413d78
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package org.elasticsearch.xpack.profiler;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.get.MultiGetItemResponse;
import org.elasticsearch.action.get.MultiGetResponse;
Expand All @@ -17,6 +19,7 @@
import org.elasticsearch.client.internal.node.NodeClient;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.util.Maps;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.Sum;
Expand All @@ -33,6 +36,7 @@
import java.util.Set;

public class TransportGetProfilingAction extends HandledTransportAction<GetProfilingRequest, GetProfilingResponse> {
private static final Logger log = LogManager.getLogger(TransportGetProfilingAction.class);
private final NodeClient nodeClient;
private final TransportService transportService;

Expand All @@ -59,11 +63,21 @@ public void onResponse(SearchResponse searchResponse) {
searchEventGroupByStackTrace(client, request, resampledIndex, submitListener);
}

@Override
public void onFailure(Exception e) {
@Override
public void onFailure(Exception e) {
// Apart from profiling-events-all, indices are created lazily. In a relatively empty cluster it can happen
// that there are so few data that we need to resort to the full index. As this is an edge case we'd rather
// fail instead of prematurely checking for existence in all cases.
if (e instanceof IndexNotFoundException) {
String missingIndex = ((IndexNotFoundException) e).getIndex().getName();
EventsIndex fullIndex = EventsIndex.FULL_INDEX;
log.debug("Index [{}] does not exist. Using [{}] instead.", missingIndex, fullIndex.getName());
searchEventGroupByStackTrace(client, request, fullIndex, submitListener);
} else {
submitListener.onFailure(e);
}
});
}
});
}

private void searchEventGroupByStackTrace(
Expand Down

0 comments on commit 2413d78

Please sign in to comment.