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

osd: support more dynamic perf query subkey types #25371

Merged
merged 3 commits into from Dec 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/mgr/BaseMgrModule.cc
Expand Up @@ -685,8 +685,13 @@ ceph_add_osd_perf_query(BaseMgrModule *self, PyObject *args)
static const std::string NAME_SUB_KEY_REGEX = "regex";
static const std::map<std::string, OSDPerfMetricSubKeyType> sub_key_types = {
{"client_id", OSDPerfMetricSubKeyType::CLIENT_ID},
{"client_address", OSDPerfMetricSubKeyType::CLIENT_ADDRESS},
{"pool_id", OSDPerfMetricSubKeyType::POOL_ID},
{"namespace", OSDPerfMetricSubKeyType::NAMESPACE},
{"osd_id", OSDPerfMetricSubKeyType::OSD_ID},
{"pg_id", OSDPerfMetricSubKeyType::PG_ID},
{"object_name", OSDPerfMetricSubKeyType::OBJECT_NAME},
{"snap_id", OSDPerfMetricSubKeyType::SNAP_ID},
};
static const std::map<std::string, PerformanceCounterType> counter_types = {
{"write_ops", PerformanceCounterType::WRITE_OPS},
Expand Down
15 changes: 15 additions & 0 deletions src/mgr/OSDPerfMetricTypes.cc
Expand Up @@ -11,12 +11,27 @@ std::ostream& operator<<(std::ostream& os,
case OSDPerfMetricSubKeyType::CLIENT_ID:
os << "client_id";
break;
case OSDPerfMetricSubKeyType::CLIENT_ADDRESS:
os << "client_address";
break;
case OSDPerfMetricSubKeyType::POOL_ID:
os << "pool_id";
break;
case OSDPerfMetricSubKeyType::NAMESPACE:
os << "namespace";
break;
case OSDPerfMetricSubKeyType::OSD_ID:
os << "osd_id";
break;
case OSDPerfMetricSubKeyType::PG_ID:
os << "pg_id";
break;
case OSDPerfMetricSubKeyType::OBJECT_NAME:
os << "object_name";
break;
case OSDPerfMetricSubKeyType::SNAP_ID:
os << "snap_id";
break;
default:
os << "unknown (" << static_cast<int>(d.type) << ")";
}
Expand Down
14 changes: 12 additions & 2 deletions src/mgr/OSDPerfMetricTypes.h
Expand Up @@ -14,8 +14,13 @@ typedef std::vector<OSDPerfMetricSubKey> OSDPerfMetricKey;

enum class OSDPerfMetricSubKeyType : uint8_t {
CLIENT_ID = 0,
POOL_ID = 1,
OBJECT_NAME = 2,
CLIENT_ADDRESS = 1,
POOL_ID = 2,
NAMESPACE = 3,
OSD_ID = 4,
PG_ID = 5,
OBJECT_NAME = 6,
SNAP_ID = 7,
};

struct OSDPerfMetricSubKeyDescriptor {
Expand All @@ -26,8 +31,13 @@ struct OSDPerfMetricSubKeyDescriptor {
bool is_supported() const {
switch (type) {
case OSDPerfMetricSubKeyType::CLIENT_ID:
case OSDPerfMetricSubKeyType::CLIENT_ADDRESS:
case OSDPerfMetricSubKeyType::POOL_ID:
case OSDPerfMetricSubKeyType::NAMESPACE:
case OSDPerfMetricSubKeyType::OSD_ID:
case OSDPerfMetricSubKeyType::PG_ID:
case OSDPerfMetricSubKeyType::OBJECT_NAME:
case OSDPerfMetricSubKeyType::SNAP_ID:
return true;
default:
return false;
Expand Down
24 changes: 20 additions & 4 deletions src/osd/DynamicPerfStats.h
Expand Up @@ -6,6 +6,7 @@

#include "messages/MOSDOp.h"
#include "mgr/OSDPerfMetricTypes.h"
#include "osd/OSD.h"
#include "osd/OpRequest.h"

class DynamicPerfStats {
Expand Down Expand Up @@ -52,8 +53,8 @@ class DynamicPerfStats {
return !data.empty();
}

void add(const OpRequest& op, uint64_t inb, uint64_t outb,
const utime_t &latency) {
void add(const OSDService *osd, const pg_info_t &pg_info, const OpRequest& op,
uint64_t inb, uint64_t outb, const utime_t &latency) {

auto update_counter_fnc =
[&op, inb, outb, &latency](const PerformanceCounterDescriptor &d,
Expand Down Expand Up @@ -101,8 +102,8 @@ class DynamicPerfStats {
};

auto get_subkey_fnc =
[&op](const OSDPerfMetricSubKeyDescriptor &d,
OSDPerfMetricSubKey *sub_key) {
[&osd, &pg_info, &op](const OSDPerfMetricSubKeyDescriptor &d,
OSDPerfMetricSubKey *sub_key) {
ceph_assert(d.is_supported());

auto m = static_cast<const MOSDOp*>(op.get_req());
Expand All @@ -111,12 +112,27 @@ class DynamicPerfStats {
case OSDPerfMetricSubKeyType::CLIENT_ID:
match_string = stringify(m->get_reqid().name);
break;
case OSDPerfMetricSubKeyType::CLIENT_ADDRESS:
match_string = stringify(m->get_connection()->get_peer_addr());
break;
case OSDPerfMetricSubKeyType::POOL_ID:
match_string = stringify(m->get_spg().pool());
break;
case OSDPerfMetricSubKeyType::NAMESPACE:
match_string = m->get_hobj().nspace;
break;
case OSDPerfMetricSubKeyType::OSD_ID:
match_string = stringify(osd->get_nodeid());
break;
case OSDPerfMetricSubKeyType::PG_ID:
match_string = stringify(pg_info.pgid);
break;
case OSDPerfMetricSubKeyType::OBJECT_NAME:
match_string = m->get_oid().name;
break;
case OSDPerfMetricSubKeyType::SNAP_ID:
match_string = stringify(m->get_snapid());
break;
default:
ceph_abort_msg("unknown counter type");
}
Expand Down
2 changes: 1 addition & 1 deletion src/osd/PrimaryLogPG.cc
Expand Up @@ -4141,7 +4141,7 @@ void PrimaryLogPG::log_op_stats(const OpRequest& op,
<< " lat " << latency << dendl;

if (m_dynamic_perf_stats.is_enabled()) {
m_dynamic_perf_stats.add(op, inb, outb, latency);
m_dynamic_perf_stats.add(osd, info, op, inb, outb, latency);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/pybind/mgr/mgr_module.py
Expand Up @@ -969,7 +969,9 @@ def add_osd_perf_query(self, query):
],
}

Valid subkey types: 'client_id', 'pool_id', 'object_name'
Valid subkey types:
'client_id', 'client_address', 'pool_id', 'namespace', 'osd_id',
'pg_id', 'object_name', 'snap_id'
Valid performance counter types:
'write_ops', 'read_ops', 'write_bytes', 'read_bytes',
'write_latency', 'read_latency'
Expand Down
27 changes: 23 additions & 4 deletions src/pybind/mgr/osd_perf_query/module.py
Expand Up @@ -23,7 +23,8 @@ class OSDPerfQuery(MgrModule):
COMMANDS = [
{
"cmd": "osd perf query add "
"name=query,type=CephChoices,strings=client_id|rbd_image_id",
"name=query,type=CephChoices,"
"strings=client_id|rbd_image_id|all_subkeys",
"desc": "add osd perf query",
"perm": "w"
},
Expand Down Expand Up @@ -62,14 +63,32 @@ class OSDPerfQuery(MgrModule):
],
}

ALL_SUBKEYS_QUERY = {
'key_descriptor': [
{'type': 'client_id', 'regex': '^.*$'},
{'type': 'client_address', 'regex': '^.*$'},
{'type': 'pool_id', 'regex': '^.*$'},
{'type': 'namespace', 'regex': '^.*$'},
{'type': 'osd_id', 'regex': '^.*$'},
{'type': 'pg_id', 'regex': '^.*$'},
{'type': 'object_name', 'regex': '^.*$'},
{'type': 'snap_id', 'regex': '^.*$'},
],
'performance_counter_descriptors': [
'write_ops', 'read_ops',
],
}

queries = {}

def handle_command(self, inbuf, cmd):
if cmd['prefix'] == "osd perf query add":
if cmd['query'] == 'rbd_image_id':
query = self.RBD_IMAGE_ID_QUERY
else:
elif cmd['query'] == 'rbd_image_id':
query = self.CLIENT_ID_QUERY
else:
query = self.ALL_SUBKEYS_QUERY
query_id = self.add_osd_perf_query(query)
if query_id is None:
return -errno.EINVAL, "", "Invalid query"
Expand All @@ -94,7 +113,7 @@ def handle_command(self, inbuf, cmd):
if query == self.RBD_IMAGE_ID_QUERY:
column_names = ["pool_id", "rbd image_id"]
else:
column_names = ["client_id"]
column_names = [sk['type'] for sk in query['key_descriptor']]
for d in descriptors:
desc = d
if d in ['write_bytes', 'read_bytes']:
Expand All @@ -109,7 +128,7 @@ def handle_command(self, inbuf, cmd):
if query == self.RBD_IMAGE_ID_QUERY:
row = [c['k'][0][0], c['k'][1][1]]
else:
row = [c['k'][0][0]]
row = [sk[0] for sk in c['k']]
counters = c['c']
for i in range(len(descriptors)):
if descriptors[i] in ['write_bytes', 'read_bytes']:
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rbd/action/Bench.cc
Expand Up @@ -462,8 +462,8 @@ int bench_execute(const po::variables_map &vm, io_type_t bench_io_type) {
librados::Rados rados;
librados::IoCtx io_ctx;
librbd::Image image;
r = utils::init_and_open_image(pool_name, namespace_name, image_name, "", "",
false, &rados, &io_ctx, &image);
r = utils::init_and_open_image(pool_name, namespace_name, image_name, "",
snap_name, false, &rados, &io_ctx, &image);
if (r < 0) {
return r;
}
Expand Down