Skip to content

Commit

Permalink
Add range params
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Apr 18, 2022
1 parent 67cd8ad commit 679fa7c
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
8 changes: 8 additions & 0 deletions x-pack/plugins/cases/common/api/metrics/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ export const CasesMetricsRequestRt = rt.intersection([
features: rt.array(rt.string),
}),
rt.partial({
/**
* A KQL date. If used all cases created after (gte) the from date will be returned
*/
from: rt.string,
/**
* A KQL date. If used all cases created before (lte) the to date will be returned.
*/
to: rt.string,
/**
* The owner(s) to filter by. The user making the request must have privileges to retrieve cases of that
* ownership or they will be ignored. If no owner is included, then all ownership types will be included in the response
Expand Down
8 changes: 7 additions & 1 deletion x-pack/plugins/cases/server/client/metrics/all_cases/mttr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ export class MTTR extends AllCasesAggregationHandler {
Operations.getCaseMetrics
);

const caseQueryOptions = constructQueryOptions({ owner: this.owner, authorizationFilter });
const caseQueryOptions = constructQueryOptions({
from: this.from,
to: this.to,
owner: this.owner,
authorizationFilter,
});

const aggregationsResponse = await caseService.executeAggregations({
aggregationBuilders: this.aggregationBuilders,
options: { filter: caseQueryOptions.filter },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ import { AggregationHandler } from './aggregation_handler';
import { AggregationBuilder, AllCasesBaseHandlerCommonOptions } from './types';

export abstract class AllCasesAggregationHandler extends AggregationHandler<CasesMetricsResponse> {
protected readonly from?: string;
protected readonly to?: string;
protected readonly owner?: string | string[];

constructor(
options: AllCasesBaseHandlerCommonOptions,
aggregations: Map<string, AggregationBuilder<CasesMetricsResponse>>
) {
const { owner, ...restOptions } = options;
const { owner, from, to, ...restOptions } = options;
super(restOptions, aggregations);

this.from = from;
this.to = to;
this.owner = owner;
}
}
2 changes: 2 additions & 0 deletions x-pack/plugins/cases/server/client/metrics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ export interface SingleCaseBaseHandlerCommonOptions extends BaseHandlerCommonOpt
}

export interface AllCasesBaseHandlerCommonOptions extends BaseHandlerCommonOptions {
from?: string;
to?: string;
owner?: string | string[];
}
9 changes: 8 additions & 1 deletion x-pack/plugins/cases/server/client/metrics/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ export const buildHandlers = (
);
} else {
handlers = [MTTR].map(
(ClassName) => new ClassName({ owner: params.owner, casesClient, clientArgs })
(ClassName) =>
new ClassName({
owner: params.owner,
from: params.from,
to: params.to,
casesClient,
clientArgs,
})
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const getCasesMetricRoute = createCasesRoute({
query: schema.object({
features: schema.arrayOf(schema.string({ minLength: 1 })),
owner: schema.maybe(schema.oneOf([schema.arrayOf(schema.string()), schema.string()])),
from: schema.maybe(schema.string()),
to: schema.maybe(schema.string()),
}),
},
handler: async ({ context, request, response }) => {
Expand Down

0 comments on commit 679fa7c

Please sign in to comment.