Skip to content

Commit

Permalink
Merge branch 'main' into rename_layer_types
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Dec 3, 2021
2 parents 031d9b8 + c7a06cd commit b079de9
Show file tree
Hide file tree
Showing 84 changed files with 1,269 additions and 1,031 deletions.
13 changes: 10 additions & 3 deletions packages/kbn-utils/src/path/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@
*/

import { accessSync, constants } from 'fs';
import { createAbsolutePathSerializer } from '@kbn/dev-utils';
import { getConfigPath, getDataPath, getLogsPath, getConfigDirectory } from './';

expect.addSnapshotSerializer(createAbsolutePathSerializer());
import { REPO_ROOT } from '../repo_root';

expect.addSnapshotSerializer(
((rootPath: string = REPO_ROOT, replacement = '<absolute path>') => {
return {
test: (value: any) => typeof value === 'string' && value.startsWith(rootPath),
serialize: (value: string) => value.replace(rootPath, replacement).replace(/\\/g, '/'),
};
})()
);

describe('Default path finder', () => {
it('should expose a path to the config directory', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
getFailedTransactionRateTimeSeries,
} from '../helpers/transaction_error_rate';

export async function getErrorRate({
export async function getFailedTransactionRate({
environment,
kuery,
serviceName,
Expand Down Expand Up @@ -122,7 +122,7 @@ export async function getErrorRate({
return { timeseries, average };
}

export async function getErrorRatePeriods({
export async function getFailedTransactionRatePeriods({
environment,
kuery,
serviceName,
Expand Down Expand Up @@ -157,11 +157,15 @@ export async function getErrorRatePeriods({
searchAggregatedTransactions,
};

const currentPeriodPromise = getErrorRate({ ...commonProps, start, end });
const currentPeriodPromise = getFailedTransactionRate({
...commonProps,
start,
end,
});

const previousPeriodPromise =
comparisonStart && comparisonEnd
? getErrorRate({
? getFailedTransactionRate({
...commonProps,
start: comparisonStart,
end: comparisonEnd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
getDurationFieldForTransactions,
getProcessorEventForTransactions,
} from '../../lib/helpers/transactions';
import { getErrorRate } from '../../lib/transaction_groups/get_error_rate';
import { getFailedTransactionRate } from '../../lib/transaction_groups/get_failed_transaction_rate';
import { withApmSpan } from '../../utils/with_apm_span';
import {
percentCgroupMemoryUsedScript,
Expand Down Expand Up @@ -123,7 +123,7 @@ async function getFailedTransactionsRateStats({
numBuckets,
}: TaskParameters): Promise<NodeStats['failedTransactionsRate']> {
return withApmSpan('get_error_rate_for_service_map_node', async () => {
const { average, timeseries } = await getErrorRate({
const { average, timeseries } = await getFailedTransactionRate({
environment,
setup,
serviceName,
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/server/routes/transactions/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { getServiceTransactionGroupDetailedStatisticsPeriods } from '../services
import { getTransactionBreakdown } from './breakdown';
import { getTransactionTraceSamples } from './trace_samples';
import { getLatencyPeriods } from './get_latency_charts';
import { getErrorRatePeriods } from '../../lib/transaction_groups/get_error_rate';
import { getFailedTransactionRatePeriods } from '../../lib/transaction_groups/get_failed_transaction_rate';
import { createApmServerRoute } from '../apm_routes/create_apm_server_route';
import { createApmServerRouteRepository } from '../apm_routes/create_apm_server_route_repository';
import {
Expand Down Expand Up @@ -349,7 +349,7 @@ const transactionChartsErrorRateRoute = createApmServerRoute({
end,
});

return getErrorRatePeriods({
return getFailedTransactionRatePeriods({
environment,
kuery,
serviceName,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export * from './services';
export * from './types';
export type { FleetAuthz } from './authz';
export { calculateAuthz } from './authz';
export { createFleetAuthzMock } from './mocks';
27 changes: 26 additions & 1 deletion x-pack/plugins/fleet/common/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* 2.0.
*/

import type { NewPackagePolicy, PackagePolicy, DeletePackagePoliciesResponse } from './types';
import type { DeletePackagePoliciesResponse, NewPackagePolicy, PackagePolicy } from './types';
import type { FleetAuthz } from './authz';

export const createNewPackagePolicyMock = (): NewPackagePolicy => {
return {
Expand Down Expand Up @@ -56,3 +57,27 @@ export const deletePackagePolicyMock = (): DeletePackagePoliciesResponse => {
},
];
};

/**
* Creates mock `authz` object
*/
export const createFleetAuthzMock = (): FleetAuthz => {
return {
fleet: {
all: true,
setup: true,
readEnrollmentTokens: true,
},
integrations: {
readPackageInfo: true,
readInstalledPackages: true,
installPackages: true,
upgradePackages: true,
removePackages: true,
readPackageSettings: true,
writePackageSettings: true,
readIntegrationPolicies: true,
writeIntegrationPolicies: true,
},
};
};
30 changes: 3 additions & 27 deletions x-pack/plugins/fleet/server/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import { of } from 'rxjs';

import {
coreMock,
elasticsearchServiceMock,
loggingSystemMock,
savedObjectsServiceMock,
coreMock,
savedObjectsClientMock,
savedObjectsServiceMock,
} from '../../../../../src/core/server/mocks';
import { dataPluginMock } from '../../../../../src/plugins/data/server/mocks';
import { licensingMock } from '../../../../plugins/licensing/server/mocks';
Expand All @@ -21,7 +21,7 @@ import type { PackagePolicyServiceInterface } from '../services/package_policy';
import type { AgentPolicyServiceInterface, PackageService } from '../services';
import type { FleetAppContext } from '../plugin';
import { createMockTelemetryEventsSender } from '../telemetry/__mocks__';
import type { FleetAuthz } from '../../common';
import { createFleetAuthzMock } from '../../common';
import { agentServiceMock } from '../services/agents/agent_service.mock';
import type { FleetRequestHandlerContext } from '../types';

Expand Down Expand Up @@ -145,27 +145,3 @@ export const createMockPackageService = (): PackageService => {
ensureInstalledPackage: jest.fn(),
};
};

/**
* Creates mock `authz` object
*/
export const createFleetAuthzMock = (): FleetAuthz => {
return {
fleet: {
all: true,
setup: true,
readEnrollmentTokens: true,
},
integrations: {
readPackageInfo: true,
readInstalledPackages: true,
installPackages: true,
upgradePackages: true,
removePackages: true,
readPackageSettings: true,
writePackageSettings: true,
readIntegrationPolicies: true,
writeIntegrationPolicies: true,
},
};
};
37 changes: 36 additions & 1 deletion x-pack/plugins/fleet/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import type { Observable } from 'rxjs';
import { BehaviorSubject } from 'rxjs';
import type {
CoreSetup,
CoreStart,
Expand All @@ -16,13 +17,18 @@ import type {
SavedObjectsServiceStart,
HttpServiceSetup,
KibanaRequest,
ServiceStatus,
ElasticsearchClient,
} from 'kibana/server';
import type { UsageCollectionSetup } from 'src/plugins/usage_collection/server';

import type { TelemetryPluginSetup, TelemetryPluginStart } from 'src/plugins/telemetry/server';

import { DEFAULT_APP_CATEGORIES, SavedObjectsClient } from '../../../../src/core/server';
import {
DEFAULT_APP_CATEGORIES,
SavedObjectsClient,
ServiceStatusLevels,
} from '../../../../src/core/server';
import type { PluginStart as DataPluginStart } from '../../../../src/plugins/data/server';
import type { LicensingPluginSetup, ILicense } from '../../licensing/server';
import type {
Expand Down Expand Up @@ -182,6 +188,7 @@ export class FleetPlugin
private securitySetup?: SecurityPluginSetup;
private encryptedSavedObjectsSetup?: EncryptedSavedObjectsPluginSetup;
private readonly telemetryEventsSender: TelemetryEventsSender;
private readonly fleetStatus$: BehaviorSubject<ServiceStatus>;

private agentService?: AgentService;

Expand All @@ -193,6 +200,11 @@ export class FleetPlugin
this.logger = this.initializerContext.logger.get();
this.configInitialValue = this.initializerContext.config.get();
this.telemetryEventsSender = new TelemetryEventsSender(this.logger.get('telemetry_events'));

this.fleetStatus$ = new BehaviorSubject<ServiceStatus>({
level: ServiceStatusLevels.unavailable,
summary: 'Fleet is unavailable',
});
}

public setup(core: CoreSetup, deps: FleetSetupDeps) {
Expand All @@ -203,6 +215,8 @@ export class FleetPlugin
this.securitySetup = deps.security;
const config = this.configInitialValue;

core.status.set(this.fleetStatus$.asObservable());

registerSavedObjects(core.savedObjects, deps.encryptedSavedObjects);
registerEncryptedSavedObjects(deps.encryptedSavedObjects);

Expand Down Expand Up @@ -357,13 +371,33 @@ export class FleetPlugin

const fleetSetupPromise = (async () => {
try {
this.fleetStatus$.next({
level: ServiceStatusLevels.degraded,
summary: 'Fleet is setting up',
});

await setupFleet(
new SavedObjectsClient(core.savedObjects.createInternalRepository()),
core.elasticsearch.client.asInternalUser
);

this.fleetStatus$.next({
level: ServiceStatusLevels.available,
summary: 'Fleet is available',
});
} catch (error) {
logger.warn('Fleet setup failed');
logger.warn(error);

this.fleetStatus$.next({
// As long as Fleet has a dependency on EPR, we can't reliably set Kibana status to `unavailable` here.
// See https://github.com/elastic/kibana/issues/120237
level: ServiceStatusLevels.available,
summary: 'Fleet setup failed',
meta: {
error: error.message,
},
});
}
})();

Expand Down Expand Up @@ -400,6 +434,7 @@ export class FleetPlugin
appContextService.stop();
licenseService.stop();
this.telemetryEventsSender.stop();
this.fleetStatus$.complete();
}

private setupAgentService(internalEsClient: ElasticsearchClient): AgentService {
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/fleet/server/routes/setup/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { httpServerMock, savedObjectsClientMock } from 'src/core/server/mocks';

import type { PostFleetSetupResponse } from '../../../common';
import { RegistryError } from '../../errors';
import { createAppContextStartContractMock, xpackMocks, createFleetAuthzMock } from '../../mocks';
import { createAppContextStartContractMock, xpackMocks } from '../../mocks';
import { agentServiceMock } from '../../services/agents/agent_service.mock';
import { appContextService } from '../../services/app_context';
import { setupFleet } from '../../services/setup';
import type { FleetRequestHandlerContext } from '../../types';

import { createFleetAuthzMock } from '../../../common';

import { fleetSetupHandler } from './handlers';

jest.mock('../../services/setup', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import React, { useState, useEffect, useCallback } from 'react';
import { EuiButtonEmpty, EuiFlexItem, EuiFlexGroup, EuiFlyout } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import './_index.scss';

import { Dictionary } from '../../../../common/types/common';
import { useUrlState } from '../../util/url_state';
// @ts-ignore
Expand Down
13 changes: 11 additions & 2 deletions x-pack/plugins/security_solution/common/cti/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,14 @@ export const EVENT_ENRICHMENT_INDICATOR_FIELD_MAP = {
export const DEFAULT_EVENT_ENRICHMENT_FROM = 'now-30d';
export const DEFAULT_EVENT_ENRICHMENT_TO = 'now';

export const TI_INTEGRATION_PREFIX = 'ti';
export const OTHER_TI_DATASET_KEY = '_others_ti_';
export const CTI_DATASET_KEY_MAP: { [key: string]: string } = {
'AbuseCH URL': 'ti_abusech.url',
'AbuseCH Malware': 'ti_abusech.malware',
'AbuseCH MalwareBazaar': 'ti_abusech.malwarebazaar',
'AlienVault OTX': 'ti_otx.threat',
'Anomali Limo': 'ti_anomali.limo',
'Anomali Threatstream': 'ti_anomali.threatstream',
MISP: 'ti_misp.threat',
ThreatQuotient: 'ti_threatq.threat',
Cybersixgill: 'ti_cybersixgill.threat',
};
Loading

0 comments on commit b079de9

Please sign in to comment.