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

Add logging of query IDs via QueryLogIterator class #2451

Open
wants to merge 23 commits into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
aab6f6b
Add TServer logging of query IDs
SethSmucker Mar 21, 2024
7a967cf
Removed star imports
SethSmucker Jun 6, 2024
e80161d
tserverLoggingActivce added to ShardQueryConfiguraitonTest
SethSmucker Jun 6, 2024
27285cc
tserverLoggingActivce added to ShardQueryConfiguraitonTest
SethSmucker Jun 6, 2024
031adf8
Fix CountQueryTest issues (#1)
lbschanno Jun 6, 2024
879f0b2
Fix NPE issues (#2)
lbschanno Jun 6, 2024
4dfab3d
Add TserverLoggingTest and make configuration changes (#3)
lbschanno Jun 7, 2024
8347fa3
Added javadocs
SethSmucker Jun 7, 2024
75bcf9e
Added class comment
SethSmucker Jun 7, 2024
aa123f7
Formatting
SethSmucker Jun 7, 2024
c5c75a9
Merge branch 'integration' into log-iterator
SethSmucker Jun 7, 2024
e5e1883
Add TServer logging of query IDs and Tests
SethSmucker Mar 21, 2024
9550f60
Merged with upstream/log-iterator
SethSmucker Jun 20, 2024
09cb6e1
Suggested formatting tweaks
SethSmucker Jun 25, 2024
4575f22
Suggested formatting tweaks
SethSmucker Jun 25, 2024
c44ce02
Merge branch 'integration' into log-iterator
lbschanno Jun 25, 2024
e48807b
Commit test
SethSmucker Jun 28, 2024
43f8f32
Fixed SQL bug
SethSmucker Jun 28, 2024
3aed0d6
Merge branch 'integration' into log-iterator
SethSmucker Jun 28, 2024
2a7f891
Merge branch 'integration' into log-iterator
SethSmucker Jul 1, 2024
4838e69
Merge branch 'integration' into log-iterator
lbschanno Jul 1, 2024
49600e5
Merge branch 'integration' into log-iterator
SethSmucker Jul 2, 2024
93d38c8
Merge branch 'integration' into log-iterator
SethSmucker Jul 5, 2024
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 @@ -494,6 +494,11 @@ public class ShardQueryConfiguration extends GenericQueryConfiguration implement
*/
private boolean sortQueryByCounts = false;

/**
* Controls whether query IDs are logged on the tserver level via {@link datawave.query.iterator.QueryLogIterator}.
*/
private boolean tserverLoggingActive = true;

/**
* Default constructor
*/
Expand Down Expand Up @@ -720,6 +725,7 @@ public ShardQueryConfiguration(ShardQueryConfiguration other) {
this.setUseTermCounts(other.getUseTermCounts());
this.setSortQueryBeforeGlobalIndex(other.isSortQueryBeforeGlobalIndex());
this.setSortQueryByCounts(other.isSortQueryByCounts());
this.setTserverLoggingActive(other.isTserverLoggingActive());
}

/**
Expand Down Expand Up @@ -2744,14 +2750,25 @@ public void setSortQueryByCounts(boolean sortQueryByCounts) {
this.sortQueryByCounts = sortQueryByCounts;
}

public boolean isTserverLoggingActive() {
return this.tserverLoggingActive;
}

public void setTserverLoggingActive(boolean tserverLoggingActive) {
this.tserverLoggingActive = tserverLoggingActive;
}

@Override
public boolean equals(Object o) {
if (this == o)
if (this == o) {
return true;
if (o == null || getClass() != o.getClass())
}
if (o == null || getClass() != o.getClass()) {
return false;
if (!super.equals(o))
}
if (!super.equals(o)) {
return false;
}
// @formatter:off
ShardQueryConfiguration that = (ShardQueryConfiguration) o;
return isTldQuery() == that.isTldQuery() &&
Expand Down Expand Up @@ -2951,7 +2968,8 @@ public boolean equals(Object o) {
getUseFieldCounts() == that.getUseFieldCounts() &&
getUseTermCounts() == that.getUseTermCounts() &&
isSortQueryBeforeGlobalIndex() == that.isSortQueryBeforeGlobalIndex() &&
isSortQueryByCounts() == that.isSortQueryByCounts();
isSortQueryByCounts() == that.isSortQueryByCounts() &&
isTserverLoggingActive() == that.isTserverLoggingActive();
// @formatter:on
}

Expand Down Expand Up @@ -3156,7 +3174,8 @@ public int hashCode() {
getUseFieldCounts(),
getUseTermCounts(),
isSortQueryBeforeGlobalIndex(),
isSortQueryByCounts());
isSortQueryByCounts(),
isTserverLoggingActive());
// @formatter:on
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
package datawave.query.iterator;

import static datawave.query.iterator.QueryOptions.QUERY_ID;

import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.apache.accumulo.core.data.ByteSequence;
import org.apache.accumulo.core.data.Key;
import org.apache.accumulo.core.data.Range;
import org.apache.accumulo.core.data.Value;
import org.apache.accumulo.core.iterators.IteratorEnvironment;
import org.apache.accumulo.core.iterators.OptionDescriber;
import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
import org.apache.log4j.Logger;

/**
* An iterator used to log the start and end of each method run by the {@link SortedKeyValueIterator} above it in the iterator stack. Logs the QueryID
* associated with each method. Logs are written on the TServer where the iterator is running
*/
public class QueryLogIterator implements SortedKeyValueIterator<Key,Value>, OptionDescriber {

private static final Logger log = Logger.getLogger(QueryLogIterator.class);
private static final String CLASS_NAME = QueryLogIterator.class.getSimpleName();

private String queryID;
private SortedKeyValueIterator<Key,Value> source;
private IteratorEnvironment env;

/**
* Default constructor
*/
public QueryLogIterator() {
// no-arg constructor
}

/**
* Class copy constructor
*/
public QueryLogIterator(QueryLogIterator other, IteratorEnvironment env) {
this.source = other.source.deepCopy(env);
this.env = other.env;
this.queryID = other.queryID;
}

/**
* Wraps the init() method of the iterator above it, logging the start/end of the method along with its query id.
*/
@Override
public void init(SortedKeyValueIterator<Key,Value> source, Map<String,String> options, IteratorEnvironment env) throws IOException {

try {
logStartOf("init()");
this.queryID = options.get(QUERY_ID);
this.source = source;
this.env = env;
} finally {
logEndOf("init()");
}
}

/**
* Logs the query id and {@link SortedKeyValueIterator} method name before the method is run.
*/
private void logStartOf(String methodName) {
if (log.isInfoEnabled()) {
log.info(CLASS_NAME + " " + methodName + " Started QueryID: " + this.queryID);
}
}

/**
* Logs the query id and {@link SortedKeyValueIterator} method name after the method is run.
*/
private void logEndOf(String methodName) {
if (log.isInfoEnabled()) {
log.info(CLASS_NAME + " " + methodName + " Ended QueryID: " + this.queryID);
}
}

/**
* Wraps the hasTop() method of the iterator above it, logging the start and end of the method along with its query id.
*/
@Override
public boolean hasTop() {
boolean result;

try {
logStartOf("hasTop()");
result = source.hasTop();
} finally {
logEndOf("hasTop()");
}
return result;
}

/**
* Wraps the next() method of the iterator above it, logging the start and end of the method along with its query id.
*/
@Override
public void next() throws IOException {
try {
logStartOf("next()");
source.next();
} finally {
logEndOf("next()");
}
}

/**
* Wraps the getTopKey() method of the iterator above it, logging the start and end of the method along with its query id.
*/
@Override
public Key getTopKey() {
Key k;
try {
logStartOf("getTopKey()");
k = source.getTopKey();
} finally {
logEndOf("getTopKey()");
}
return k;
}

/**
* Wraps the getTopValue() method of the iterator above it, logging the start and end of the method along with its query id.
*/
@Override
public Value getTopValue() {
Value v;
try {
logStartOf("getTopValue()");
v = source.getTopValue();
} finally {
logEndOf("getTopValue()");
}
return v;
}

/**
* Wraps the deepCopy() method of the iterator above it, logging the start and end of the method along with its query id.
*/
@Override
public SortedKeyValueIterator<Key,Value> deepCopy(IteratorEnvironment iteratorEnvironment) {

QueryLogIterator copy;

try {
logStartOf("deepCopy()");
copy = new QueryLogIterator(this, this.env);
} finally {
logEndOf("deepCopy()");
}
return copy;
}

/**
* Wraps the seek() method of the iterator above it, logging the start and end of the method along with its query id.
*/
@Override
public void seek(Range range, Collection<ByteSequence> collection, boolean b) throws IOException {

try {
logStartOf("seek()");
this.source.seek(range, collection, b);
} finally {
logEndOf("seek()");
}
}

/**
* Returns a {@link org.apache.accumulo.core.iterators.OptionDescriber.IteratorOptions} object containing a description of the iterator and an option for
* the QueryID.
*/
@Override
public IteratorOptions describeOptions() {
Map<String,String> options = new HashMap<>();
options.put(QUERY_ID, "The QueryID to be logged as methods are invoked");

return new IteratorOptions(getClass().getSimpleName(), "An iterator used to log the QueryID", options, null);
}

/**
* Returns true if the options provided contains the QueryID.
*/
@Override
public boolean validateOptions(Map<String,String> options) {
return options.containsKey(QUERY_ID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
Expand All @@ -39,12 +38,7 @@
import org.apache.log4j.Logger;
import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.CharMatcher;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
Expand Down Expand Up @@ -562,6 +556,7 @@ public void deepCopy(QueryOptions other) {

this.fieldCounts = other.fieldCounts;
this.termCounts = other.termCounts;

}

public String getQuery() {
Expand Down
Loading
Loading