Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.x] Remove <7.14 EP Metrics from Security Solution usage collector (#103632) #103702

Merged
merged 1 commit into from
Jun 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion x-pack/plugins/security_solution/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S

initUsageCollectors({
core,
endpointAppContext: endpointContext,
kibanaIndex: globalConfig.kibana.index,
signalsIndex: config.signalsIndex,
ml: plugins.ml,
Expand Down
63 changes: 3 additions & 60 deletions x-pack/plugins/security_solution/server/usage/collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ import { CoreSetup, SavedObjectsClientContract } from '../../../../../src/core/s
import { CollectorFetchContext } from '../../../../../src/plugins/usage_collection/server';
import { CollectorDependencies } from './types';
import { fetchDetectionsMetrics } from './detections';
import { EndpointUsage, getEndpointTelemetryFromFleet } from './endpoints';

export type RegisterCollector = (deps: CollectorDependencies) => void;
export interface UsageData {
endpoints: EndpointUsage | {};
detectionMetrics: {};
}

Expand All @@ -25,7 +23,6 @@ export async function getInternalSavedObjectsClient(core: CoreSetup) {

export const registerCollector: RegisterCollector = ({
core,
endpointAppContext,
kibanaIndex,
signalsIndex,
ml,
Expand Down Expand Up @@ -397,69 +394,15 @@ export const registerCollector: RegisterCollector = ({
},
},
},
endpoints: {
total_installed: {
type: 'long',
_meta: { description: 'The number of installed endpoints' },
},
active_within_last_24_hours: {
type: 'long',
_meta: { description: 'The number of active endpoints' },
},
os: {
type: 'array',
items: {
full_name: {
type: 'keyword',
_meta: { description: 'Full name of the operating system' },
},
platform: {
type: 'keyword',
_meta: { description: 'OS Platform. eg Centos, Ubuntu' },
},
version: {
type: 'keyword',
_meta: {
description:
'The version of the operating system, eg 16.04.7 LTS (Xenial Xerus), 8 (Core)',
},
},
count: {
type: 'long',
_meta: { description: 'The total number of endpoints from that platform' },
},
},
},
policies: {
malware: {
active: {
type: 'long',
_meta: { description: 'The total number of active malware policies' },
},
inactive: {
type: 'long',
_meta: { description: 'The total number of inactive malware policies' },
},
failure: {
type: 'long',
_meta: { description: 'The total number of failing malware policies' },
},
},
},
},
},
isReady: () => true,
fetch: async ({ esClient }: CollectorFetchContext): Promise<UsageData> => {
const internalSavedObjectsClient = await getInternalSavedObjectsClient(core);
const savedObjectsClient = (internalSavedObjectsClient as unknown) as SavedObjectsClientContract;
const [detectionMetrics, endpoints] = await Promise.allSettled([
fetchDetectionsMetrics(kibanaIndex, signalsIndex, esClient, ml, savedObjectsClient),
getEndpointTelemetryFromFleet(savedObjectsClient, endpointAppContext, esClient),
]);
const soClient = (internalSavedObjectsClient as unknown) as SavedObjectsClientContract;

return {
detectionMetrics: detectionMetrics.status === 'fulfilled' ? detectionMetrics.value : {},
endpoints: endpoints.status === 'fulfilled' ? endpoints.value : {},
detectionMetrics:
(await fetchDetectionsMetrics(kibanaIndex, signalsIndex, esClient, soClient, ml)) || {},
};
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Detections Usage and Metrics', () => {
});

it('returns zeroed counts if calls are empty', async () => {
const result = await fetchDetectionsMetrics('', '', esClientMock, mlMock, savedObjectsClient);
const result = await fetchDetectionsMetrics('', '', esClientMock, savedObjectsClient, mlMock);

expect(result).toEqual(
expect.objectContaining({
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('Detections Usage and Metrics', () => {
.mockReturnValue({ body: getMockRuleAlertsResponse(3400) });
(savedObjectsClient.find as jest.Mock).mockReturnValue(getMockAlertCasesResponse());

const result = await fetchDetectionsMetrics('', '', esClientMock, mlMock, savedObjectsClient);
const result = await fetchDetectionsMetrics('', '', esClientMock, savedObjectsClient, mlMock);

expect(result).toEqual(
expect.objectContaining({
Expand Down Expand Up @@ -174,7 +174,7 @@ describe('Detections Usage and Metrics', () => {
.mockReturnValue({ body: getMockRuleAlertsResponse(800) });
(savedObjectsClient.find as jest.Mock).mockReturnValue(getMockAlertCasesResponse());

const result = await fetchDetectionsMetrics('', '', esClientMock, mlMock, savedObjectsClient);
const result = await fetchDetectionsMetrics('', '', esClientMock, savedObjectsClient, mlMock);

expect(result).toEqual(
expect.objectContaining({
Expand Down Expand Up @@ -236,7 +236,7 @@ describe('Detections Usage and Metrics', () => {
.mockReturnValue({ body: getMockRuleAlertsResponse(0) });
(savedObjectsClient.find as jest.Mock).mockReturnValue(getMockAlertCasesResponse());

const result = await fetchDetectionsMetrics('', '', esClientMock, mlMock, savedObjectsClient);
const result = await fetchDetectionsMetrics('', '', esClientMock, savedObjectsClient, mlMock);

expect(result).toEqual(
expect.objectContaining({
Expand Down Expand Up @@ -317,7 +317,7 @@ describe('Detections Usage and Metrics', () => {
jobs: null,
jobStats: null,
} as unknown) as ReturnType<typeof mlMock.anomalyDetectorsProvider>);
const result = await fetchDetectionsMetrics('', '', esClientMock, mlMock, savedObjectsClient);
const result = await fetchDetectionsMetrics('', '', esClientMock, savedObjectsClient, mlMock);

expect(result).toEqual(
expect.objectContaining({
Expand Down Expand Up @@ -347,7 +347,7 @@ describe('Detections Usage and Metrics', () => {
datafeedStats: mockDatafeedStatsResponse,
} as unknown) as ReturnType<typeof mlMock.anomalyDetectorsProvider>);

const result = await fetchDetectionsMetrics('', '', esClientMock, mlMock, savedObjectsClient);
const result = await fetchDetectionsMetrics('', '', esClientMock, savedObjectsClient, mlMock);

expect(result).toEqual(
expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export const fetchDetectionsMetrics = async (
kibanaIndex: string,
signalsIndex: string,
esClient: ElasticsearchClient,
ml: MlPluginSetup | undefined,
savedObjectClient: SavedObjectsClientContract
soClient: SavedObjectsClientContract,
mlClient: MlPluginSetup | undefined
): Promise<DetectionMetrics> => {
const [mlJobMetrics, detectionRuleMetrics] = await Promise.allSettled([
getMlJobMetrics(ml, savedObjectClient),
getDetectionRuleMetrics(kibanaIndex, signalsIndex, esClient, savedObjectClient),
getMlJobMetrics(mlClient, soClient),
getDetectionRuleMetrics(kibanaIndex, signalsIndex, esClient, soClient),
]);

return {
Expand Down
Loading