Skip to content

Commit

Permalink
Merge branch 'main' into fix-node-roles-list
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyghiani committed Oct 3, 2023
2 parents d6b36aa + fe7d2eb commit 0099b55
Show file tree
Hide file tree
Showing 66 changed files with 968 additions and 172 deletions.
13 changes: 5 additions & 8 deletions x-pack/plugins/aiops/server/plugin.ts
Expand Up @@ -10,8 +10,6 @@ import { Subscription } from 'rxjs';
import { PluginInitializerContext, CoreSetup, CoreStart, Plugin, Logger } from '@kbn/core/server';
import type { DataRequestHandlerContext } from '@kbn/data-plugin/server';
import type { UsageCounter } from '@kbn/usage-collection-plugin/server';

import { CASES_ATTACHMENT_CHANGE_POINT_CHART } from '../common/constants';
import { PLUGIN_ID } from '../common';
import { isActiveLicense } from './lib/license';
import {
Expand All @@ -24,6 +22,7 @@ import {

import { defineLogRateAnalysisRoute } from './routes';
import { defineLogCategorizationRoutes } from './routes/log_categorization';
import { registerCasesPersistableState } from './register_cases';

export class AiopsPlugin
implements Plugin<AiopsPluginSetup, AiopsPluginStart, AiopsPluginSetupDeps, AiopsPluginStartDeps>
Expand All @@ -49,6 +48,10 @@ export class AiopsPlugin
const aiopsLicense: AiopsLicense = { isActivePlatinumLicense: false };
this.licenseSubscription = plugins.licensing.license$.subscribe(async (license) => {
aiopsLicense.isActivePlatinumLicense = isActiveLicense('platinum', license);

if (aiopsLicense.isActivePlatinumLicense) {
registerCasesPersistableState(plugins.cases, this.logger);
}
});

const router = core.http.createRouter<DataRequestHandlerContext>();
Expand All @@ -59,12 +62,6 @@ export class AiopsPlugin
defineLogCategorizationRoutes(router, aiopsLicense, this.usageCounter);
});

if (plugins.cases) {
plugins.cases.attachmentFramework.registerPersistableState({
id: CASES_ATTACHMENT_CHANGE_POINT_CHART,
});
}

return {};
}

Expand Down
24 changes: 24 additions & 0 deletions x-pack/plugins/aiops/server/register_cases.ts
@@ -0,0 +1,24 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { Logger } from '@kbn/core/server';
import type { CasesSetup } from '@kbn/cases-plugin/server';
import { CASES_ATTACHMENT_CHANGE_POINT_CHART } from '../common/constants';

export function registerCasesPersistableState(cases: CasesSetup | undefined, logger: Logger) {
if (cases) {
try {
cases.attachmentFramework.registerPersistableState({
id: CASES_ATTACHMENT_CHANGE_POINT_CHART,
});
} catch (error) {
logger.warn(
`AIOPs failed to register cases persistable state for ${CASES_ATTACHMENT_CHANGE_POINT_CHART}`
);
}
}
}
4 changes: 2 additions & 2 deletions x-pack/plugins/aiops/server/types.ts
Expand Up @@ -6,13 +6,13 @@
*/

import type { PluginSetup, PluginStart } from '@kbn/data-plugin/server';
import type { LicensingPluginStart } from '@kbn/licensing-plugin/server';
import type { LicensingPluginSetup } from '@kbn/licensing-plugin/server';
import type { CasesSetup } from '@kbn/cases-plugin/server';
import type { UsageCollectionSetup } from '@kbn/usage-collection-plugin/server';

export interface AiopsPluginSetupDeps {
data: PluginSetup;
licensing: LicensingPluginStart;
licensing: LicensingPluginSetup;
cases?: CasesSetup;
usageCollection?: UsageCollectionSetup;
}
Expand Down
Expand Up @@ -20,6 +20,7 @@ import { renderWithTheme } from '../../../utils/test_helpers';
import { fromQuery } from '../links/url_helpers';
import { CoreStart } from '@kbn/core/public';
import { SearchBar } from './search_bar';
import { ApmTimeRangeMetadataContextProvider } from '../../../context/time_range_metadata/time_range_metadata_context';

function setup({
urlParams,
Expand All @@ -36,8 +37,12 @@ function setup({
});

const KibanaReactContext = createKibanaReactContext({
usageCollection: { reportUiCounter: () => {} },
dataViews: { get: async () => {} },
usageCollection: {
reportUiCounter: () => {},
},
dataViews: {
get: async () => {},
},
data: {
query: {
queryString: {
Expand Down Expand Up @@ -75,9 +80,11 @@ function setup({
<KibanaReactContext.Provider>
<MockApmPluginContextWrapper history={history}>
<UrlParamsProvider>
<ApmServiceContextProvider>
<SearchBar showTransactionTypeSelector />
</ApmServiceContextProvider>
<ApmTimeRangeMetadataContextProvider>
<ApmServiceContextProvider>
<SearchBar showTransactionTypeSelector />
</ApmServiceContextProvider>
</ApmTimeRangeMetadataContextProvider>
</UrlParamsProvider>
</MockApmPluginContextWrapper>
</KibanaReactContext.Provider>
Expand Down
Expand Up @@ -8,6 +8,7 @@
import React, { createContext, ReactNode } from 'react';
import { useHistory } from 'react-router-dom';
import { History } from 'history';
import { ApmDocumentType } from '../../../common/document_type';
import { getDefaultTransactionType } from '../../../common/transaction_types';
import { useServiceTransactionTypesFetcher } from './use_service_transaction_types_fetcher';
import { useServiceAgentFetcher } from './use_service_agent_fetcher';
Expand All @@ -17,6 +18,7 @@ import { useFallbackToTransactionsFetcher } from '../../hooks/use_fallback_to_tr
import { replace } from '../../components/shared/links/url_helpers';
import { FETCH_STATUS } from '../../hooks/use_fetcher';
import { ServerlessType } from '../../../common/serverless';
import { usePreferredDataSourceAndBucketSize } from '../../hooks/use_preferred_data_source_and_bucket_size';

export interface APMServiceContextValue {
serviceName: string;
Expand Down Expand Up @@ -67,11 +69,21 @@ export function ApmServiceContextProvider({
end,
});

const preferred = usePreferredDataSourceAndBucketSize({
start,
end,
kuery,
type: ApmDocumentType.TransactionMetric,
numBuckets: 100,
});

const { transactionTypes, status: transactionTypeStatus } =
useServiceTransactionTypesFetcher({
serviceName,
start,
end,
documentType: preferred?.source.documentType,
rollupInterval: preferred?.source.rollupInterval,
});

const currentTransactionType = getOrRedirectToTransactionType({
Expand Down
Expand Up @@ -6,33 +6,39 @@
*/

import { useFetcher } from '../../hooks/use_fetcher';
import { RollupInterval } from '../../../common/rollup';
import { ApmTransactionDocumentType } from '../../../common/document_type';

const INITIAL_DATA = { transactionTypes: [] };

export function useServiceTransactionTypesFetcher({
serviceName,
start,
end,
documentType,
rollupInterval,
}: {
serviceName?: string;
start?: string;
end?: string;
documentType?: ApmTransactionDocumentType;
rollupInterval?: RollupInterval;
}) {
const { data = INITIAL_DATA, status } = useFetcher(
(callApmApi) => {
if (serviceName && start && end) {
if (serviceName && start && end && documentType && rollupInterval) {
return callApmApi(
'GET /internal/apm/services/{serviceName}/transaction_types',
{
params: {
path: { serviceName },
query: { start, end },
query: { start, end, documentType, rollupInterval },
},
}
);
}
},
[serviceName, start, end]
[serviceName, start, end, documentType, rollupInterval]
);

return { transactionTypes: data.transactionTypes, status };
Expand Down
Expand Up @@ -12,6 +12,12 @@ import { getBucketSize } from '../../common/utils/get_bucket_size';
import { getPreferredBucketSizeAndDataSource } from '../../common/utils/get_preferred_bucket_size_and_data_source';
import { useTimeRangeMetadata } from '../context/time_range_metadata/use_time_range_metadata_context';

/**
* Hook to get the source and interval based on Time Range Metadata API
*
* @param {number} numBuckets - The number of buckets. Should be 20 for SparkPlots or 100 for Other charts.
*/
export function usePreferredDataSourceAndBucketSize<
TDocumentType extends
| ApmDocumentType.ServiceTransactionMetric
Expand Down
Expand Up @@ -15,7 +15,7 @@ import {
import { RollupInterval } from '../../../../common/rollup';
import { termQuery } from '../../../../common/utils/term_query';
import { getDocumentTypeFilterForServiceDestinationStatistics } from '../spans/get_is_using_service_destination_metrics';
import { getDocumentTypeFilterForTransactions } from '../transactions';
import { getBackwardCompatibleDocumentTypeFilter } from '../transactions';

const defaultRollupIntervals = [
RollupInterval.OneMinute,
Expand Down Expand Up @@ -66,7 +66,7 @@ const documentTypeConfigMap: Record<
bool: {
filter:
rollupInterval === RollupInterval.OneMinute
? getDocumentTypeFilterForTransactions(true)
? getBackwardCompatibleDocumentTypeFilter(true)
: getDefaultFilter('transaction', rollupInterval),
},
}),
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/apm/server/lib/helpers/transactions/index.ts
Expand Up @@ -121,7 +121,8 @@ export function getDurationFieldForTransactions(
return TRANSACTION_DURATION;
}

export function getDocumentTypeFilterForTransactions(
// The function returns Document type filter for 1m Transaction Metrics
export function getBackwardCompatibleDocumentTypeFilter(
searchAggregatedTransactions: boolean
) {
return searchAggregatedTransactions
Expand Down
Expand Up @@ -17,7 +17,7 @@ import { offsetPreviousPeriodCoordinates } from '../../../common/utils/offset_pr
import { environmentQuery } from '../../../common/utils/environment_query';
import { Coordinate } from '../../../typings/timeseries';
import {
getDocumentTypeFilterForTransactions,
getBackwardCompatibleDocumentTypeFilter,
getProcessorEventForTransactions,
} from '../helpers/transactions';
import { getBucketSizeForAggregatedTransactions } from '../helpers/get_bucket_size_for_aggregated_transactions';
Expand Down Expand Up @@ -66,7 +66,7 @@ export async function getColdstartRate({
{ exists: { field: FAAS_COLDSTART } },
...(transactionName ? termQuery(TRANSACTION_NAME, transactionName) : []),
...termQuery(TRANSACTION_TYPE, transactionType),
...getDocumentTypeFilterForTransactions(searchAggregatedTransactions),
...getBackwardCompatibleDocumentTypeFilter(searchAggregatedTransactions),
...rangeQuery(startWithOffset, endWithOffset),
...environmentQuery(environment),
...kqlQuery(kuery),
Expand Down
Expand Up @@ -24,7 +24,7 @@ import { environmentQuery } from '../../../../../common/utils/environment_query'
import { AlertParams, PreviewChartResponse } from '../../route';
import {
getSearchTransactionsEvents,
getDocumentTypeFilterForTransactions,
getBackwardCompatibleDocumentTypeFilter,
getDurationFieldForTransactions,
getProcessorEventForTransactions,
} from '../../../../lib/helpers/transactions';
Expand Down Expand Up @@ -89,7 +89,9 @@ export async function getTransactionDurationChartPreview({
...termFilterQuery,
...getParsedFilterQuery(searchConfiguration?.query?.query as string),
...rangeQuery(start, end),
...getDocumentTypeFilterForTransactions(searchAggregatedTransactions),
...getBackwardCompatibleDocumentTypeFilter(
searchAggregatedTransactions
),
] as QueryDslQueryContainer[],
},
};
Expand Down
Expand Up @@ -50,7 +50,7 @@ import {
getDurationFormatter,
} from '../../../../../common/utils/formatters';
import {
getDocumentTypeFilterForTransactions,
getBackwardCompatibleDocumentTypeFilter,
getDurationFieldForTransactions,
} from '../../../../lib/helpers/transactions';
import { apmActionVariables } from '../../action_variables';
Expand Down Expand Up @@ -167,7 +167,7 @@ export function registerTransactionDurationRuleType({
},
},
},
...getDocumentTypeFilterForTransactions(
...getBackwardCompatibleDocumentTypeFilter(
searchAggregatedTransactions
),
...termFilterQuery,
Expand Down
Expand Up @@ -21,7 +21,7 @@ import { environmentQuery } from '../../../../../common/utils/environment_query'
import { AlertParams, PreviewChartResponse } from '../../route';
import {
getSearchTransactionsEvents,
getDocumentTypeFilterForTransactions,
getBackwardCompatibleDocumentTypeFilter,
getProcessorEventForTransactions,
} from '../../../../lib/helpers/transactions';
import { APMConfig } from '../../../..';
Expand Down Expand Up @@ -96,7 +96,7 @@ export async function getTransactionErrorRateChartPreview({
searchConfiguration?.query?.query as string
),
...rangeQuery(start, end),
...getDocumentTypeFilterForTransactions(
...getBackwardCompatibleDocumentTypeFilter(
searchAggregatedTransactions
),
{
Expand Down
Expand Up @@ -50,7 +50,7 @@ import {
asDecimalOrInteger,
getAlertUrlTransaction,
} from '../../../../../common/utils/formatters';
import { getDocumentTypeFilterForTransactions } from '../../../../lib/helpers/transactions';
import { getBackwardCompatibleDocumentTypeFilter } from '../../../../lib/helpers/transactions';
import { apmActionVariables } from '../../action_variables';
import { alertingEsClient } from '../../alerting_es_client';
import {
Expand Down Expand Up @@ -169,7 +169,7 @@ export function registerTransactionErrorRateRuleType({
},
},
},
...getDocumentTypeFilterForTransactions(
...getBackwardCompatibleDocumentTypeFilter(
searchAggregatedTransactions
),
{
Expand Down
Expand Up @@ -13,7 +13,7 @@ import { LatencyDistributionChartType } from '../../../../common/latency_distrib
import { getCommonCorrelationsQuery } from './get_common_correlations_query';
import { getDurationField, getEventType } from '../utils';
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
import { getDocumentTypeFilterForTransactions } from '../../../lib/helpers/transactions';
import { getBackwardCompatibleDocumentTypeFilter } from '../../../lib/helpers/transactions';

const getHistogramRangeSteps = (min: number, max: number, steps: number) => {
// A d3 based scale function as a helper to get equally distributed bins on a log scale.
Expand Down Expand Up @@ -66,7 +66,7 @@ export const fetchDurationHistogramRangeSteps = async ({
const filteredQuery = searchMetrics
? {
bool: {
filter: [query, ...getDocumentTypeFilterForTransactions(true)],
filter: [query, ...getBackwardCompatibleDocumentTypeFilter(true)],
},
}
: query;
Expand Down
Expand Up @@ -11,7 +11,7 @@ import { getCommonCorrelationsQuery } from './get_common_correlations_query';
import { CommonCorrelationsQueryParams } from '../../../../common/correlations/types';
import { getDurationField, getEventType } from '../utils';
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
import { getDocumentTypeFilterForTransactions } from '../../../lib/helpers/transactions';
import { getBackwardCompatibleDocumentTypeFilter } from '../../../lib/helpers/transactions';

export const fetchDurationPercentiles = async ({
chartType,
Expand All @@ -36,7 +36,7 @@ export const fetchDurationPercentiles = async ({
const filteredQuery = searchMetrics
? {
bool: {
filter: [query, ...getDocumentTypeFilterForTransactions(true)],
filter: [query, ...getBackwardCompatibleDocumentTypeFilter(true)],
},
}
: query;
Expand Down
Expand Up @@ -12,7 +12,7 @@ import { getCommonCorrelationsQuery } from './get_common_correlations_query';
import { Environment } from '../../../../common/environment_rt';
import { getDurationField, getEventType } from '../utils';
import { APMEventClient } from '../../../lib/helpers/create_es_client/create_apm_event_client';
import { getDocumentTypeFilterForTransactions } from '../../../lib/helpers/transactions';
import { getBackwardCompatibleDocumentTypeFilter } from '../../../lib/helpers/transactions';

export const fetchDurationRanges = async ({
rangeSteps,
Expand Down Expand Up @@ -42,7 +42,7 @@ export const fetchDurationRanges = async ({
const filteredQuery = searchMetrics
? {
bool: {
filter: [query, ...getDocumentTypeFilterForTransactions(true)],
filter: [query, ...getBackwardCompatibleDocumentTypeFilter(true)],
},
}
: query;
Expand Down

0 comments on commit 0099b55

Please sign in to comment.