github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/views/statements/statementsTableContent.tsx (about) 1 // Copyright 2020 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 import React from "react"; 12 import { Link } from "react-router-dom"; 13 import { Anchor, Tooltip } from "src/components"; 14 import { statementDiagnostics, statementsRetries, statementsSql, statementsTimeInterval, transactionalPipelining } from "src/util/docs"; 15 import getHighlightedText from "src/util/highlightedText"; 16 import { summarize } from "src/util/sql/summarize"; 17 import { ActivateDiagnosticsModalRef } from "./diagnostics/activateDiagnosticsModal"; 18 import { DiagnosticStatusBadge } from "./diagnostics/diagnosticStatusBadge"; 19 import { shortStatement } from "./statementsTable"; 20 21 export type NodeNames = { [nodeId: string]: string }; 22 23 export const StatementTableTitle = { 24 statements: ( 25 <Tooltip 26 placement="bottom" 27 title={ 28 <div className="tooltip__table--title"> 29 <p> 30 {"SQL statement "} 31 <Anchor 32 href={statementsSql} 33 target="_blank" 34 > 35 fingerprint. 36 </Anchor> 37 </p> 38 <p> 39 To view additional details of a SQL statement fingerprint, click this to open the Statement Details page. 40 </p> 41 </div> 42 } 43 > 44 Statements 45 </Tooltip> 46 ), 47 txtType: ( 48 <Tooltip 49 placement="bottom" 50 title={ 51 <div className="tooltip__table--title"> 52 <p> 53 {"Type of transaction (implicit or explicit). Explicit transactions refer to statements that are wrapped by "} 54 <code>BEGIN</code> 55 {" and "} 56 <code>COMMIT</code> 57 {" statements by the client. Explicit transactions employ "} 58 <Anchor 59 href={transactionalPipelining} 60 target="_blank" 61 > 62 transactional pipelining 63 </Anchor> 64 {" and therefore report latencies that do not account for replication."} 65 </p> 66 <p> 67 For statements not in explicit transactions, CockroachDB wraps each statement in individual implicit transactions. 68 </p> 69 </div> 70 } 71 > 72 TXN Type 73 </Tooltip> 74 ), 75 diagnostics: ( 76 <Tooltip 77 placement="bottom" 78 title={ 79 <div className="tooltip__table--title"> 80 <p> 81 {"Option to activate "} 82 <Anchor 83 href={statementDiagnostics} 84 target="_blank" 85 > 86 diagnostics 87 </Anchor> 88 {" for each statement. If activated, this displays the status of diagnostics collection ("} 89 <code>WAITING FOR QUERY</code>, <code>READY</code>, OR <code>ERROR</code>). 90 </p> 91 </div> 92 } 93 > 94 Diagnostics 95 </Tooltip> 96 ), 97 retries: ( 98 <Tooltip 99 placement="bottom" 100 title={ 101 <div className="tooltip__table--title"> 102 <p> 103 {"Cumulative number of "} 104 <Anchor 105 href={statementsRetries} 106 target="_blank" 107 > 108 retries 109 </Anchor> 110 {" of statements with this fingerprint within the last hour or specified time interval."} 111 </p> 112 </div> 113 } 114 > 115 Retries 116 </Tooltip> 117 ), 118 executionCount: ( 119 <Tooltip 120 placement="bottom" 121 title={ 122 <div className="tooltip__table--title"> 123 <p> 124 {"Cumulative number of executions of statements with this fingerprint within the last hour or specified "} 125 <Anchor 126 href={statementsTimeInterval} 127 target="_blank" 128 > 129 time interval 130 </Anchor>. 131 </p> 132 <p> 133 {"The bar indicates the ratio of runtime success (gray) to "} 134 <Anchor 135 href={statementsRetries} 136 target="_blank" 137 > 138 retries 139 </Anchor> 140 {" (red) for the SQL statement fingerprint."} 141 </p> 142 </div> 143 } 144 > 145 Execution Count 146 </Tooltip> 147 ), 148 rowsAffected: ( 149 <Tooltip 150 placement="bottom" 151 title={ 152 <div className="tooltip__table--title"> 153 <p> 154 {"Average number of rows returned while executing statements with this fingerprint within the last hour or specified "} 155 <Anchor 156 href={statementsTimeInterval} 157 target="_blank" 158 > 159 time interval 160 </Anchor>. 161 </p> 162 <p> 163 The gray bar indicates the mean number of rows returned. The blue bar indicates one standard deviation from the mean. 164 </p> 165 </div> 166 } 167 > 168 Rows Affected 169 </Tooltip> 170 ), 171 latency: ( 172 <Tooltip 173 placement="bottom" 174 title={ 175 <div className="tooltip__table--title"> 176 <p> 177 Average service latency of statements with this fingerprint within the last hour or specified time interval. 178 </p> 179 <p> 180 The gray bar indicates the mean latency. The blue bar indicates one standard deviation from the mean. 181 </p> 182 </div> 183 } 184 > 185 Latency 186 </Tooltip> 187 ), 188 }; 189 190 export const StatementTableCell = { 191 statements: (search?: string, selectedApp?: string) => (stmt: any) => ( 192 <StatementLink 193 statement={ stmt.label } 194 implicitTxn={ stmt.implicitTxn } 195 search={search} 196 app={ selectedApp } 197 /> 198 ), 199 diagnostics: (activateDiagnosticsRef: React.RefObject<ActivateDiagnosticsModalRef>) => (stmt: any) => { 200 if (stmt.diagnosticsReport) { 201 return <DiagnosticStatusBadge status={stmt.diagnosticsReport.completed ? "READY" : "WAITING FOR QUERY"}/>; 202 } 203 return ( 204 <Anchor 205 onClick={() => activateDiagnosticsRef?.current?.showModalFor(stmt.label)} 206 > 207 Activate 208 </Anchor> 209 ); 210 }, 211 nodeLink: (nodeNames: NodeNames) => (stmt: any) => <NodeLink nodeId={stmt.label} nodeNames={ nodeNames } />, 212 }; 213 214 export const StatementLink = (props: { statement: string, app: string, implicitTxn: boolean, search: string }) => { 215 const summary = summarize(props.statement); 216 const base = props.app && props.app.length > 0 ? `/statements/${props.app}/${props.implicitTxn}` : `/statement/${props.implicitTxn}`; 217 return ( 218 <Link to={ `${base}/${encodeURIComponent(props.statement)}` }> 219 <div className="cl-table-link__tooltip"> 220 <Tooltip 221 placement="bottom" 222 title={<pre className="cl-table-link__description"> 223 { getHighlightedText(props.statement, props.search) } 224 </pre>} 225 overlayClassName="cl-table-link__statement-tooltip--fixed-width" 226 > 227 <div className="cl-table-link__tooltip-hover-area"> 228 { getHighlightedText(shortStatement(summary, props.statement), props.search, true) } 229 </div> 230 </Tooltip> 231 </div> 232 </Link> 233 ); 234 }; 235 236 const NodeLink = (props: { nodeId: string, nodeNames: NodeNames }) => ( 237 <Link to={ `/node/${props.nodeId}` }> 238 <div className="node-name-tooltip__info-icon">{props.nodeNames[props.nodeId]}</div> 239 </Link> 240 );