-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Query Split Counting (#537)
Implement query split logging
- Loading branch information
1 parent
2ee4259
commit 871c326
Showing
18 changed files
with
393 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
fili-core/src/test/groovy/com/yahoo/bard/webservice/logging/blocks/BardQueryInfoSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2017 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.web.ErrorMessageFormat | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
class BardQueryInfoSpec extends Specification { | ||
BardQueryInfo bardQueryInfo | ||
|
||
def setup() { | ||
bardQueryInfo = BardQueryInfoUtils.initializeBardQueryInfo() | ||
} | ||
|
||
def cleanup() { | ||
BardQueryInfoUtils.resetBardQueryInfo() | ||
} | ||
|
||
def "getBardQueryInfo() returns registered BardQueryInfo instance"() { | ||
expect: | ||
BardQueryInfo.getBardQueryInfo() == bardQueryInfo | ||
} | ||
|
||
@Unroll | ||
def "incrementCountFor(#queryType) increments count of #queryType by 1"() { | ||
expect: "count for #queryType is 0" | ||
BardQueryInfo.QUERY_COUNTER.get(queryType).get() == 0 | ||
|
||
when: "calling incrementCountFor(#queryType)" | ||
BardQueryInfo.incrementCountFor(queryType) | ||
|
||
then: "count of #queryType is incremented by 1" | ||
BardQueryInfo.QUERY_COUNTER.get(queryType).get() == 1 | ||
|
||
where: | ||
queryType | _ | ||
BardQueryInfo.WEIGHT_CHECK | _ | ||
BardQueryInfo.FACT_QUERIES | _ | ||
BardQueryInfo.FACT_QUERY_CACHE_HIT | _ | ||
} | ||
|
||
def "incrementCountFor(String) throws IllegalArgumentException on non-existing query type"() { | ||
when: "BardQueryInfo is given an unknown query type" | ||
BardQueryInfo.incrementCountFor("nonExistingQueryType") | ||
|
||
then: "IllegalArgumentException is thrown with exception message" | ||
IllegalArgumentException illegalArgumentException = thrown() | ||
illegalArgumentException.message == ErrorMessageFormat.RESOURCE_RETRIEVAL_FAILURE.format("nonExistingQueryType") | ||
} | ||
|
||
def "incrementCount*() methods increment their corresponding query type counts by 1"() { | ||
expect: "all query counts are 0" | ||
BardQueryInfo.QUERY_COUNTER.get(BardQueryInfo.WEIGHT_CHECK).get() == 0 | ||
BardQueryInfo.QUERY_COUNTER.get(BardQueryInfo.FACT_QUERIES).get() == 0 | ||
BardQueryInfo.QUERY_COUNTER.get(BardQueryInfo.FACT_QUERY_CACHE_HIT).get() == 0 | ||
|
||
when: "calling incrementCount*() methods for all query types" | ||
BardQueryInfo.incrementCountWeightCheck() | ||
BardQueryInfo.incrementCountFactHits() | ||
BardQueryInfo.incrementCountCacheHits() | ||
|
||
then: "counts of all query types are incremented by 1" | ||
BardQueryInfo.QUERY_COUNTER.get(BardQueryInfo.WEIGHT_CHECK).get() == 1 | ||
BardQueryInfo.QUERY_COUNTER.get(BardQueryInfo.FACT_QUERIES).get() == 1 | ||
BardQueryInfo.QUERY_COUNTER.get(BardQueryInfo.FACT_QUERY_CACHE_HIT).get() == 1 | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
fili-core/src/test/groovy/com/yahoo/bard/webservice/logging/blocks/BardQueryInfoUtils.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2017 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.logging.RequestLog | ||
|
||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
class BardQueryInfoUtils { | ||
/** | ||
* Constructs and returns a testing BardQueryInfo instance without a query type. | ||
* | ||
* @return a testing BardQueryInfo instance without a query type | ||
*/ | ||
static BardQueryInfo initializeBardQueryInfo() { | ||
resetBardQueryInfo() | ||
BardQueryInfo bardQueryInfo = new BardQueryInfo(null) | ||
RequestLog.getId() // initialize RequestLog | ||
RequestLog.record(bardQueryInfo) | ||
return bardQueryInfo | ||
} | ||
|
||
/** | ||
* Resets counts of all query types in BardQueryInfo. | ||
*/ | ||
static void resetBardQueryInfo() { | ||
RequestLog.dump() | ||
|
||
// reset counts of all query types after each individual test | ||
for (Map.Entry<String, AtomicInteger> entry : BardQueryInfo.QUERY_COUNTER.entrySet()) { | ||
entry.value = new AtomicInteger() | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...-core/src/test/groovy/com/yahoo/bard/webservice/logging/blocks/DruidFilterInfoSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.