]> git.proxmox.com Git - ceph.git/blame - ceph/src/test/perf_counters.cc
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / test / perf_counters.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2011 New Dream Network
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14#include "include/int_types.h"
15#include "include/types.h" // FIXME: ordering shouldn't be important, but right
16 // now, this include has to come before the others.
17
18
1e59de90 19#include "common/perf_counters_key.h"
11fdf7f2 20#include "common/perf_counters_collection.h"
7c673cae
FG
21#include "common/admin_socket_client.h"
22#include "common/ceph_context.h"
23#include "common/config.h"
24#include "common/errno.h"
25#include "common/safe_io.h"
26
27#include "common/code_environment.h"
28#include "global/global_context.h"
29#include "global/global_init.h"
30#include "include/msgr.h" // for CEPH_ENTITY_TYPE_CLIENT
31#include "gtest/gtest.h"
32
33#include <errno.h>
34#include <fcntl.h>
35#include <map>
36#include <poll.h>
37#include <sstream>
38#include <stdint.h>
39#include <string.h>
40#include <string>
41#include <sys/socket.h>
42#include <sys/types.h>
43#include <sys/un.h>
44#include <time.h>
45#include <unistd.h>
11fdf7f2 46#include <thread>
7c673cae
FG
47
48#include "common/common_init.h"
49
20effc67
TL
50using namespace std;
51
7c673cae 52int main(int argc, char **argv) {
11fdf7f2
TL
53 map<string,string> defaults = {
54 { "admin_socket", get_rand_socket_path() }
55 };
7c673cae 56 std::vector<const char*> args;
11fdf7f2 57 auto cct = global_init(&defaults, args, CEPH_ENTITY_TYPE_CLIENT,
7c673cae 58 CODE_ENVIRONMENT_UTILITY,
11fdf7f2
TL
59 CINIT_FLAG_NO_DEFAULT_CONFIG_FILE|
60 CINIT_FLAG_NO_CCT_PERF_COUNTERS);
7c673cae
FG
61 common_init_finish(g_ceph_context);
62 ::testing::InitGoogleTest(&argc, argv);
63 return RUN_ALL_TESTS();
64}
65
66TEST(PerfCounters, SimpleTest) {
67 AdminSocketClient client(get_rand_socket_path());
68 std::string message;
69 ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf dump\" }", &message));
70 ASSERT_EQ("{}\n", message);
71}
72
73enum {
74 TEST_PERFCOUNTERS1_ELEMENT_FIRST = 200,
75 TEST_PERFCOUNTERS1_ELEMENT_1,
76 TEST_PERFCOUNTERS1_ELEMENT_2,
77 TEST_PERFCOUNTERS1_ELEMENT_3,
78 TEST_PERFCOUNTERS1_ELEMENT_LAST,
79};
80
81std::string sd(const char *c)
82{
83 std::string ret(c);
84 std::string::size_type sz = ret.size();
85 for (std::string::size_type i = 0; i < sz; ++i) {
86 if (ret[i] == '\'') {
87 ret[i] = '\"';
88 }
89 }
90 return ret;
91}
92
93static PerfCounters* setup_test_perfcounters1(CephContext *cct)
94{
95 PerfCountersBuilder bld(cct, "test_perfcounter_1",
96 TEST_PERFCOUNTERS1_ELEMENT_FIRST, TEST_PERFCOUNTERS1_ELEMENT_LAST);
97 bld.add_u64(TEST_PERFCOUNTERS1_ELEMENT_1, "element1");
98 bld.add_time(TEST_PERFCOUNTERS1_ELEMENT_2, "element2");
99 bld.add_time_avg(TEST_PERFCOUNTERS1_ELEMENT_3, "element3");
100 return bld.create_perf_counters();
101}
102
103TEST(PerfCounters, SinglePerfCounters) {
104 PerfCountersCollection *coll = g_ceph_context->get_perfcounters_collection();
105 PerfCounters* fake_pf = setup_test_perfcounters1(g_ceph_context);
106 coll->add(fake_pf);
107 AdminSocketClient client(get_rand_socket_path());
108 std::string msg;
109 ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf dump\", \"format\": \"json\" }", &msg));
110 ASSERT_EQ(sd("{\"test_perfcounter_1\":{\"element1\":0,"
31f18b77 111 "\"element2\":0.000000000,\"element3\":{\"avgcount\":0,\"sum\":0.000000000,\"avgtime\":0.000000000}}}"), msg);
7c673cae
FG
112 fake_pf->inc(TEST_PERFCOUNTERS1_ELEMENT_1);
113 fake_pf->tset(TEST_PERFCOUNTERS1_ELEMENT_2, utime_t(0, 500000000));
114 fake_pf->tinc(TEST_PERFCOUNTERS1_ELEMENT_3, utime_t(100, 0));
115 ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf dump\", \"format\": \"json\" }", &msg));
116 ASSERT_EQ(sd("{\"test_perfcounter_1\":{\"element1\":1,"
31f18b77 117 "\"element2\":0.500000000,\"element3\":{\"avgcount\":1,\"sum\":100.000000000,\"avgtime\":100.000000000}}}"), msg);
7c673cae 118 fake_pf->tinc(TEST_PERFCOUNTERS1_ELEMENT_3, utime_t());
31f18b77 119 fake_pf->tinc(TEST_PERFCOUNTERS1_ELEMENT_3, utime_t(20,0));
7c673cae
FG
120 ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf dump\", \"format\": \"json\" }", &msg));
121 ASSERT_EQ(sd("{\"test_perfcounter_1\":{\"element1\":1,\"element2\":0.500000000,"
31f18b77 122 "\"element3\":{\"avgcount\":3,\"sum\":120.000000000,\"avgtime\":40.000000000}}}"), msg);
7c673cae
FG
123
124 fake_pf->reset();
125 msg.clear();
126 ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf dump\", \"format\": \"json\" }", &msg));
127 ASSERT_EQ(sd("{\"test_perfcounter_1\":{\"element1\":1,"
31f18b77 128 "\"element2\":0.000000000,\"element3\":{\"avgcount\":0,\"sum\":0.000000000,\"avgtime\":0.000000000}}}"), msg);
7c673cae
FG
129
130}
131
132enum {
133 TEST_PERFCOUNTERS2_ELEMENT_FIRST = 400,
134 TEST_PERFCOUNTERS2_ELEMENT_FOO,
135 TEST_PERFCOUNTERS2_ELEMENT_BAR,
136 TEST_PERFCOUNTERS2_ELEMENT_LAST,
137};
138
139static PerfCounters* setup_test_perfcounter2(CephContext *cct)
140{
141 PerfCountersBuilder bld(cct, "test_perfcounter_2",
142 TEST_PERFCOUNTERS2_ELEMENT_FIRST, TEST_PERFCOUNTERS2_ELEMENT_LAST);
143 bld.add_u64(TEST_PERFCOUNTERS2_ELEMENT_FOO, "foo");
144 bld.add_time(TEST_PERFCOUNTERS2_ELEMENT_BAR, "bar");
145 return bld.create_perf_counters();
146}
147
148TEST(PerfCounters, MultiplePerfCounters) {
149 PerfCountersCollection *coll = g_ceph_context->get_perfcounters_collection();
150 coll->clear();
151 PerfCounters* fake_pf1 = setup_test_perfcounters1(g_ceph_context);
152 PerfCounters* fake_pf2 = setup_test_perfcounter2(g_ceph_context);
153 coll->add(fake_pf1);
154 coll->add(fake_pf2);
155 AdminSocketClient client(get_rand_socket_path());
156 std::string msg;
157
158 ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf dump\", \"format\": \"json\" }", &msg));
159 ASSERT_EQ(sd("{\"test_perfcounter_1\":{\"element1\":0,\"element2\":0.000000000,\"element3\":"
31f18b77 160 "{\"avgcount\":0,\"sum\":0.000000000,\"avgtime\":0.000000000}},\"test_perfcounter_2\":{\"foo\":0,\"bar\":0.000000000}}"), msg);
7c673cae
FG
161
162 fake_pf1->inc(TEST_PERFCOUNTERS1_ELEMENT_1);
163 fake_pf1->inc(TEST_PERFCOUNTERS1_ELEMENT_1, 5);
164 ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf dump\", \"format\": \"json\" }", &msg));
165 ASSERT_EQ(sd("{\"test_perfcounter_1\":{\"element1\":6,\"element2\":0.000000000,\"element3\":"
31f18b77 166 "{\"avgcount\":0,\"sum\":0.000000000,\"avgtime\":0.000000000}},\"test_perfcounter_2\":{\"foo\":0,\"bar\":0.000000000}}"), msg);
7c673cae
FG
167
168 coll->reset(string("test_perfcounter_1"));
169 ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf dump\", \"format\": \"json\" }", &msg));
170 ASSERT_EQ(sd("{\"test_perfcounter_1\":{\"element1\":6,\"element2\":0.000000000,\"element3\":"
31f18b77 171 "{\"avgcount\":0,\"sum\":0.000000000,\"avgtime\":0.000000000}},\"test_perfcounter_2\":{\"foo\":0,\"bar\":0.000000000}}"), msg);
7c673cae
FG
172
173 fake_pf1->inc(TEST_PERFCOUNTERS1_ELEMENT_1);
174 fake_pf1->inc(TEST_PERFCOUNTERS1_ELEMENT_1, 6);
175 ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf dump\", \"format\": \"json\" }", &msg));
176 ASSERT_EQ(sd("{\"test_perfcounter_1\":{\"element1\":13,\"element2\":0.000000000,\"element3\":"
31f18b77 177 "{\"avgcount\":0,\"sum\":0.000000000,\"avgtime\":0.000000000}},\"test_perfcounter_2\":{\"foo\":0,\"bar\":0.000000000}}"), msg);
7c673cae
FG
178
179 coll->reset(string("all"));
180 msg.clear();
181 ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf dump\", \"format\": \"json\" }", &msg));
182 ASSERT_EQ(sd("{\"test_perfcounter_1\":{\"element1\":13,\"element2\":0.000000000,\"element3\":"
31f18b77 183 "{\"avgcount\":0,\"sum\":0.000000000,\"avgtime\":0.000000000}},\"test_perfcounter_2\":{\"foo\":0,\"bar\":0.000000000}}"), msg);
7c673cae
FG
184
185 coll->remove(fake_pf2);
1e59de90 186 delete fake_pf2;
7c673cae
FG
187 ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf dump\", \"format\": \"json\" }", &msg));
188 ASSERT_EQ(sd("{\"test_perfcounter_1\":{\"element1\":13,\"element2\":0.000000000,"
31f18b77 189 "\"element3\":{\"avgcount\":0,\"sum\":0.000000000,\"avgtime\":0.000000000}}}"), msg);
7c673cae 190 ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf schema\", \"format\": \"json\" }", &msg));
1adf2230 191 ASSERT_EQ(sd("{\"test_perfcounter_1\":{\"element1\":{\"type\":2,\"metric_type\":\"gauge\",\"value_type\":\"integer\",\"description\":\"\",\"nick\":\"\",\"priority\":0,\"units\":\"none\"},\"element2\":{\"type\":1,\"metric_type\":\"gauge\",\"value_type\":\"real\",\"description\":\"\",\"nick\":\"\",\"priority\":0,\"units\":\"none\"},\"element3\":{\"type\":5,\"metric_type\":\"gauge\",\"value_type\":\"real-integer-pair\",\"description\":\"\",\"nick\":\"\",\"priority\":0,\"units\":\"none\"}}}"), msg);
7c673cae
FG
192 coll->clear();
193 ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf dump\", \"format\": \"json\" }", &msg));
194 ASSERT_EQ("{}", msg);
195}
196
7c673cae
FG
197TEST(PerfCounters, ResetPerfCounters) {
198 AdminSocketClient client(get_rand_socket_path());
199 std::string msg;
200 PerfCountersCollection *coll = g_ceph_context->get_perfcounters_collection();
201 coll->clear();
202 PerfCounters* fake_pf1 = setup_test_perfcounters1(g_ceph_context);
203 coll->add(fake_pf1);
204
205 ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf reset\", \"var\": \"all\", \"format\": \"json\" }", &msg));
206 ASSERT_EQ(sd("{\"success\":\"perf reset all\"}"), msg);
207
208 ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf reset\", \"var\": \"test_perfcounter_1\", \"format\": \"json\" }", &msg));
209 ASSERT_EQ(sd("{\"success\":\"perf reset test_perfcounter_1\"}"), msg);
210
211 coll->clear();
212 ASSERT_EQ("", client.do_request("{ \"prefix\": \"perf reset\", \"var\": \"test_perfcounter_1\", \"format\": \"json\" }", &msg));
213 ASSERT_EQ(sd("{\"error\":\"Not find: test_perfcounter_1\"}"), msg);
214}
11fdf7f2
TL
215
216enum {
217 TEST_PERFCOUNTERS3_ELEMENT_FIRST = 400,
218 TEST_PERFCOUNTERS3_ELEMENT_READ,
219 TEST_PERFCOUNTERS3_ELEMENT_LAST,
220};
221
222static std::shared_ptr<PerfCounters> setup_test_perfcounter3(CephContext* cct) {
223 PerfCountersBuilder bld(cct, "test_percounter_3",
224 TEST_PERFCOUNTERS3_ELEMENT_FIRST, TEST_PERFCOUNTERS3_ELEMENT_LAST);
225 bld.add_time_avg(TEST_PERFCOUNTERS3_ELEMENT_READ, "read_avg");
226 std::shared_ptr<PerfCounters> p(bld.create_perf_counters());
227 return p;
228}
229
230static void counters_inc_test(std::shared_ptr<PerfCounters> fake_pf) {
231 int i = 100000;
232 utime_t t;
233
234 // set to 1 nsec
235 t.set_from_double(0.000000001);
236 while (i--) {
237 // increase by one, make sure data.u64 equal to data.avgcount
238 fake_pf->tinc(TEST_PERFCOUNTERS3_ELEMENT_READ, t);
239 }
240}
241
242static void counters_readavg_test(std::shared_ptr<PerfCounters> fake_pf) {
243 int i = 100000;
244
245 while (i--) {
246 std::pair<uint64_t, uint64_t> dat = fake_pf->get_tavg_ns(TEST_PERFCOUNTERS3_ELEMENT_READ);
247 // sum and count should be identical as we increment TEST_PERCOUNTERS_ELEMENT_READ by 1 nsec eveytime
248 ASSERT_EQ(dat.first, dat.second);
249 }
250}
251
252TEST(PerfCounters, read_avg) {
253 std::shared_ptr<PerfCounters> fake_pf = setup_test_perfcounter3(g_ceph_context);
254
255 std::thread t1(counters_inc_test, fake_pf);
256 std::thread t2(counters_readavg_test, fake_pf);
257 t2.join();
258 t1.join();
20effc67 259}
1e59de90
TL
260
261static PerfCounters* setup_test_perfcounter4(std::string name, CephContext *cct)
262{
263 PerfCountersBuilder bld(cct, name,
264 TEST_PERFCOUNTERS2_ELEMENT_FIRST, TEST_PERFCOUNTERS2_ELEMENT_LAST);
265 bld.add_u64(TEST_PERFCOUNTERS2_ELEMENT_FOO, "foo");
266 bld.add_time(TEST_PERFCOUNTERS2_ELEMENT_BAR, "bar");
267
268 PerfCounters* counters = bld.create_perf_counters();
269 cct->get_perfcounters_collection()->add(counters);
270 return counters;
271}
272
273TEST(PerfCounters, TestLabeledCountersOnly) {
274 constexpr std::string_view empty_dump_format_raw = R"({}
275)";
276 std::string counter_key1 = ceph::perf_counters::key_create("name1", {{"label1", "val1"}});
277 std::string counter_key2 = ceph::perf_counters::key_create("name2", {{"label2", "val2"}});
278
279 PerfCounters* counters1 = setup_test_perfcounter4(counter_key1, g_ceph_context);
280 PerfCounters* counters2 = setup_test_perfcounter4(counter_key2, g_ceph_context);
281
282 counters1->inc(TEST_PERFCOUNTERS2_ELEMENT_FOO, 3);
283 counters1->dec(TEST_PERFCOUNTERS2_ELEMENT_FOO, 1);
284 counters2->set(TEST_PERFCOUNTERS2_ELEMENT_FOO, 4);
285
286 AdminSocketClient client(get_rand_socket_path());
287 std::string message;
288 ASSERT_EQ("", client.do_request(R"({ "prefix": "counter dump", "format": "raw" })", &message));
289 ASSERT_EQ(R"({
290 "name1": {
291 "labels": {
292 "label1": "val1"
293 },
294 "counters": {
295 "foo": 2,
296 "bar": 0.000000000
297 }
298 },
299 "name2": {
300 "labels": {
301 "label2": "val2"
302 },
303 "counters": {
304 "foo": 4,
305 "bar": 0.000000000
306 }
307 }
308}
309)", message);
310
311 // make sure labeled counters are not in normal perf dump
312 ASSERT_EQ("", client.do_request(R"({ "prefix": "perf dump", "format": "raw" })", &message));
313 ASSERT_EQ(empty_dump_format_raw, message);
314
315 ASSERT_EQ("", client.do_request(R"({ "prefix": "counter schema", "format": "raw" })", &message));
316 ASSERT_EQ(R"({
317 "name1": {
318 "labels": {
319 "label1": "val1"
320 },
321 "counters": {
322 "foo": {
323 "type": 2,
324 "metric_type": "gauge",
325 "value_type": "integer",
326 "description": "",
327 "nick": "",
328 "priority": 0,
329 "units": "none"
330 },
331 "bar": {
332 "type": 1,
333 "metric_type": "gauge",
334 "value_type": "real",
335 "description": "",
336 "nick": "",
337 "priority": 0,
338 "units": "none"
339 }
340 }
341 },
342 "name2": {
343 "labels": {
344 "label2": "val2"
345 },
346 "counters": {
347 "foo": {
348 "type": 2,
349 "metric_type": "gauge",
350 "value_type": "integer",
351 "description": "",
352 "nick": "",
353 "priority": 0,
354 "units": "none"
355 },
356 "bar": {
357 "type": 1,
358 "metric_type": "gauge",
359 "value_type": "real",
360 "description": "",
361 "nick": "",
362 "priority": 0,
363 "units": "none"
364 }
365 }
366 }
367}
368)", message);
369
370 // make sure labeled counters are not in normal perf schema
371 ASSERT_EQ("", client.do_request(R"({ "prefix": "perf schema", "format": "raw" })", &message));
372 ASSERT_EQ(empty_dump_format_raw, message);
373
374 g_ceph_context->get_perfcounters_collection()->clear();
375}
376
377TEST(PerfCounters, TestLabelStrings) {
378 AdminSocketClient client(get_rand_socket_path());
379 std::string message;
380
381 // test empty val in a label pair will get the label pair added but empty key will not
382 std::string counter_key1 = ceph::perf_counters::key_create("good_ctrs", {{"label3", "val4"}, {"label1", ""}});
383 PerfCounters* counters1 = setup_test_perfcounter4(counter_key1, g_ceph_context);
384
385 std::string counter_key2 = ceph::perf_counters::key_create("bad_ctrs", {{"", "val4"}, {"label1", "val1"}});
386 PerfCounters* counters2 = setup_test_perfcounter4(counter_key2, g_ceph_context);
387
388 counters1->set(TEST_PERFCOUNTERS2_ELEMENT_FOO, 2);
389 counters2->set(TEST_PERFCOUNTERS2_ELEMENT_FOO, 4);
390
391 // test empty keys in each of the label pairs will get only the labels section added
392 std::string counter_key3 = ceph::perf_counters::key_create("bad_ctrs2", {{"", "val2"}, {"", "val33"}});
393 PerfCounters* counters3 = setup_test_perfcounter4(counter_key3, g_ceph_context);
394 counters3->set(TEST_PERFCOUNTERS2_ELEMENT_FOO, 6);
395
396 // a key with a somehow odd number of entries after the the key name will omit final unfinished label pair
397 std::string counter_key4 = "too_many_delimiters";
398 counter_key4 += '\0';
399 counter_key4 += "label1";
400 counter_key4 += '\0';
401 counter_key4 += "val1";
402 counter_key4 += '\0';
403 counter_key4 += "label2";
404 counter_key4 += '\0';
405 PerfCounters* counters4 = setup_test_perfcounter4(counter_key4, g_ceph_context);
406 counters4->set(TEST_PERFCOUNTERS2_ELEMENT_FOO, 8);
407
408 // test unlabeled perf counters are in the counter dump with labels and counters sections
409 std::string counter_key5 = "only_key";
410 PerfCounters* no_label_counters = setup_test_perfcounter4(counter_key5, g_ceph_context);
411 no_label_counters->set(TEST_PERFCOUNTERS2_ELEMENT_FOO, 4);
412
413 ASSERT_EQ("", client.do_request(R"({ "prefix": "counter dump", "format": "raw" })", &message));
414 ASSERT_EQ(R"({
415 "bad_ctrs": {
416 "labels": {
417 "label1": "val1"
418 },
419 "counters": {
420 "foo": 4,
421 "bar": 0.000000000
422 }
423 },
424 "bad_ctrs2": {
425 "labels": {},
426 "counters": {
427 "foo": 6,
428 "bar": 0.000000000
429 }
430 },
431 "good_ctrs": {
432 "labels": {
433 "label1": "",
434 "label3": "val4"
435 },
436 "counters": {
437 "foo": 2,
438 "bar": 0.000000000
439 }
440 },
441 "only_key": {
442 "labels": {},
443 "counters": {
444 "foo": 4,
445 "bar": 0.000000000
446 }
447 },
448 "too_many_delimiters": {
449 "labels": {
450 "label1": "val1"
451 },
452 "counters": {
453 "foo": 8,
454 "bar": 0.000000000
455 }
456 }
457}
458)", message);
459
460 // test unlabeled perf counters are in the schema dump with labels and counters sections
461 ASSERT_EQ("", client.do_request(R"({ "prefix": "counter schema", "format": "raw" })", &message));
462 ASSERT_EQ(R"({
463 "bad_ctrs": {
464 "labels": {
465 "label1": "val1"
466 },
467 "counters": {
468 "foo": {
469 "type": 2,
470 "metric_type": "gauge",
471 "value_type": "integer",
472 "description": "",
473 "nick": "",
474 "priority": 0,
475 "units": "none"
476 },
477 "bar": {
478 "type": 1,
479 "metric_type": "gauge",
480 "value_type": "real",
481 "description": "",
482 "nick": "",
483 "priority": 0,
484 "units": "none"
485 }
486 }
487 },
488 "bad_ctrs2": {
489 "labels": {},
490 "counters": {
491 "foo": {
492 "type": 2,
493 "metric_type": "gauge",
494 "value_type": "integer",
495 "description": "",
496 "nick": "",
497 "priority": 0,
498 "units": "none"
499 },
500 "bar": {
501 "type": 1,
502 "metric_type": "gauge",
503 "value_type": "real",
504 "description": "",
505 "nick": "",
506 "priority": 0,
507 "units": "none"
508 }
509 }
510 },
511 "good_ctrs": {
512 "labels": {
513 "label1": "",
514 "label3": "val4"
515 },
516 "counters": {
517 "foo": {
518 "type": 2,
519 "metric_type": "gauge",
520 "value_type": "integer",
521 "description": "",
522 "nick": "",
523 "priority": 0,
524 "units": "none"
525 },
526 "bar": {
527 "type": 1,
528 "metric_type": "gauge",
529 "value_type": "real",
530 "description": "",
531 "nick": "",
532 "priority": 0,
533 "units": "none"
534 }
535 }
536 },
537 "only_key": {
538 "labels": {},
539 "counters": {
540 "foo": {
541 "type": 2,
542 "metric_type": "gauge",
543 "value_type": "integer",
544 "description": "",
545 "nick": "",
546 "priority": 0,
547 "units": "none"
548 },
549 "bar": {
550 "type": 1,
551 "metric_type": "gauge",
552 "value_type": "real",
553 "description": "",
554 "nick": "",
555 "priority": 0,
556 "units": "none"
557 }
558 }
559 },
560 "too_many_delimiters": {
561 "labels": {
562 "label1": "val1"
563 },
564 "counters": {
565 "foo": {
566 "type": 2,
567 "metric_type": "gauge",
568 "value_type": "integer",
569 "description": "",
570 "nick": "",
571 "priority": 0,
572 "units": "none"
573 },
574 "bar": {
575 "type": 1,
576 "metric_type": "gauge",
577 "value_type": "real",
578 "description": "",
579 "nick": "",
580 "priority": 0,
581 "units": "none"
582 }
583 }
584 }
585}
586)", message);
587
588 // test unlabeled perf counters are in the perf dump without the labels and counters section
589 ASSERT_EQ("", client.do_request(R"({ "prefix": "perf dump", "format": "raw" })", &message));
590 ASSERT_EQ(R"({
591 "only_key": {
592 "foo": 4,
593 "bar": 0.000000000
594 }
595}
596)", message);
597
598 // test unlabeled perf counters are in the perf schema without the labels and counters section
599 ASSERT_EQ("", client.do_request(R"({ "prefix": "perf schema", "format": "raw" })", &message));
600 ASSERT_EQ(R"({
601 "only_key": {
602 "foo": {
603 "type": 2,
604 "metric_type": "gauge",
605 "value_type": "integer",
606 "description": "",
607 "nick": "",
608 "priority": 0,
609 "units": "none"
610 },
611 "bar": {
612 "type": 1,
613 "metric_type": "gauge",
614 "value_type": "real",
615 "description": "",
616 "nick": "",
617 "priority": 0,
618 "units": "none"
619 }
620 }
621}
622)", message);
623
624 g_ceph_context->get_perfcounters_collection()->clear();
625}