forked from opendistro-for-elasticsearch/k-NN
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stats to track knn request counts (opendistro-for-elasticsearch#89)
- Loading branch information
1 parent
3fc88f3
commit abef1bd
Showing
10 changed files
with
269 additions
and
6 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
67 changes: 67 additions & 0 deletions
67
src/main/java/com/amazon/opendistroforelasticsearch/knn/plugin/stats/KNNCounter.java
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,67 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.knn.plugin.stats; | ||
|
||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
/** | ||
* Contains a map of counters to keep track of different values | ||
*/ | ||
public enum KNNCounter { | ||
GRAPH_QUERY_ERRORS("graph_query_errors"), | ||
GRAPH_QUERY_REQUESTS("graph_query_requests"), | ||
GRAPH_INDEX_ERRORS("graph_index_errors"), | ||
GRAPH_INDEX_REQUESTS("graph_index_requests"), | ||
KNN_QUERY_REQUESTS("knn_query_requests"); | ||
|
||
private String name; | ||
private AtomicLong count; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param name name of the counter | ||
*/ | ||
KNNCounter(String name) { | ||
this.name = name; | ||
this.count = new AtomicLong(0); | ||
} | ||
|
||
/** | ||
* Get name of counter | ||
* | ||
* @return name | ||
*/ | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
/** | ||
* Get the value of count | ||
* | ||
* @return count | ||
*/ | ||
public Long getCount() { | ||
return count.get(); | ||
} | ||
|
||
/** | ||
* Increment the value of a counter | ||
*/ | ||
public void increment() { | ||
count.getAndIncrement(); | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
.../com/amazon/opendistroforelasticsearch/knn/plugin/stats/suppliers/KNNCounterSupplier.java
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,41 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.knn.plugin.stats.suppliers; | ||
|
||
import com.amazon.opendistroforelasticsearch.knn.plugin.stats.KNNCounter; | ||
|
||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Supplier for stats that need to keep count | ||
*/ | ||
public class KNNCounterSupplier implements Supplier<Long> { | ||
private KNNCounter knnCounter; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param knnCounter KNN Plugin Counter | ||
*/ | ||
public KNNCounterSupplier(KNNCounter knnCounter) { | ||
this.knnCounter = knnCounter; | ||
} | ||
|
||
@Override | ||
public Long get() { | ||
return knnCounter.getCount(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/test/java/com/amazon/opendistroforelasticsearch/knn/plugin/stats/KNNCounterTests.java
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,33 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.knn.plugin.stats; | ||
|
||
import org.elasticsearch.test.ESTestCase; | ||
|
||
public class KNNCounterTests extends ESTestCase { | ||
public void testGetName() { | ||
assertEquals(StatNames.GRAPH_QUERY_ERRORS.getName(), KNNCounter.GRAPH_QUERY_ERRORS.getName()); | ||
} | ||
|
||
public void testCount() { | ||
assertEquals((Long) 0L, KNNCounter.GRAPH_QUERY_ERRORS.getCount()); | ||
|
||
for (long i = 0; i < 100; i++) { | ||
KNNCounter.GRAPH_QUERY_ERRORS.increment(); | ||
assertEquals((Long) (i+1), KNNCounter.GRAPH_QUERY_ERRORS.getCount()); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...amazon/opendistroforelasticsearch/knn/plugin/stats/suppliers/KNNCounterSupplierTests.java
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,28 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package com.amazon.opendistroforelasticsearch.knn.plugin.stats.suppliers; | ||
|
||
import com.amazon.opendistroforelasticsearch.knn.plugin.stats.KNNCounter; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
public class KNNCounterSupplierTests extends ESTestCase { | ||
public void testNormal() { | ||
KNNCounterSupplier knnCounterSupplier = new KNNCounterSupplier(KNNCounter.GRAPH_QUERY_REQUESTS); | ||
assertEquals((Long) 0L, knnCounterSupplier.get()); | ||
KNNCounter.GRAPH_QUERY_REQUESTS.increment(); | ||
assertEquals((Long) 1L, knnCounterSupplier.get()); | ||
} | ||
} |