Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into billing-ftr
Browse files Browse the repository at this point in the history
  • Loading branch information
CohenIdo committed Jul 4, 2024
2 parents e31300b + 13b3de2 commit 48836e3
Show file tree
Hide file tree
Showing 97 changed files with 3,108 additions and 1,262 deletions.
3 changes: 2 additions & 1 deletion .backportrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"repoName": "kibana",
"targetBranchChoices": [
"main",
"8.15",
"8.14",
"8.13",
"8.12",
Expand Down Expand Up @@ -51,7 +52,7 @@
"backport"
],
"branchLabelMapping": {
"^v8.15.0$": "main",
"^v8.16.0$": "main",
"^v(\\d+).(\\d+).\\d+$": "$1.$2"
},
"autoMerge": true,
Expand Down
6 changes: 3 additions & 3 deletions docs/management/connectors/action-types/gemini.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ image::management/connectors/images/gemini-connector.png[{gemini} connector]

Name:: The name of the connector.
API URL:: The {gemini} request URL.
PROJECT ID:: The project which has Vertex AI endpoint enabled.
Project ID:: The project which has Vertex AI endpoint enabled.
Region:: The GCP region where the Vertex AI endpoint enabled.
Default model:: The GAI model for {gemini} to use. Current support is for the Google Gemini models, defaulting to gemini-1.5-pro-001. The model can be set on a per request basis by including a "model" parameter alongside the request body.
Credentials JSON:: The GCP service account JSON file for authentication.
Expand All @@ -47,7 +47,7 @@ image::management/connectors/images/gemini-params.png[{gemini} params test]

The {gemini} actions have the following configuration properties.

Body:: A stringified JSON payload sent to the {gemini} Invoke Model API URL. For example:
Body:: A stringified JSON payload sent to the {gemini} invoke model API. For example:
+
[source,text]
--
Expand All @@ -65,7 +65,7 @@ Body:: A stringified JSON payload sent to the {gemini} Invoke Model API URL
})
}
--
Model:: An optional string that will overwrite the connector's default model. For
Model:: An optional string that overwrites the connector's default model.

[float]
[[gemini-connector-networking-configuration]]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dashboarding"
],
"private": true,
"version": "8.15.0",
"version": "8.16.0",
"branch": "main",
"types": "./kibana.d.ts",
"tsdocMetadata": "./build/tsdoc-metadata.json",
Expand Down
3 changes: 2 additions & 1 deletion packages/deeplinks/observability/locators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* Side Public License, v 1.
*/

export * from './dataset_quality';
export * from './logs_explorer';
export * from './observability_logs_explorer';
export * from './observability_onboarding';
export * from './dataset_quality';
export * from './uptime';
23 changes: 23 additions & 0 deletions packages/deeplinks/observability/locators/uptime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { SerializableRecord } from '@kbn/utility-types';

export const uptimeOverviewLocatorID = 'UPTIME_OVERVIEW_LOCATOR';

export interface UptimeOverviewLocatorInfraParams extends SerializableRecord {
ip?: string;
host?: string;
container?: string;
pod?: string;
}

export interface UptimeOverviewLocatorParams extends SerializableRecord {
dateRangeStart?: string;
dateRangeEnd?: string;
search?: string;
}
1 change: 1 addition & 0 deletions packages/kbn-alerts-ui-shared/src/common/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export * from './use_load_alerting_framework_health';
export * from './use_create_rule';
export * from './use_update_rule';
export * from './use_resolve_rule';
export * from './use_get_alerts_group_aggregations_query';
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import React from 'react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { renderHook } from '@testing-library/react-hooks/dom';
import type { HttpStart } from '@kbn/core-http-browser';
import { ToastsStart } from '@kbn/core-notifications-browser';
import { AlertConsumers } from '@kbn/rule-data-utils';

import { useGetAlertsGroupAggregationsQuery } from './use_get_alerts_group_aggregations_query';
import { waitFor } from '@testing-library/react';
import { BASE_RAC_ALERTS_API_PATH } from '../constants';

const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: false,
},
},
});

const wrapper = ({ children }: { children: Node }) => (
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
);

const mockHttp = {
post: jest.fn(),
};
const http = mockHttp as unknown as HttpStart;

const mockToasts = {
addDanger: jest.fn(),
};
const toasts = mockToasts as unknown as ToastsStart;

const params = {
featureIds: [AlertConsumers.STACK_ALERTS],
groupByField: 'kibana.alert.rule.name',
};

describe('useAlertsGroupAggregationsQuery', () => {
afterEach(() => {
jest.clearAllMocks();
});

test('displays toast on errors', async () => {
mockHttp.post.mockRejectedValue(new Error('An error occurred'));
renderHook(
() =>
useGetAlertsGroupAggregationsQuery({
params,
enabled: true,
toasts,
http,
}),
{ wrapper }
);

await waitFor(() => expect(mockToasts.addDanger).toHaveBeenCalled());
});

test('calls API endpoint with the correct body', async () => {
renderHook(
() =>
useGetAlertsGroupAggregationsQuery({
params,
enabled: true,
toasts,
http,
}),
{ wrapper }
);

await waitFor(() =>
expect(mockHttp.post).toHaveBeenLastCalledWith(
`${BASE_RAC_ALERTS_API_PATH}/_group_aggregations`,
{
body: JSON.stringify(params),
}
)
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { i18n } from '@kbn/i18n';
import { useQuery } from '@tanstack/react-query';
import type { HttpStart } from '@kbn/core-http-browser';
import type { ToastsStart } from '@kbn/core-notifications-browser';
import { SearchResponseBody } from '@elastic/elasticsearch/lib/api/types';
import { AlertConsumers } from '@kbn/rule-data-utils';
import type {
AggregationsAggregationContainer,
QueryDslQueryContainer,
SortCombinations,
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { BASE_RAC_ALERTS_API_PATH } from '../constants';

export interface UseGetAlertsGroupAggregationsQueryProps {
http: HttpStart;
toasts: ToastsStart;
enabled?: boolean;
params: {
featureIds: AlertConsumers[];
groupByField: string;
aggregations?: Record<string, AggregationsAggregationContainer>;
filters?: QueryDslQueryContainer[];
sort?: SortCombinations[];
pageIndex?: number;
pageSize?: number;
};
}

/**
* Fetches alerts aggregations for a given groupByField.
*
* Some default aggregations are applied:
* - `groupByFields`, to get the buckets based on the provided grouping field,
* - `unitsCount`, to count the number of alerts in each bucket,
* - `unitsCount`, to count the total number of alerts targeted by the query,
* - `groupsCount`, to count the total number of groups.
*
* The provided `aggregations` are applied within `groupByFields`. Here the `groupByField` runtime
* field can be used to perform grouping-based aggregations.
*
* Applies alerting RBAC through featureIds.
*/
export const useGetAlertsGroupAggregationsQuery = <T>({
http,
toasts,
enabled = true,
params,
}: UseGetAlertsGroupAggregationsQueryProps) => {
const onErrorFn = (error: Error) => {
if (error) {
toasts.addDanger(
i18n.translate(
'alertsUIShared.hooks.useFindAlertsQuery.unableToFetchAlertsGroupingAggregations',
{
defaultMessage: 'Unable to fetch alerts grouping aggregations',
}
)
);
}
};

return useQuery({
queryKey: ['getAlertsGroupAggregations', JSON.stringify(params)],
queryFn: () =>
http.post<SearchResponseBody<{}, T>>(`${BASE_RAC_ALERTS_API_PATH}/_group_aggregations`, {
body: JSON.stringify(params),
}),
onError: onErrorFn,
refetchOnWindowFocus: false,
enabled,
});
};
28 changes: 3 additions & 25 deletions packages/kbn-openapi-generator/src/parser/lib/get_circular_refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import type { OpenApiDocument } from '../openapi_types';
import type { PlainObject } from './helpers/plain_object';
import { extractByJsonPointer } from './helpers/extract_by_json_pointer';
import { findRefs } from './find_refs';
import { findLocalRefs } from './helpers/find_local_refs';
import { parseRef } from './helpers/parse_ref';

/**
* Extracts circular references from a provided document.
Expand All @@ -19,7 +20,7 @@ export function getCircularRefs(document: OpenApiDocument): Set<string> {
const localRefs = findLocalRefs(document);
const circularRefs = new Set<string>();
const resolveLocalRef = (localRef: string): PlainObject =>
extractByJsonPointer(document, extractJsonPointer(localRef));
extractByJsonPointer(document, parseRef(localRef).pointer);

// In general references represent a disconnected graph. To find
// all references cycles we need to check each reference.
Expand Down Expand Up @@ -80,26 +81,3 @@ function findCycleHeadRef(

return result;
}

/**
* Finds local references
*/
function findLocalRefs(obj: unknown): string[] {
return findRefs(obj).filter((ref) => isLocalRef(ref));
}

/**
* Checks whether the provided ref is local.
* Local references start with `#/`
*/
function isLocalRef(ref: string): boolean {
return ref.startsWith('#/');
}

/**
* Extracts a JSON Pointer from a local reference
* by getting rid of the leading slash
*/
function extractJsonPointer(ref: string): string {
return ref.substring(1);
}
Loading

0 comments on commit 48836e3

Please sign in to comment.