Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Short-circuit StageData creation in trace generation #430

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ protected String getStageBreakdown(Run run) {
return null;
}

final List<StageData> stages = traverseStages(currentHeads);
// Limit stage count to MAX_TAG_LENGTH since each stage will contribute at least 1 to the tag length json
final List<StageData> stages = traverseStages(currentHeads, MAX_TAG_LENGTH);
if (stages == null) {
logger.warning("Skipping sending stage to Datadog; stage breakdown is too large");
return null;
}

Collections.sort(stages);

final String stagesJson = JsonUtils.toJson(new ArrayList<>(stages));
Expand All @@ -101,7 +107,14 @@ protected String getStageBreakdown(Run run) {
return stagesJson;
}

private List<StageData> traverseStages(List<FlowNode> heads) {
/**
* Find all stages associated with heads, unless the number of stages exceeds the limit, in which case we
* short-circuit and omit stage data altogether.
* @param heads
* @param limit
* @return stages or null if there are more stages than the limit
*/
private List<StageData> traverseStages(List<FlowNode> heads, int limit) {
List<StageData> stages = new ArrayList<>();
Queue<FlowNode> nodes = new ArrayDeque<>(heads);
while (!nodes.isEmpty()) {
Expand All @@ -126,6 +139,11 @@ private List<StageData> traverseStages(List<FlowNode> heads) {
continue;
}

// If adding another stage would result in exceeding the limit then return instead
if (stages.size() >= limit) {
return null;
}

StageData stageData = new StageData.Builder()
.withName(startNode.getDisplayName())
.withStartTimeInMicros(startTimeMicros)
Expand Down
Loading