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

Show Impact metric in the Operations list on the Insights page. #6389

Merged
merged 6 commits into from
Jan 21, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/short-donkeys-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'hive': minor
---

Show Impact metric in the Operations list on the Insights page.
Impact equals to the total time spent on this operation in the selected period in seconds.
It helps assess which operations contribute the most to overall latency.


```
Impact = Requests * avg/1000
```
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface OperationsStatsMapper {
clients: readonly string[];
}
export interface DurationValuesMapper {
avg: number | null;
p75: number | null;
p90: number | null;
p95: number | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export default gql`
}

type DurationValues {
avg: Int!
p75: Int!
p90: Int!
p95: Int!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ export class OperationsManager {
}

@cache<{ period: DateRange } & TargetSelector>(selector => JSON.stringify(selector))
async readDetailedDurationPercentiles({
async readDetailedDurationMetrics({
period,
organizationId: organization,
projectId: project,
Expand Down Expand Up @@ -744,7 +744,7 @@ export class OperationsManager {
},
});

return this.reader.durationPercentiles({
return this.reader.durationMetrics({
target,
period,
operations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,21 @@ function toUnixTimestamp(utcDate: string): any {
return new UTCDate(iso).getTime();
}

export interface Percentiles {
export interface DurationMetrics {
avg: number;
p75: number;
p90: number;
p95: number;
p99: number;
}

function toPercentiles(item: Percentiles | number[]) {
if (Array.isArray(item)) {
return {
p75: item[0],
p90: item[1],
p95: item[2],
p99: item[3],
};
}

function toDurationMetrics(percentiles: [number, number, number, number], avg: number) {
return {
p75: item.p75,
p90: item.p90,
p95: item.p95,
p99: item.p99,
avg,
p75: percentiles[0],
p90: percentiles[1],
p95: percentiles[2],
p99: percentiles[3],
};
}

Expand Down Expand Up @@ -575,7 +568,7 @@ export class OperationsReader {
operation_kind: string;
}>({
query: sql`
SELECT
SELECT
name,
hash,
operation_kind
Expand Down Expand Up @@ -651,7 +644,7 @@ export class OperationsReader {
type: 'query' | 'mutation' | 'subscription';
}>({
query: sql`
SELECT
SELECT
"operation_collection_details"."hash" AS "hash",
"operation_collection_details"."operation_kind" AS "type",
"operation_collection_details"."name" AS "name",
Expand Down Expand Up @@ -697,7 +690,7 @@ export class OperationsReader {
}>(
this.pickAggregationByPeriod({
query: aggregationTableName => sql`
SELECT
SELECT
coordinate
FROM ${aggregationTableName('coordinates')}
${this.createFilter({
Expand Down Expand Up @@ -747,7 +740,7 @@ export class OperationsReader {
}>(
this.pickAggregationByPeriod({
query: aggregationTableName => sql`
SELECT
SELECT
sum(total) as total,
client_name,
client_version
Expand Down Expand Up @@ -844,7 +837,7 @@ export class OperationsReader {
}>(
this.pickAggregationByPeriod({
query: aggregationTableName => sql`
SELECT
SELECT
sum(total) as total,
client_version
FROM ${aggregationTableName('clients')}
Expand Down Expand Up @@ -892,7 +885,7 @@ export class OperationsReader {
SELECT
SUM("result"."total") AS "amountOfRequests"
FROM (
SELECT
SELECT
SUM("operations_daily"."total") AS "total"
FROM
"operations_daily"
Expand All @@ -904,7 +897,7 @@ export class OperationsReader {

UNION ALL

SELECT
SELECT
SUM("subscription_operations_daily"."total") AS "total"
FROM
"subscription_operations_daily"
Expand Down Expand Up @@ -1005,7 +998,7 @@ export class OperationsReader {
SELECT
"operation_collection_details"."name",
"operation_collection_details"."hash"
FROM
FROM
"operation_collection_details"
PREWHERE
"operation_collection_details"."target" IN (${sql.array(args.targetIds, 'String')})
Expand Down Expand Up @@ -1262,7 +1255,7 @@ export class OperationsReader {
}>(
this.pickAggregationByPeriod({
query: aggregationTableName => sql`
SELECT
SELECT
count(distinct client_version) as total
FROM ${aggregationTableName('clients')}
${this.createFilter({
Expand Down Expand Up @@ -1470,7 +1463,7 @@ export class OperationsReader {
client_name: string;
}>({
query: sql`
SELECT
SELECT
sum(total) as count,
client_name
FROM clients_daily
Expand Down Expand Up @@ -1573,7 +1566,7 @@ export class OperationsReader {
}>(
this.pickAggregationByPeriod({
query: aggregationTableName => sql`
SELECT
SELECT
toDateTime(
intDiv(
toUnixTimestamp(timestamp),
Expand All @@ -1585,7 +1578,7 @@ export class OperationsReader {
FROM ${aggregationTableName('operations')}
${this.createFilter({ target: targets, period: roundedPeriod })}
GROUP BY target, date
ORDER BY
ORDER BY
target,
date
WITH FILL
Expand Down Expand Up @@ -1723,7 +1716,7 @@ export class OperationsReader {
}): Promise<
Array<{
date: any;
duration: Percentiles;
duration: DurationMetrics;
}>
> {
return this.getDurationAndCountOverTime({
Expand All @@ -1745,13 +1738,15 @@ export class OperationsReader {
period: DateRange;
operations?: readonly string[];
clients?: readonly string[];
}): Promise<Percentiles> {
}): Promise<DurationMetrics> {
const result = await this.clickHouse.query<{
percentiles: [number, number, number, number];
average: number;
}>(
this.pickAggregationByPeriod({
query: aggregationTableName => sql`
SELECT
SELECT
avgMerge(duration_avg) as average,
quantilesMerge(0.75, 0.90, 0.95, 0.99)(duration_quantiles) as percentiles
FROM ${aggregationTableName('operations')}
${this.createFilter({ target, period, operations, clients })}
Expand All @@ -1762,10 +1757,10 @@ export class OperationsReader {
}),
);

return toPercentiles(result.data[0].percentiles);
return toDurationMetrics(result.data[0].percentiles, result.data[0].average);
}

async durationPercentiles({
async durationMetrics({
target,
period,
operations,
Expand All @@ -1780,12 +1775,14 @@ export class OperationsReader {
}) {
const result = await this.clickHouse.query<{
hash: string;
average: number;
percentiles: [number, number, number, number];
}>(
this.pickAggregationByPeriod({
query: aggregationTableName => sql`
SELECT
SELECT
hash,
avgMerge(duration_avg) as average,
quantilesMerge(0.75, 0.90, 0.95, 0.99)(duration_quantiles) as percentiles
FROM ${aggregationTableName('operations')}
${this.createFilter({
Expand Down Expand Up @@ -1813,10 +1810,10 @@ export class OperationsReader {
}),
);

const collection = new Map<string, Percentiles>();
const collection = new Map<string, DurationMetrics>();

result.data.forEach(row => {
collection.set(row.hash, toPercentiles(row.percentiles));
collection.set(row.hash, toDurationMetrics(row.percentiles, row.average));
});

return collection;
Expand Down Expand Up @@ -1881,6 +1878,7 @@ export class OperationsReader {
return sql`
SELECT
date,
average,
percentiles,
total,
totalOk
Expand All @@ -1892,6 +1890,7 @@ export class OperationsReader {
toUInt32(${String(interval.seconds)})
) * toUInt32(${String(interval.seconds)})
) as date,
avgMerge(duration_avg) as average,
quantilesMerge(0.75, 0.90, 0.95, 0.99)(duration_quantiles) as percentiles,
sum(total) as total,
sum(total_ok) as totalOk
Expand Down Expand Up @@ -1929,6 +1928,7 @@ export class OperationsReader {
date: string;
total: number;
totalOk: number;
average: number;
percentiles: [number, number, number, number];
}>(query);

Expand All @@ -1937,7 +1937,7 @@ export class OperationsReader {
date: toUnixTimestamp(row.date),
total: ensureNumber(row.total),
totalOk: ensureNumber(row.totalOk),
duration: toPercentiles(row.percentiles),
duration: toDurationMetrics(row.percentiles, row.average),
};
});
}
Expand Down Expand Up @@ -2148,7 +2148,7 @@ export class OperationsReader {
}>(
this.pickAggregationByPeriod({
query: aggregationTableName => sql`
SELECT
SELECT
toDateTime(
intDiv(
toUnixTimestamp(timestamp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const ClientStats: ClientStatsResolvers = {
period,
clients: clientName === 'unknown' ? ['unknown', ''] : [clientName],
}),
operationsManager.readDetailedDurationPercentiles({
operationsManager.readDetailedDurationMetrics({
organizationId: organization,
projectId: project,
targetId: target,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { nsToMs } from '../../../shared/helpers';
import type { DurationValuesResolvers } from './../../../__generated__/types';

export const DurationValues: DurationValuesResolvers = {
avg: value => {
return transformPercentile(value.avg);
},
p75: value => {
return transformPercentile(value.p75);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const OperationsStats: OperationsStatsResolvers = {
operations: operationsFilter,
clients,
}),
operationsManager.readDetailedDurationPercentiles({
operationsManager.readDetailedDurationMetrics({
organizationId: organization,
projectId: project,
targetId: target,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const SchemaCoordinateStats: SchemaCoordinateStatsResolvers = {
period,
schemaCoordinate,
}),
operationsManager.readDetailedDurationPercentiles({
operationsManager.readDetailedDurationMetrics({
organizationId: organization,
projectId: project,
targetId: target,
Expand Down
Loading
Loading