Skip to content

Commit

Permalink
add search latency metrics for grafana
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Liu <[email protected]>
  • Loading branch information
weiliu1031 committed Aug 31, 2023
1 parent 4176a66 commit 73452cf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion include/knowhere/prometheus_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ DECLARE_PROMETHEUS_COUNTER(knowhere_build_count);
DECLARE_PROMETHEUS_COUNTER(knowhere_search_count);
DECLARE_PROMETHEUS_COUNTER(knowhere_range_search_count);
DECLARE_PROMETHEUS_HISTOGRAM(knowhere_search_topk);

DECLARE_PROMETHEUS_HISTOGRAM(knowhere_search_latency);
DECLARE_PROMETHEUS_HISTOGRAM(knowhere_range_search_latency);
} // namespace knowhere
20 changes: 17 additions & 3 deletions src/common/index.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// or implied. See the License for the specific language governing permissions and limitations under the License.

#include "knowhere/index.h"

#include "knowhere/comp/time_recorder.h"
#include "knowhere/dataset.h"
#include "knowhere/expected.h"
#include "knowhere/log.h"
Expand Down Expand Up @@ -75,10 +75,17 @@ Index<T>::Search(const DataSet& dataset, const Json& json, const BitsetView& bit
}

#ifdef NOT_COMPILE_FOR_SWIG
TimeRecorder rc("Search");
auto res = this->node->Search(dataset, *cfg, bitset);
auto span = rc.ElapseFromBegin("done");
span *= 0.001; // convert to ms
knowhere_search_latency.Observe(span);
knowhere_search_count.Increment();
knowhere_search_topk.Observe(cfg->k.value());
#else
auto res = this->node->Search(dataset, *cfg, bitset);
#endif
return this->node->Search(dataset, *cfg, bitset);
return res;
}

template <typename T>
Expand All @@ -96,9 +103,16 @@ Index<T>::RangeSearch(const DataSet& dataset, const Json& json, const BitsetView
}

#ifdef NOT_COMPILE_FOR_SWIG
TimeRecorder rc("Range Search");
auto res = this->node->RangeSearch(dataset, *cfg, bitset);
auto span = rc.ElapseFromBegin("done");
span *= 0.001; // convert to ms
knowhere_range_search_latency.Observe(span);
knowhere_range_search_count.Increment();
#else
auto res = this->node->RangeSearch(dataset, *cfg, bitset);
#endif
return this->node->RangeSearch(dataset, *cfg, bitset);
return res;
}

template <typename T>
Expand Down
2 changes: 2 additions & 0 deletions src/common/prometheus_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ DEFINE_PROMETHEUS_COUNTER(knowhere_build_count, "knowhere index build count")
DEFINE_PROMETHEUS_COUNTER(knowhere_search_count, "knowhere search count")
DEFINE_PROMETHEUS_COUNTER(knowhere_range_search_count, "knowhere range search count")
DEFINE_PROMETHEUS_HISTOGRAM(knowhere_search_topk, "knowhere search topk")
DEFINE_PROMETHEUS_HISTOGRAM(knowhere_search_latency, "search latency in knowhere (ms)")
DEFINE_PROMETHEUS_HISTOGRAM(knowhere_range_search_latency, "range search latency in knowhere (ms)")

} // namespace knowhere

0 comments on commit 73452cf

Please sign in to comment.