Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/elastic/kibana into alertin…
Browse files Browse the repository at this point in the history
…g/ux-minimum-rule-interval-2
  • Loading branch information
ymao1 committed Mar 23, 2022
2 parents ec5640c + daea5a8 commit 152a5f6
Show file tree
Hide file tree
Showing 64 changed files with 1,030 additions and 215 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/add-to-ao-project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Add issues to Actionable Observability project
on:
issues:
types: [labeled]
jobs:
sync_issues_with_table:
runs-on: ubuntu-latest
name: Add issues to project
if: |
github.event.label.name == 'Team: Actionable Observability'
steps:
- name: Add
uses: richkuz/projectnext-label-assigner@1.0.2
id: add_to_projects
with:
config: |
[
{"label": "Team: Actionable Observability", "projectNumber": 669}
]
env:
GRAPHQL_API_BASE: 'https://api.github.com'
PAT_TOKEN: ${{ secrets.PROJECT_ASSIGNER_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 1 addition & 2 deletions docs/api/cases/cases-api-find-cases.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ default space is used.
(Optional, string) The default operator to use for the `simple_query_string`.
Defaults to `OR`.

////
`fields`::
(Optional, array of strings) The fields in the entity to return in the response.
////

`owner`::
(Optional, string or array of strings) A filter to limit the retrieved cases to
a specific set of applications. Valid values are: `cases`, `observability`,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/common/api/cases/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const CasesFindRequestRt = rt.partial({
/**
* The fields in the entity to return in the response
*/
fields: rt.array(rt.string),
fields: rt.union([rt.array(rt.string), rt.string]),
/**
* The page of objects to return
*/
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/server/authorization/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ describe('utils', () => {
expect(includeFieldsRequiredForAuthentication()).toBeUndefined();
});

it('returns an array with a single entry containing the owner field', () => {
expect(includeFieldsRequiredForAuthentication([])).toStrictEqual([OWNER_FIELD]);
it('returns undefined when the fields parameter is an empty array', () => {
expect(includeFieldsRequiredForAuthentication([])).toBeUndefined();
});

it('returns an array without duplicates and including the owner field', () => {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/authorization/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const ensureFieldIsSafeForQuery = (field: string, value: string): boolean
};

export const includeFieldsRequiredForAuthentication = (fields?: string[]): string[] | undefined => {
if (fields === undefined) {
if (fields === undefined || fields.length === 0) {
return;
}
return uniq([...fields, OWNER_FIELD]);
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/cases/server/client/cases/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ export const find = async (
const { caseService, authorization, logger } = clientArgs;

try {
const fields = asArray(params.fields);

const queryParams = pipe(
excess(CasesFindRequestRt).decode(params),
excess(CasesFindRequestRt).decode({ ...params, fields }),
fold(throwErrors(Boom.badRequest), identity)
);

Expand Down Expand Up @@ -67,7 +69,7 @@ export const find = async (
...queryParams,
...caseQueryOptions,
searchFields: asArray(queryParams.searchFields),
fields: includeFieldsRequiredForAuthentication(queryParams.fields),
fields: includeFieldsRequiredForAuthentication(fields),
},
}),
caseService.getCaseStatusStats({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const TabComponent = (props: TabProps) => {

return (
<TabContent>
<OsqueryAction metadata={metadata} />
<OsqueryAction agentId={metadata?.info?.agent?.id} />
</TabContent>
);
}, [OsqueryAction, loading, metadata]);
Expand Down
46 changes: 15 additions & 31 deletions x-pack/plugins/ml/server/models/filter/filter_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,44 +41,28 @@ interface FiltersInUse {
[id: string]: FilterUsage;
}

// interface PartialDetector {
// detector_description: string;
// custom_rules: DetectorRule[];
// }

// interface PartialJob {
// job_id: string;
// analysis_config: {
// detectors: PartialDetector[];
// };
// }

export class FilterManager {
constructor(private _mlClient: MlClient) {}

async getFilter(filterId: string) {
try {
const [JOBS, FILTERS] = [0, 1];
const results = await Promise.all([
this._mlClient.getJobs(),
this._mlClient.getFilters({ filter_id: filterId }),
]);

if (results[FILTERS] && (results[FILTERS] as estypes.MlGetFiltersResponse).filters.length) {
let filtersInUse: FiltersInUse = {};
if (results[JOBS] && (results[JOBS] as estypes.MlGetJobsResponse).jobs) {
filtersInUse = this.buildFiltersInUse((results[JOBS] as estypes.MlGetJobsResponse).jobs);
}

const filter = (results[FILTERS] as estypes.MlGetFiltersResponse).filters[0];
return {
...filter,
used_by: filtersInUse[filter.filter_id],
item_count: 0,
} as FilterStats;
} else {
const {
filters: [filter],
} = await this._mlClient.getFilters({ filter_id: filterId });
if (filter === undefined) {
// could be an empty list rather than a 404 if a wildcard was used,
// so throw our own 404
throw Boom.notFound(`Filter with the id "${filterId}" not found`);
}

const { jobs } = await this._mlClient.getJobs();
const filtersInUse = this.buildFiltersInUse(jobs);

return {
...filter,
used_by: filtersInUse[filter.filter_id],
item_count: 0,
} as FilterStats;
} catch (error) {
throw Boom.badRequest(error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface ObservabilityStatusContent {
learnMoreLink: string;
goToAppTitle: string;
goToAppLink: string;
weight: number;
}

export const getContent = (
Expand All @@ -42,6 +43,7 @@ export const getContent = (
defaultMessage: 'Show log stream',
}),
goToAppLink: http.basePath.prepend('/app/logs/stream'),
weight: 1,
},
{
id: 'apm',
Expand All @@ -61,6 +63,7 @@ export const getContent = (
defaultMessage: 'Show services inventory',
}),
goToAppLink: http.basePath.prepend('/app/apm/services'),
weight: 3,
},
{
id: 'infra_metrics',
Expand All @@ -79,6 +82,7 @@ export const getContent = (
defaultMessage: 'Show inventory',
}),
goToAppLink: http.basePath.prepend('/app/metrics/inventory'),
weight: 2,
},
{
id: 'synthetics',
Expand All @@ -97,6 +101,7 @@ export const getContent = (
defaultMessage: 'Show monitors ',
}),
goToAppLink: http.basePath.prepend('/app/uptime'),
weight: 4,
},
{
id: 'ux',
Expand All @@ -116,6 +121,7 @@ export const getContent = (
defaultMessage: 'Show dashboard',
}),
goToAppLink: http.basePath.prepend('/app/ux'),
weight: 5,
},
{
id: 'alert',
Expand All @@ -135,6 +141,7 @@ export const getContent = (
defaultMessage: 'Show alerts',
}),
goToAppLink: http.basePath.prepend('/app/observability/alerts'),
weight: 6,
},
];
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const testBoxes = [
goToAppLink: '/app/logs/stream',
hasData: false,
modules: [],
weight: 1,
},
{
id: 'apm',
Expand All @@ -40,6 +41,7 @@ const testBoxes = [
goToAppLink: '/app/apm/services',
hasData: false,
modules: [],
weight: 2,
},
{
id: 'infra_metrics',
Expand All @@ -52,6 +54,7 @@ const testBoxes = [
goToAppLink: '/app/metrics/inventory',
hasData: false,
modules: [],
weight: 3,
},
{
id: 'synthetics',
Expand All @@ -64,6 +67,7 @@ const testBoxes = [
goToAppLink: '/app/uptime',
hasData: false,
modules: [],
weight: 4,
},
{
id: 'ux',
Expand All @@ -77,6 +81,7 @@ const testBoxes = [
goToAppLink: '/app/ux',
hasData: true,
modules: [],
weight: 5,
},
{
id: 'alert',
Expand All @@ -90,6 +95,7 @@ const testBoxes = [
goToAppLink: '/app/observability/alerts',
hasData: true,
modules: [],
weight: 6,
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('ObservabilityStatusBox', () => {
learnMoreLink: 'learnMoreUrl.com',
goToAppTitle: 'go to app title',
goToAppLink: 'go to app link',
weight: 1,
};

render(
Expand Down Expand Up @@ -60,6 +61,7 @@ describe('ObservabilityStatusBox', () => {
learnMoreLink: 'http://example.com',
goToAppTitle: 'go to app title',
goToAppLink: 'go to app link',
weight: 1,
};

render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface ObservabilityStatusBoxProps {
learnMoreLink: string;
goToAppTitle: string;
goToAppLink: string;
weight: number;
}

export function ObservabilityStatusBox(props: ObservabilityStatusBoxProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('ObservabilityStatusBoxes', () => {
learnMoreLink: 'http://example.com',
goToAppTitle: 'go to app title',
goToAppLink: 'go to app link',
weight: 2,
},
{
id: 'metrics',
Expand All @@ -36,6 +37,7 @@ describe('ObservabilityStatusBoxes', () => {
learnMoreLink: 'http://example.com',
goToAppTitle: 'go to app title',
goToAppLink: 'go to app link',
weight: 1,
},
];

Expand All @@ -48,4 +50,45 @@ describe('ObservabilityStatusBoxes', () => {
expect(screen.getByText('Logs')).toBeInTheDocument();
expect(screen.getByText('Metrics')).toBeInTheDocument();
});

it('should render elements by order', () => {
const boxes = [
{
id: 'logs',
title: 'Logs',
hasData: true,
description: 'This is the description for logs',
modules: [],
addTitle: 'logs add title',
addLink: 'http://example.com',
learnMoreLink: 'http://example.com',
goToAppTitle: 'go to app title',
goToAppLink: 'go to app link',
weight: 2,
},
{
id: 'metrics',
title: 'Metrics',
hasData: true,
description: 'This is the description for metrics',
modules: [],
addTitle: 'metrics add title',
addLink: 'http://example.com',
learnMoreLink: 'http://example.com',
goToAppTitle: 'go to app title',
goToAppLink: 'go to app link',
weight: 1,
},
];

render(
<I18nProvider>
<ObservabilityStatusBoxes boxes={boxes} />
</I18nProvider>
);

const content = screen.getAllByTestId(/box-*/);
expect(content[0]).toHaveTextContent('Metrics');
expect(content[1]).toHaveTextContent('Logs');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ export interface ObservabilityStatusProps {
boxes: ObservabilityStatusBoxProps[];
}

const sortingFn = (a: ObservabilityStatusBoxProps, b: ObservabilityStatusBoxProps) => {
return a.weight - b.weight;
};

export function ObservabilityStatusBoxes({ boxes }: ObservabilityStatusProps) {
const hasDataBoxes = boxes.filter((box) => box.hasData);
const noHasDataBoxes = boxes.filter((box) => !box.hasData);
const hasDataBoxes = boxes.filter((box) => box.hasData).sort(sortingFn);
const noHasDataBoxes = boxes.filter((box) => !box.hasData).sort(sortingFn);

return (
<EuiFlexGroup direction="column">
Expand All @@ -34,7 +38,7 @@ export function ObservabilityStatusBoxes({ boxes }: ObservabilityStatusProps) {
</EuiTitle>
</EuiFlexItem>
{noHasDataBoxes.map((box) => (
<EuiFlexItem key={box.id}>
<EuiFlexItem key={box.id} data-test-id={`box-${box.id}`}>
<EmptyStatusBox {...box} />
</EuiFlexItem>
))}
Expand All @@ -52,7 +56,7 @@ export function ObservabilityStatusBoxes({ boxes }: ObservabilityStatusProps) {
</EuiTitle>
</EuiFlexItem>
{hasDataBoxes.map((box) => (
<EuiFlexItem key={box.id}>
<EuiFlexItem key={box.id} data-test-subj={`box-${box.id}`}>
<CompletedStatusBox {...box} />
</EuiFlexItem>
))}
Expand Down
Loading

0 comments on commit 152a5f6

Please sign in to comment.