github.com/matrixorigin/matrixone@v1.2.0/pkg/util/metric/v2/dashboard/grafana_dashboard_txn.go (about) 1 // Copyright 2023 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package dashboard 16 17 import ( 18 "context" 19 20 "github.com/K-Phoen/grabana/axis" 21 "github.com/K-Phoen/grabana/dashboard" 22 ) 23 24 func (c *DashboardCreator) initTxnDashboard() error { 25 folder, err := c.createFolder(moFolderName) 26 if err != nil { 27 return err 28 } 29 30 build, err := dashboard.New( 31 "Txn Metrics", 32 c.withRowOptions( 33 c.initTxnOverviewRow(), 34 c.initTxnDurationRow(), 35 c.initTxnCommitDurationRow(), 36 c.initTxnLockDurationRow(), 37 c.initTxnUnlockTablesRow(), 38 c.initTxnLockWaitersRow(), 39 c.initTxnStatementDurationRow(), 40 c.initTxnStatementsCountRow(), 41 c.initTxnTableRangesRow(), 42 c.initTxnCheckPKDupRow(), 43 c.initTxnReaderDurationRow(), 44 c.initTxnMpoolRow(), 45 c.initTxnOnPrepareWALRow(), 46 c.initTxnBeforeCommitRow(), 47 c.initTxnDequeuePreparedRow(), 48 c.initTxnRangesLoadedObjectMetaRow(), 49 c.initFastRangesRow(), 50 c.initRangesRow(), 51 c.initTxnShowAccountsRow(), 52 c.initCNCommittedObjectQuantityRow(), 53 )...) 54 if err != nil { 55 return err 56 } 57 _, err = c.cli.UpsertDashboard(context.Background(), folder, build) 58 return err 59 } 60 61 func (c *DashboardCreator) initCNCommittedObjectQuantityRow() dashboard.Option { 62 return dashboard.Row( 63 "Quantity of Object Location The CN Have Committed to TN", 64 c.withGraph( 65 "meta location", 66 6, 67 `sum(`+c.getMetricWithFilter("mo_txn_cn_committed_location_quantity_size", `type="meta_location"`)+`)`, 68 ""), 69 70 c.withGraph( 71 "delta location", 72 6, 73 `sum(`+c.getMetricWithFilter("mo_txn_cn_committed_location_quantity_size", `type="delta_location"`)+`)`, 74 ""), 75 ) 76 } 77 78 func (c *DashboardCreator) initRangesRow() dashboard.Option { 79 return dashboard.Row( 80 "Txn Ranges Selectivity", 81 c.getHistogram( 82 "ranges block selectivity", 83 c.getMetricWithFilter("mo_txn_ranges_selectivity_percentage_bucket", `type="block_selectivity"`), 84 []float64{0.50, 0.8, 0.90, 0.99}, 85 6, 86 axis.Unit(""), 87 axis.Min(0)), 88 89 c.getHistogram( 90 "ranges result len", 91 c.getMetricWithFilter("mo_txn_ranges_duration_size_bucket", `type="ranges_len"`), 92 []float64{0.50, 0.8, 0.90, 0.99}, 93 6, 94 axis.Unit(""), 95 axis.Min(0)), 96 ) 97 } 98 99 func (c *DashboardCreator) initFastRangesRow() dashboard.Option { 100 return dashboard.Row( 101 "Txn Fast Ranges Selectivity", 102 c.getHistogram( 103 "fast ranges block selectivity", 104 c.getMetricWithFilter("mo_txn_ranges_selectivity_percentage_bucket", `type="fast_block_selectivity"`), 105 []float64{0.50, 0.8, 0.90, 0.99}, 106 4, 107 axis.Unit(""), 108 axis.Min(0)), 109 110 c.getHistogram( 111 "fast ranges zone map selectivity", 112 c.getMetricWithFilter("mo_txn_ranges_selectivity_percentage_bucket", `type="fast_zm_selectivity"`), 113 []float64{0.50, 0.8, 0.90, 0.99}, 114 4, 115 axis.Unit(""), 116 axis.Min(0)), 117 118 c.getHistogram( 119 "fast ranges result len", 120 c.getMetricWithFilter("mo_txn_ranges_duration_size_bucket", `type="fast_ranges_len"`), 121 []float64{0.50, 0.8, 0.90, 0.99}, 122 4, 123 axis.Unit(""), 124 axis.Min(0)), 125 ) 126 } 127 128 func (c *DashboardCreator) initTxnTableRangesRow() dashboard.Option { 129 return dashboard.Row( 130 "Txn table ranges", 131 c.getHistogram( 132 "Txn table ranges duration", 133 c.getMetricWithFilter(`mo_txn_ranges_duration_seconds_bucket`, ``), 134 []float64{0.50, 0.8, 0.90, 0.99}, 135 12, 136 axis.Unit("s"), 137 axis.Min(0)), 138 ) 139 } 140 141 func (c *DashboardCreator) initTxnCheckPKDupRow() dashboard.Option { 142 return dashboard.Row( 143 "Txn check pk dup", 144 c.getHistogram( 145 "Txn check pk dup duration", 146 c.getMetricWithFilter(`mo_txn_check_pk_dup_duration_seconds_bucket`, ``), 147 []float64{0.50, 0.8, 0.90, 0.99}, 148 12, 149 axis.Unit("s"), 150 axis.Min(0)), 151 ) 152 } 153 154 func (c *DashboardCreator) initTxnOverviewRow() dashboard.Option { 155 return dashboard.Row( 156 "Txn overview", 157 c.withMultiGraph( 158 "Txn requests", 159 3, 160 []string{ 161 `sum(rate(` + c.getMetricWithFilter("mo_txn_total", `type="user"`) + `[$interval]))`, 162 `sum(rate(` + c.getMetricWithFilter("mo_txn_total", `type="internal"`) + `[$interval]))`, 163 `sum(rate(` + c.getMetricWithFilter("mo_txn_total", `type="leak"`) + `[$interval]))`, 164 `sum(rate(` + c.getMetricWithFilter("mo_txn_total", `type="long-running"`) + `[$interval]))`, 165 `sum(rate(` + c.getMetricWithFilter("mo_txn_total", `type="stuck-in-commit"`) + `[$interval]))`, 166 `sum(rate(` + c.getMetricWithFilter("mo_txn_total", `type="stuck-in-rollback"`) + `[$interval]))`, 167 `sum(rate(` + c.getMetricWithFilter("mo_txn_statement_total", `type="total"`) + `[$interval]))`, 168 `sum(rate(` + c.getMetricWithFilter("mo_txn_statement_total", `type="retry"`) + `[$interval]))`, 169 `sum(rate(` + c.getMetricWithFilter("mo_txn_lock_total", `type="total"`) + `[$interval]))`, 170 `sum(rate(` + c.getMetricWithFilter("mo_txn_lock_total", `type="local"`) + `[$interval]))`, 171 `sum(rate(` + c.getMetricWithFilter("mo_txn_lock_total", `type="remote"`) + `[$interval]))`, 172 }, 173 []string{ 174 "user-txn", 175 "internal-txn", 176 "leak", 177 "long-running", 178 "stuck-in-commit", 179 "stuck-in-rollback", 180 "statement", 181 "statement-retry", 182 "lock", 183 "local-lock", 184 "remote-lock", 185 }), 186 187 c.withMultiGraph( 188 "Commit requests", 189 3, 190 []string{ 191 `sum(rate(` + c.getMetricWithFilter("mo_txn_commit_total", `type="cn"`) + `[$interval]))`, 192 `sum(rate(` + c.getMetricWithFilter("mo_txn_commit_total", `type="tn-receive"`) + `[$interval]))`, 193 `sum(rate(` + c.getMetricWithFilter("mo_txn_commit_total", `type="tn-handle"`) + `[$interval]))`, 194 }, 195 []string{ 196 "cn", 197 "tn-receive", 198 "tn-handle", 199 }), 200 201 c.withGraph( 202 "Rollback requests", 203 3, 204 `sum(rate(`+c.getMetricWithFilter("mo_txn_rollback_total", "")+`[$interval])) by (`+c.by+`)`, 205 "{{ "+c.by+" }}"), 206 207 c.withMultiGraph( 208 "Txn Queue Status", 209 3, 210 []string{ 211 `sum(` + c.getMetricWithFilter("mo_txn_queue_size", `type="active"`) + `)`, 212 `sum(` + c.getMetricWithFilter("mo_txn_queue_size", `type="wait-active"`) + `)`, 213 `sum(` + c.getMetricWithFilter("mo_txn_queue_size", `type="commit"`) + `)`, 214 `sum(` + c.getMetricWithFilter("mo_txn_queue_size", `type="lock-rpc"`) + `)`, 215 }, 216 []string{ 217 "active", 218 "wait-active", 219 "commit", 220 "lock-rpc", 221 }), 222 ) 223 } 224 225 func (c *DashboardCreator) initTxnDurationRow() dashboard.Option { 226 return dashboard.Row( 227 "Txn create duration", 228 c.getMultiHistogram( 229 []string{ 230 c.getMetricWithFilter(`mo_txn_life_duration_seconds_bucket`, ``), 231 c.getMetricWithFilter(`mo_txn_create_duration_seconds_bucket`, `type="total"`), 232 c.getMetricWithFilter(`mo_txn_create_duration_seconds_bucket`, `type="wait-active"`), 233 c.getMetricWithFilter(`mo_txn_create_duration_seconds_bucket`, `type="determine-snapshot"`), 234 }, 235 []string{ 236 "life", 237 "create", 238 "wait-active", 239 "determine-snapshot", 240 }, 241 []float64{0.50, 0.8, 0.90, 0.99}, 242 []float32{3, 3, 3, 3}, 243 axis.Unit("s"), 244 axis.Min(0))..., 245 ) 246 } 247 248 func (c *DashboardCreator) initTxnCommitDurationRow() dashboard.Option { 249 return dashboard.Row( 250 "Txn CN commit duration", 251 c.getMultiHistogram( 252 []string{ 253 c.getMetricWithFilter("mo_txn_commit_duration_seconds_bucket", `type="cn"`), 254 c.getMetricWithFilter(`mo_txn_commit_duration_seconds_bucket`, `type="cn-send"`), 255 c.getMetricWithFilter(`mo_txn_commit_duration_seconds_bucket`, `type="cn-resp"`), 256 c.getMetricWithFilter(`mo_txn_commit_duration_seconds_bucket`, `type="cn-wait-logtail"`), 257 c.getMetricWithFilter(`mo_txn_commit_duration_seconds_bucket`, `type="tn"`), 258 }, 259 []string{ 260 "total", 261 "send", 262 "response", 263 "logtail-applied", 264 "tn", 265 }, 266 []float64{0.50, 0.8, 0.90, 0.99}, 267 []float32{3, 3, 3, 3}, 268 axis.Unit("s"), 269 axis.Min(0))..., 270 ) 271 } 272 273 func (c *DashboardCreator) initTxnOnPrepareWALRow() dashboard.Option { 274 return dashboard.Row( 275 "txn on prepare wal duration", 276 c.getMultiHistogram( 277 []string{ 278 c.getMetricWithFilter("mo_txn_tn_side_duration_seconds_bucket", `step="1-PreparingWait"`), 279 c.getMetricWithFilter("mo_txn_tn_side_duration_seconds_bucket", `step="2-Preparing"`), 280 c.getMetricWithFilter("mo_txn_tn_side_duration_seconds_bucket", `step="3-PrepareWalWait"`), 281 c.getMetricWithFilter("mo_txn_tn_side_duration_seconds_bucket", `step="4-PrepareWal"`), 282 c.getMetricWithFilter("mo_txn_tn_side_duration_seconds_bucket", `step="5-PreparedWait"`), 283 c.getMetricWithFilter("mo_txn_tn_side_duration_seconds_bucket", `step="6-Prepared"`), 284 }, 285 []string{ 286 "1-PreparingWait", 287 "2-Preparing", 288 "3-PrepareWalWait", 289 "4-PrepareWal", 290 "5-PreparedWait", 291 "6-Prepared", 292 }, 293 []float64{0.80, 0.90, 0.95, 0.99}, 294 []float32{3, 3, 3, 3}, 295 axis.Unit("s"), 296 axis.Min(0))..., 297 ) 298 } 299 300 func (c *DashboardCreator) initTxnDequeuePreparedRow() dashboard.Option { 301 return dashboard.Row( 302 "txn dequeue prepared duration", 303 c.getHistogram( 304 "txn dequeue prepared duration", 305 c.getMetricWithFilter("mo_txn_tn_side_duration_seconds_bucket", `step="dequeue_prepared"`), 306 []float64{0.50, 0.8, 0.90, 0.99}, 307 12, 308 axis.Unit("s"), 309 axis.Min(0)), 310 ) 311 } 312 313 func (c *DashboardCreator) initTxnBeforeCommitRow() dashboard.Option { 314 return dashboard.Row( 315 "txn handle commit but before txn.commit duration", 316 c.getHistogram( 317 "txn handle commit but before txn.commit duration", 318 c.getMetricWithFilter("mo_txn_tn_side_duration_seconds_bucket", `step="before_txn_commit"`), 319 []float64{0.50, 0.8, 0.90, 0.99}, 320 12, 321 axis.Unit("s"), 322 axis.Min(0)), 323 ) 324 } 325 326 func (c *DashboardCreator) initTxnStatementDurationRow() dashboard.Option { 327 return dashboard.Row( 328 "Txn statement duration", 329 c.getMultiHistogram( 330 []string{ 331 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="execute"`), 332 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="execute-latency"`), 333 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="build-plan"`), 334 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="compile"`), 335 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="scan"`), 336 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="external-scan"`), 337 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="insert-s3"`), 338 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="stats"`), 339 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="resolve"`), 340 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="resolve-udf"`), 341 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="update-stats"`), 342 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="update-info-from-zonemap"`), 343 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="update-stats-info-map"`), 344 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="nodes"`), 345 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="compileScope"`), 346 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="compileQuery"`), 347 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="compilePlanScope"`), 348 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="BuildPlan"`), 349 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="BuildSelect"`), 350 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="BuildInsert"`), 351 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="BuildExplain"`), 352 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="BuildReplace"`), 353 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="BuildUpdate"`), 354 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="BuildDelete"`), 355 c.getMetricWithFilter(`mo_txn_statement_duration_seconds_bucket`, `type="BuildLoad"`), 356 }, 357 []string{ 358 "execute", 359 "execute-latency", 360 "build-plan", 361 "compile", 362 "scan", 363 "external-scan", 364 "insert-s3", 365 "stats", 366 "resolve", 367 "resolve-udf", 368 "update-stats", 369 "update-info-from-zonemap", 370 "update-stats-info-map", 371 "nodes", 372 "compileScope", 373 "compileQuery", 374 "compilePlanScope", 375 "BuildPlan", 376 "BuildSelect", 377 "BuildInsert", 378 "BuildExplain", 379 "BuildReplace", 380 "BuildUpdate", 381 "BuildDelete", 382 "BuildLoad", 383 }, 384 []float64{0.50, 0.8, 0.90, 0.99}, 385 []float32{3, 3, 3, 3}, 386 axis.Unit("s"), 387 axis.Min(0))..., 388 ) 389 } 390 391 func (c *DashboardCreator) initTxnStatementsCountRow() dashboard.Option { 392 return dashboard.Row( 393 "Txn statements count", 394 c.getMultiHistogram( 395 []string{ 396 c.getMetricWithFilter(`mo_txn_life_statements_total_bucket`, ``), 397 }, 398 []string{ 399 "statements/txn", 400 }, 401 []float64{0.50, 0.8, 0.90, 0.99}, 402 []float32{3, 3, 3, 3})..., 403 ) 404 } 405 406 func (c *DashboardCreator) initTxnRangesLoadedObjectMetaRow() dashboard.Option { 407 return dashboard.Row( 408 "Txn Ranges Loaded Object Meta", 409 c.withGraph( 410 "Txn Ranges Loaded Object Meta", 411 12, 412 `sum(increase(`+c.getMetricWithFilter("mo_txn_ranges_loaded_object_meta_total", "")+`[$interval])) by (`+c.by+`, type)`, 413 "{{ "+c.by+"-type }}"), 414 ) 415 } 416 417 func (c *DashboardCreator) initTxnShowAccountsRow() dashboard.Option { 418 return dashboard.Row( 419 "Show Accounts Duration", 420 c.getHistogram( 421 "Show Accounts Duration", 422 c.getMetricWithFilter(`mo_txn_show_accounts_duration_seconds_bucket`, ``), 423 []float64{0.50, 0.8, 0.90, 0.99}, 424 12, 425 axis.Unit("s"), 426 axis.Min(0)), 427 ) 428 } 429 430 func (c *DashboardCreator) initTxnLockDurationRow() dashboard.Option { 431 return dashboard.Row( 432 "Txn lock duration", 433 c.getMultiHistogram( 434 []string{ 435 c.getMetricWithFilter(`mo_txn_lock_duration_seconds_bucket`, `type="acquire"`), 436 c.getMetricWithFilter(`mo_txn_lock_duration_seconds_bucket`, `type="acquire-wait"`), 437 c.getMetricWithFilter(`mo_txn_unlock_duration_seconds_bucket`, `type="total"`), 438 c.getMetricWithFilter(`mo_txn_unlock_duration_seconds_bucket`, `type="btree-get-lock"`), 439 c.getMetricWithFilter(`mo_txn_unlock_duration_seconds_bucket`, `type="btree-total"`), 440 c.getMetricWithFilter(`mo_txn_unlock_duration_seconds_bucket`, `type="worker-handle"`), 441 }, 442 []string{ 443 "lock-total", 444 "lock-wait", 445 "unlock-total", 446 "unlock-btree-get-lock", 447 "unlock-btree-total", 448 "worker-handle", 449 }, 450 []float64{0.50, 0.8, 0.90, 0.99}, 451 []float32{3, 3, 3, 3}, 452 axis.Unit("s"), 453 axis.Min(0))..., 454 ) 455 } 456 457 func (c *DashboardCreator) initTxnLockWaitersRow() dashboard.Option { 458 return dashboard.Row( 459 "Txn lock waiters", 460 c.getMultiHistogram( 461 []string{ 462 c.getMetricWithFilter(`mo_txn_lock_waiters_total_bucket`, ``), 463 }, 464 []string{ 465 "waiters", 466 }, 467 []float64{0.50, 0.8, 0.90, 0.99}, 468 []float32{3, 3, 3, 3})..., 469 ) 470 } 471 472 func (c *DashboardCreator) initTxnMpoolRow() dashboard.Option { 473 return dashboard.Row( 474 "Txn MPool", 475 c.getMultiHistogram( 476 []string{ 477 c.getMetricWithFilter(`mo_txn_mpool_duration_seconds_bucket`, `type="new"`), 478 c.getMetricWithFilter(`mo_txn_mpool_duration_seconds_bucket`, `type="delete"`), 479 }, 480 []string{ 481 "new", 482 "delete", 483 }, 484 []float64{0.50, 0.8, 0.90, 0.99}, 485 []float32{3, 3, 3, 3}, 486 axis.Unit("s"), 487 axis.Min(0))..., 488 ) 489 } 490 491 func (c *DashboardCreator) initTxnUnlockTablesRow() dashboard.Option { 492 return dashboard.Row( 493 "Txn unlock tables", 494 c.getMultiHistogram( 495 []string{ 496 c.getMetricWithFilter(`mo_txn_unlock_table_total_bucket`, ``), 497 }, 498 []string{ 499 "tables", 500 }, 501 []float64{0.50, 0.8, 0.90, 0.99}, 502 []float32{3, 3, 3, 3})..., 503 ) 504 } 505 506 func (c *DashboardCreator) initTxnReaderDurationRow() dashboard.Option { 507 return dashboard.Row( 508 "Txn reader duration", 509 c.getMultiHistogram( 510 []string{ 511 c.getMetricWithFilter(`mo_txn_reader_duration_seconds_bucket`, `type="block-reader"`), 512 c.getMetricWithFilter(`mo_txn_reader_duration_seconds_bucket`, `type="merge-reader"`), 513 c.getMetricWithFilter(`mo_txn_reader_duration_seconds_bucket`, `type="block-merge-reader"`), 514 }, 515 []string{ 516 "block-reader", 517 "merge-reader", 518 "block-merge-reader", 519 }, 520 []float64{0.80, 0.90, 0.95, 0.99}, 521 []float32{3, 3, 3, 3}, 522 axis.Unit("s"), 523 axis.Min(0))..., 524 ) 525 }