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

Adding Usage Telemetry for Detection Rules & Security Lists Tasks #170056

Merged
merged 34 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
81e20be
Adding Usage Telemetry for Detection Rules & Secuirty Lists Tasks
KeerthyND Oct 27, 2023
3447cb7
Enhancing interval
KeerthyND Oct 27, 2023
1bc4aeb
Merge branch 'main' into add-usage-telemetry
KeerthyND Oct 27, 2023
d6139b6
Merge branch 'main' into add-usage-telemetry
KeerthyND Oct 27, 2023
7280f91
Merge branch 'main' into add-usage-telemetry
KeerthyND Oct 30, 2023
7e0508d
Merge branch 'main' into add-usage-telemetry
KeerthyND Oct 30, 2023
535f6ab
Merge branch 'main' into add-usage-telemetry
KeerthyND Oct 30, 2023
b390c6b
Merge branch 'main' into add-usage-telemetry
KeerthyND Oct 30, 2023
4589e26
Merge branch 'main' into add-usage-telemetry
KeerthyND Nov 1, 2023
e7de3d8
Adding 24-hour filter to exception-list retrieval
KeerthyND Nov 1, 2023
acafeb2
Merge branch 'main' into add-usage-telemetry
KeerthyND Nov 1, 2023
41cc001
Merge branch 'main' into add-usage-telemetry
KeerthyND Nov 1, 2023
df5ccd4
Merge branch 'main' into add-usage-telemetry
KeerthyND Nov 1, 2023
dd0ff06
Adding import for moment
KeerthyND Nov 1, 2023
d399548
Merge branch 'main' into add-usage-telemetry
KeerthyND Nov 1, 2023
2bf61be
Merge branch 'main' into add-usage-telemetry
KeerthyND Nov 1, 2023
2866cab
Merge branch 'main' into add-usage-telemetry
KeerthyND Nov 1, 2023
c8438c9
Review comments are addressed
KeerthyND Nov 2, 2023
16751e2
Merge branch 'main' into add-usage-telemetry
KeerthyND Nov 2, 2023
12f7b97
Merge branch 'main' into add-usage-telemetry
KeerthyND Nov 2, 2023
cc3460f
Merge branch 'main' into add-usage-telemetry
KeerthyND Nov 2, 2023
66d6f33
Merge branch 'main' into add-usage-telemetry
KeerthyND Nov 2, 2023
0594f8c
Merge branch 'main' into add-usage-telemetry
KeerthyND Nov 2, 2023
aa9f6ce
Enhancing the filter
KeerthyND Nov 3, 2023
6e27ddf
Merge branch 'main' into add-usage-telemetry
KeerthyND Nov 3, 2023
ad12c2c
Merge branch 'main' into add-usage-telemetry
KeerthyND Nov 3, 2023
ddebc4e
Merge branch 'main' into add-usage-telemetry
KeerthyND Nov 9, 2023
486ebc1
Merge branch 'main' into add-usage-telemetry
pjhampton Nov 14, 2023
6ca61c2
Add polish.
pjhampton Nov 14, 2023
739c75f
Merge branch 'main' into add-usage-telemetry
pjhampton Nov 14, 2023
9ce5659
Fix filter.
pjhampton Nov 15, 2023
0c9bd9d
Merge branch 'main' into add-usage-telemetry
pjhampton Nov 15, 2023
15ed494
Merge branch 'main' into add-usage-telemetry
pjhampton Nov 27, 2023
b93311b
Don't log exception lists. Just record counts.
pjhampton Nov 27, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import type { SecurityTelemetryTaskConfig } from './task';
import { SecurityTelemetryTask } from './task';
import { telemetryConfiguration } from './configuration';

const usageLabelPrefix: string[] = ['security_telemetry', 'sender'];
export const usageLabelPrefix: string[] = ['security_telemetry', 'sender'];
pjhampton marked this conversation as resolved.
Show resolved Hide resolved

export interface ITelemetryEventsSender {
setup(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ import {
TELEMETRY_CHANNEL_LISTS,
TASK_METRICS_CHANNEL,
} from '../constants';
import { batchTelemetryRecords, templateExceptionList, tlog, createTaskMetric } from '../helpers';
import {
batchTelemetryRecords,
templateExceptionList,
tlog,
createTaskMetric,
createUsageCounterLabel,
} from '../helpers';
import { usageLabelPrefix } from '../sender';
import type { ITelemetryEventsSender } from '../sender';
import type { ITelemetryReceiver } from '../receiver';
import type { ExceptionListItem, ESClusterInfo, ESLicense, RuleSearchResult } from '../types';
Expand All @@ -31,9 +38,13 @@ export function createTelemetryDetectionRuleListsTaskConfig(maxTelemetryBatch: n
sender: ITelemetryEventsSender,
taskExecutionPeriod: TaskExecutionPeriod
) => {
const usageCollector = sender.getTelemetryUsageCluster();

const startTime = Date.now();
const taskName = 'Security Solution Detection Rule Lists Telemetry';
try {
let detectionRuleCount = 0;

const [clusterInfoPromise, licenseInfoPromise] = await Promise.allSettled([
receiver.fetchClusterInfo(),
receiver.fetchLicenseInfo(),
Expand Down Expand Up @@ -98,14 +109,22 @@ export function createTelemetryDetectionRuleListsTaskConfig(maxTelemetryBatch: n
LIST_DETECTION_RULE_EXCEPTION
);
tlog(logger, `Detection rule exception json length ${detectionRuleExceptionsJson.length}`);

detectionRuleCount = detectionRuleExceptionsJson.length;
usageCollector?.incrementCounter({
counterName: createUsageCounterLabel(usageLabelPrefix.concat(['detection_rule'])),
counterType: 'detection_rule_count',
incrementBy: detectionRuleCount,
pjhampton marked this conversation as resolved.
Show resolved Hide resolved
});

const batches = batchTelemetryRecords(detectionRuleExceptionsJson, maxTelemetryBatch);
for (const batch of batches) {
await sender.sendOnDemand(TELEMETRY_CHANNEL_LISTS, batch);
}
await sender.sendOnDemand(TASK_METRICS_CHANNEL, [
createTaskMetric(taskName, true, startTime),
]);
return detectionRuleExceptions.length;
return detectionRuleCount;
pjhampton marked this conversation as resolved.
Show resolved Hide resolved
} catch (err) {
await sender.sendOnDemand(TASK_METRICS_CHANNEL, [
createTaskMetric(taskName, false, startTime, err.message),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import {
tlog,
createTaskMetric,
formatValueListMetaData,
createUsageCounterLabel,
} from '../helpers';
import { usageLabelPrefix } from '../sender';
import type { ITelemetryEventsSender } from '../sender';
import type { ITelemetryReceiver } from '../receiver';
import type { TaskExecutionPeriod } from '../task';
Expand All @@ -43,10 +45,14 @@ export function createTelemetrySecurityListTaskConfig(maxTelemetryBatch: number)
sender: ITelemetryEventsSender,
taskExecutionPeriod: TaskExecutionPeriod
) => {
const usageCollector = sender.getTelemetryUsageCluster();

const startTime = Date.now();
const taskName = 'Security Solution Lists Telemetry';
try {
let count = 0;
let trustedApplicationsCount = 0;
let endpointExceptionsCount = 0;
let endpointEventFiltersCount = 0;

const [clusterInfoPromise, licenseInfoPromise] = await Promise.allSettled([
receiver.fetchClusterInfo(),
Expand All @@ -73,7 +79,13 @@ export function createTelemetrySecurityListTaskConfig(maxTelemetryBatch: number)
LIST_TRUSTED_APPLICATION
);
tlog(logger, `Trusted Apps: ${trustedAppsJson}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better not to log the whole JSON but just the relevant info, eg num or records, WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with this given the recent incident. I pushed something into b93311b

count += trustedAppsJson.length;
trustedApplicationsCount = trustedAppsJson.length;

usageCollector?.incrementCounter({
counterName: createUsageCounterLabel(usageLabelPrefix.concat(['security_lists'])),
counterType: 'trusted_apps_count',
incrementBy: trustedApplicationsCount,
});

const batches = batchTelemetryRecords(trustedAppsJson, maxTelemetryBatch);
for (const batch of batches) {
Expand All @@ -92,7 +104,13 @@ export function createTelemetrySecurityListTaskConfig(maxTelemetryBatch: number)
LIST_ENDPOINT_EXCEPTION
);
tlog(logger, `EP Exceptions: ${epExceptionsJson}`);
count += epExceptionsJson.length;
endpointExceptionsCount = epExceptionsJson.length;

usageCollector?.incrementCounter({
counterName: createUsageCounterLabel(usageLabelPrefix.concat(['security_lists'])),
counterType: 'endpoint_exceptions_count',
incrementBy: endpointExceptionsCount,
});

const batches = batchTelemetryRecords(epExceptionsJson, maxTelemetryBatch);
for (const batch of batches) {
Expand All @@ -111,7 +129,13 @@ export function createTelemetrySecurityListTaskConfig(maxTelemetryBatch: number)
LIST_ENDPOINT_EVENT_FILTER
);
tlog(logger, `EP Event Filters: ${epFiltersJson}`);
count += epFiltersJson.length;
endpointEventFiltersCount = epFiltersJson.length;

usageCollector?.incrementCounter({
counterName: createUsageCounterLabel(usageLabelPrefix.concat(['security_lists'])),
counterType: 'endpoint_event_filters_count',
incrementBy: endpointEventFiltersCount,
});

const batches = batchTelemetryRecords(epFiltersJson, maxTelemetryBatch);
for (const batch of batches) {
Expand All @@ -135,7 +159,7 @@ export function createTelemetrySecurityListTaskConfig(maxTelemetryBatch: number)
await sender.sendOnDemand(TASK_METRICS_CHANNEL, [
createTaskMetric(taskName, true, startTime),
]);
return count;
return trustedApplicationsCount + endpointExceptionsCount + endpointEventFiltersCount;
} catch (err) {
await sender.sendOnDemand(TASK_METRICS_CHANNEL, [
createTaskMetric(taskName, false, startTime, err.message),
Expand Down