Skip to content
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
2,666 changes: 1,338 additions & 1,328 deletions connect-go/gen/proto/wg/cosmo/platform/v1/platform.pb.go

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions connect/src/wg/cosmo/platform/v1/platform_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21889,6 +21889,11 @@ export class GetOperationsRequest extends Message<GetOperationsRequest> {
*/
clientName?: string;

/**
* @generated from field: optional int32 limit = 4;
*/
limit?: number;

constructor(data?: PartialMessage<GetOperationsRequest>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -21900,6 +21905,7 @@ export class GetOperationsRequest extends Message<GetOperationsRequest> {
{ no: 1, name: "federatedGraphName", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "namespace", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 3, name: "clientName", kind: "scalar", T: 9 /* ScalarType.STRING */, opt: true },
{ no: 4, name: "limit", kind: "scalar", T: 5 /* ScalarType.INT32 */, opt: true },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): GetOperationsRequest {
Expand Down
30 changes: 11 additions & 19 deletions controlplane/src/core/bufservices/analytics/getOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { PlainMessage } from '@bufbuild/protobuf';
import { HandlerContext } from '@connectrpc/connect';
import { EnumStatusCode } from '@wundergraph/cosmo-connect/dist/common/common_pb';
import {
AnalyticsFilter,
AnalyticsViewFilterOperator,
GetOperationsRequest,
GetOperationsResponse,
GetOperationsResponse_Operation,
GetOperationsResponse_OperationType,
AnalyticsViewFilterOperator,
AnalyticsFilter,
} from '@wundergraph/cosmo-connect/dist/platform/v1/platform_pb';
import { deafultRangeInHoursForGetOperations } from '../../constants.js';
import { MetricsRepository } from '../../repositories/analytics/MetricsRepository.js';
import { CacheWarmerRepository } from '../../repositories/CacheWarmerRepository.js';
import { FederatedGraphRepository } from '../../repositories/FederatedGraphRepository.js';
import { OrganizationRepository } from '../../repositories/OrganizationRepository.js';
import type { RouterOptions } from '../../routes.js';
import { enrichLogger, getLogger, handleError, validateDateRanges } from '../../util.js';
import { enrichLogger, getLogger, handleError } from '../../util.js';

export function getOperations(
opts: RouterOptions,
Expand All @@ -39,7 +39,6 @@ export function getOperations(
const metricsRepo = new MetricsRepository(opts.chClient);
const cacheWarmerRepo = new CacheWarmerRepository(opts.chClient, opts.db);
const fedGraphRepo = new FederatedGraphRepository(logger, opts.db, authContext.organizationId);
const orgRepo = new OrganizationRepository(logger, opts.db, opts.billingDefaultPlanId);

const graph = await fedGraphRepo.byName(req.federatedGraphName, req.namespace);
if (!graph) {
Expand All @@ -52,28 +51,20 @@ export function getOperations(
};
}

const analyticsRetention = await orgRepo.getFeature({
organizationId: authContext.organizationId,
featureId: 'analytics-retention',
});

const limit = analyticsRetention?.limit ?? 7;

const { range } = validateDateRanges({
limit,
range: limit * 24,
});

if (!range) {
req.limit = req.limit ?? 100;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
// Validate limit is within reasonable bounds
if (req.limit < 1 || req.limit > 1000) {
return {
response: {
code: EnumStatusCode.ERR,
details: 'Invalid date range',
details: 'Limit must be between 1 and 1000',
},
operations: [],
};
}

const range = deafultRangeInHoursForGetOperations;

const operations = await metricsRepo.getOperations({
range,
organizationId: authContext.organizationId,
Expand All @@ -87,6 +78,7 @@ export function getOperations(
}),
]
: [],
limit: req.limit,
});

if (operations.length === 0) {
Expand Down
2 changes: 2 additions & 0 deletions controlplane/src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export const apiKeyPermissions = [

export const delayForManualOrgDeletionInDays = 3;
export const delayForOrgAuditLogsDeletionInDays = 90;

export const deafultRangeInHoursForGetOperations = 7 * 24;
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ export class MetricsRepository {
});
}

public async getOperations(props: GetMetricsViewProps) {
public async getOperations(props: GetMetricsViewProps & { limit: number }) {
const { dateRange, organizationId, graphId, whereSql, queryParams } = this.getMetricsProps(props);

const query = `
Expand All @@ -746,14 +746,14 @@ export class MetricsRepository {
AND OrganizationID = '${organizationId}'
AND FederatedGraphID = '${graphId}'
${whereSql ? `AND ${whereSql}` : ''}
GROUP BY OperationName, OperationHash, OperationType ORDER BY latency DESC`;
GROUP BY OperationName, OperationHash, OperationType ORDER BY latency DESC LIMIT {limit:UInt32}`;

const res: {
operationHash: string;
operationName: string;
operationType: string;
latency: number;
}[] = await this.client.queryPromise(query, queryParams);
}[] = await this.client.queryPromise(query, { ...queryParams, limit: props.limit });

if (Array.isArray(res)) {
return res;
Expand Down
1 change: 1 addition & 0 deletions proto/wg/cosmo/platform/v1/platform.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2781,6 +2781,7 @@ message GetOperationsRequest {
string federatedGraphName = 1;
string namespace = 2;
optional string clientName = 3;
optional int32 limit = 4;
}

message GetOperationsResponse {
Expand Down
Loading