Skip to content

Commit

Permalink
KUDU-1684 - [python] Add Scan Resource Metrics Capabilities
Browse files Browse the repository at this point in the history
Currently, the python client doesn't expose scanner resource metrics.
This patch enables this ability and includes tests.

Change-Id: Ib6c4057bd2644e46bdbf8bae0d4a768306e2dbd9
Reviewed-on: http://gerrit.cloudera.org:8080/4675
Tested-by: Kudu Jenkins
Reviewed-by: Todd Lipcon <[email protected]>
  • Loading branch information
jtbirdsell authored and toddlipcon committed Oct 21, 2016
1 parent 2426ef3 commit 4b5425a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
17 changes: 17 additions & 0 deletions python/kudu/client.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from libcpp.string cimport string
from libcpp cimport bool as c_bool
from libcpp.map cimport map

cimport cpython
from cython.operator cimport dereference as deref
Expand Down Expand Up @@ -1453,6 +1454,22 @@ cdef class Scanner:
result.schema = schema
return result

def get_resource_metrics(self):
"""
Return the cumulative resource metrics since the scan was started.
Returns
-------
metrics : Dictionary
"""
_map = self.scanner.GetResourceMetrics().Get()

# Convert map to python dictionary
result = {}
for it in _map:
result[frombytes(it.first)] = it.second
return result

def open(self):
"""
Returns a reference to itself to facilitate chaining
Expand Down
10 changes: 10 additions & 0 deletions python/kudu/libkudu_client.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ from libc.stdint cimport *
from libcpp cimport bool as c_bool
from libcpp.string cimport string
from libcpp.vector cimport vector
from libcpp.map cimport map

# This must be included for cerr and other things to work
cdef extern from "<iostream>":
Expand Down Expand Up @@ -631,6 +632,7 @@ cdef extern from "kudu/client/client.h" namespace "kudu::client" nogil:
Status AddExclusiveUpperBound(const KuduPartialRow& key)

KuduSchema GetProjectionSchema()
const ResourceMetrics& GetResourceMetrics()
string ToString()

cdef cppclass KuduScanToken:
Expand Down Expand Up @@ -681,3 +683,11 @@ cdef extern from "kudu/client/client.h" namespace "kudu::client" nogil:
KuduWriteOperation* release_failed_op()

c_bool was_possibly_successful()

cdef extern from "kudu/client/resource_metrics.h" namespace "kudu::client" nogil:

cdef cppclass ResourceMetrics:
ResourceMetrics()

map[string, int64_t] Get()
int64_t GetMetric(const string& name)
15 changes: 15 additions & 0 deletions python/kudu/tests/test_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,21 @@ def test_read_mode(self):
# Avoid tight looping
time.sleep(0.05)

def test_resource_metrics(self):
"""
Test getting the resource metrics after scanning.
"""

# Build scanner and read through all batches and retrieve metrics.
scanner = self.table.scanner()
scanner.set_fault_tolerant().open()
scanner.read_all_tuples()
metrics = scanner.get_resource_metrics()

# Confirm that the scanner returned cache hit and miss values.
self.assertTrue('cfile_cache_hit_bytes' in metrics)
self.assertTrue('cfile_cache_miss_bytes' in metrics)

def verify_pred_type_scans(self, preds, row_indexes, count_only=False):
# Using the incoming list of predicates, verify that the row returned
# matches the inserted tuple at the row indexes specified in a
Expand Down

0 comments on commit 4b5425a

Please sign in to comment.