Skip to content

Commit

Permalink
Merge #76301 #76511
Browse files Browse the repository at this point in the history
76301: server, ui: aggregate statements on period selected r=maryliag a=maryliag

Previously, the aggregation timestamp was used as part
of the key of a statement. The new query to collect
statement now ignores aggregation timestamp as keys.
This commit also removes the aggregated timestamp value on the UI,
 since it no longer applies.

Fixes #74513

Release note (ui change): We don't show information about
aggregations timestamp in Statements overview and Details pages, since
now all the statement fingerprints are grouped inside the same
time selection.

76511: pgwire: fix flaky cancel tests r=RichardJCai a=rafiss

fixes #76494
fixes #76493

One required a nil guard, and the other required the telemetry counter
to be incremented before the connection is closed.

Release note: None

Co-authored-by: Marylia Gutierrez <[email protected]>
Co-authored-by: Rafi Shamim <[email protected]>
  • Loading branch information
3 people committed Feb 14, 2022
3 parents 66dfdac + 71ef6b8 + 055f9bf commit 3be8121
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 68 deletions.
19 changes: 12 additions & 7 deletions pkg/server/combined_statement_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ func collectCombinedStatements(
fingerprint_id,
transaction_fingerprint_id,
app_name,
aggregated_ts,
max(metadata) AS metadata,
max(aggregated_ts) as aggregated_ts,
metadata,
crdb_internal.merge_statement_stats(array_agg(statistics)) AS statistics,
max(sampled_plan) AS sampled_plan,
aggregation_interval
Expand All @@ -141,7 +141,7 @@ func collectCombinedStatements(
fingerprint_id,
transaction_fingerprint_id,
app_name,
aggregated_ts,
metadata,
aggregation_interval
%s`, whereClause, orderAndLimit)

Expand Down Expand Up @@ -244,13 +244,18 @@ func collectCombinedTransactions(
query := fmt.Sprintf(
`SELECT
app_name,
aggregated_ts,
max(aggregated_ts) as aggregated_ts,
fingerprint_id,
metadata,
crdb_internal.merge_transaction_stats(array_agg(statistics)) AS statistics,
aggregation_interval
FROM crdb_internal.transaction_statistics %s
GROUP BY
app_name,
fingerprint_id,
metadata,
statistics,
aggregation_interval
FROM crdb_internal.transaction_statistics
%s %s`, whereClause, orderAndLimit)
%s`, whereClause, orderAndLimit)

const expectedNumDatums = 6

Expand Down
4 changes: 2 additions & 2 deletions pkg/server/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2550,7 +2550,6 @@ func (s *statusServer) CancelQueryByKey(
ctx context.Context, req *serverpb.CancelQueryByKeyRequest,
) (resp *serverpb.CancelQueryByKeyResponse, retErr error) {
local := req.SQLInstanceID == s.sqlServer.SQLInstanceID()
resp = &serverpb.CancelQueryByKeyResponse{}

// Acquiring the semaphore here helps protect both the source and destination
// nodes. The source node is protected against an attacker causing too much
Expand All @@ -2571,13 +2570,14 @@ func (s *statusServer) CancelQueryByKey(
// If we acquired the semaphore but the cancellation request failed, then
// hold on to the semaphore for longer. This helps mitigate a DoS attack
// of random cancellation requests.
if !resp.Canceled {
if err != nil || (resp != nil && !resp.Canceled) {
time.Sleep(1 * time.Second)
}
alloc.Release()
}()

if local {
resp = &serverpb.CancelQueryByKeyResponse{}
resp.Canceled, err = s.sessionRegistry.CancelQueryByKey(req.CancelQueryKey)
if err != nil {
resp.Error = err.Error()
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/pgwire/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,12 +741,12 @@ func (s *Server) ServeConn(ctx context.Context, conn net.Conn, socketType Socket
// attacker) will not know if the cancellation attempt succeeded. Errors are
// logged so that an operator can be aware of any possibly malicious requests.
func (s *Server) handleCancel(ctx context.Context, conn net.Conn, buf *pgwirebase.ReadBuffer) {
telemetry.Inc(sqltelemetry.CancelRequestCounter)
var err error
defer func() {
if err != nil {
log.Sessions.Warningf(ctx, "unexpected while handling pgwire cancellation request: %v", err)
}
telemetry.Inc(sqltelemetry.CancelRequestCounter)
}()

var backendKeyDataBits uint64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,20 +708,6 @@ export class StatementDetails extends React.Component<
<Col className="gutter-row" span={12}>
<SummaryCard className={cx("summary-card")}>
<Heading type="h5">Statement details</Heading>
<div className={summaryCardStylesCx("summary--card__item")}>
<Text>Aggregation Interval (UTC)</Text>
<Text>
{intervalStartTime.format("MMM D, h:mm A")} -{" "}
{intervalEndTime.format(
`${
intervalStartTime.isSame(intervalEndTime, "day")
? ""
: "MMM D,"
}h:mm A`,
)}
</Text>
</div>

{!isTenant && (
<div>
<div className={summaryCardStylesCx("summary--card__item")}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,6 @@ function makeCommonColumns(
const retryBar = retryBarChart(statements, defaultBarChartOptions);

return [
{
name: "aggregationInterval",
title: statisticsTableTitles.aggregationInterval(statType),
className: cx("statements-table__interval_time"),
cell: (stmt: AggregateStatistics) =>
formatAggregationIntervalColumn(
stmt.aggregatedTs,
stmt.aggregationInterval,
),
sort: (stmt: AggregateStatistics) => stmt.aggregatedTs,
},
{
name: "executionCount",
title: statisticsTableTitles.executionCount(statType),
Expand Down
22 changes: 0 additions & 22 deletions pkg/ui/workspaces/cluster-ui/src/statsTableUtil/statsTableUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const statisticsColumnLabels = {
database: "Database",
diagnostics: "Diagnostics",
executionCount: "Execution Count",
aggregationInterval: "Aggregation Interval (UTC)",
maxMemUsage: "Max Memory",
networkBytes: "Network",
regionNodes: "Regions/Nodes",
Expand Down Expand Up @@ -140,27 +139,6 @@ export const statisticsTableTitles: StatisticTableTitleType = {
</Tooltip>
);
},
aggregationInterval: () => {
return (
<Tooltip
placement="bottom"
style="tableTitle"
content={
<div>
<p>
The time interval of the statement execution. By default,
statements are configured to aggregate over an hour interval.
<br />
For example, if a statement is executed at 1:23PM it will fall in
the 1:00PM - 2:00PM time interval.
</p>
</div>
}
>
{getLabel("aggregationInterval")}
</Tooltip>
);
},
executionCount: (statType: StatisticType) => {
let contentModifier = "";
let fingerprintModifier = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,6 @@ export function makeTransactionsColumns(
),
alwaysShow: true,
},
{
name: "aggregationInterval",
title: statisticsTableTitles.aggregationInterval("transaction"),
cell: (item: TransactionInfo) =>
formatAggregationIntervalColumn(
TimestampToNumber(item.stats_data?.aggregated_ts),
DurationToNumber(item.stats_data?.aggregation_interval),
),
sort: (item: TransactionInfo) =>
TimestampToNumber(item.stats_data?.aggregated_ts),
},
{
name: "executionCount",
title: statisticsTableTitles.executionCount(statType),
Expand Down

0 comments on commit 3be8121

Please sign in to comment.