-
Notifications
You must be signed in to change notification settings - Fork 96
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
Adds some additional timings. #110
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2016 Yahoo Inc. | ||
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. | ||
package com.yahoo.bard.webservice.druid.model.filter; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A Druid filter that is defined by applying an operation to at least one other filter. For example, {@code not} and | ||
* {@code and} filters are complex. A {@code selector} filter is not. | ||
*/ | ||
public interface ComplexFilter { | ||
|
||
/** | ||
* Returns the filters that are operated on by this filter. | ||
* | ||
* @return The filters operated on by this filter | ||
*/ | ||
List<Filter> getFields(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2016 Yahoo Inc. | ||
// Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. | ||
package com.yahoo.bard.webservice.logging.blocks; | ||
|
||
import com.yahoo.bard.webservice.druid.model.filter.ComplexFilter; | ||
import com.yahoo.bard.webservice.druid.model.filter.Filter; | ||
import com.yahoo.bard.webservice.logging.LogInfo; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAutoDetect; | ||
|
||
import java.util.ArrayDeque; | ||
import java.util.Collections; | ||
import java.util.Deque; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Logs some structural data about the filter sent to Druid, without actually logging the entire (potentially massive) | ||
* filter. | ||
*/ | ||
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) | ||
public class DruidFilterInfo implements LogInfo { | ||
|
||
protected final Map<String, Long> numEachFilterType; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param filter The filter that needs to be analyzed | ||
*/ | ||
public DruidFilterInfo(Filter filter) { | ||
numEachFilterType = buildFilterCount(filter); | ||
} | ||
|
||
/** | ||
* Performs a DFS search of the filter tree, populating the specified map with the number of instances of each | ||
* filter type appearing in the filter. | ||
* | ||
* @param filter The filter that needs to be traversed | ||
* | ||
* @return A map containing a count of each type of filter | ||
*/ | ||
private Map<String, Long> buildFilterCount(Filter filter) { | ||
if (filter == null) { | ||
return Collections.emptyMap(); | ||
} | ||
Map<String, Long> filterTypeCounter = new LinkedHashMap<>(); | ||
Deque<Filter> filterStack = new ArrayDeque<>(); | ||
filterStack.add(filter); | ||
while (!filterStack.isEmpty()) { | ||
Filter currentFilter = filterStack.pop(); | ||
filterTypeCounter.merge(currentFilter.getClass().getSimpleName(), 1L, (old, increment) -> old + increment); | ||
if (currentFilter instanceof ComplexFilter) { | ||
filterStack.addAll(((ComplexFilter) currentFilter).getFields()); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This smells a little like extensibility pain... It would be great if Java made it easy to ask if things had various methods, but about the best we can do is add interfaces for specific methods. To that end, do we want to make Specifically, it's the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are going to have that kind of interface, I'd much rather just have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To me, That said, I'm happy with |
||
} | ||
return filterTypeCounter; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep this whitespace