mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Security Solution] fix projectId not populating for metering records (#166417)
This commit is contained in:
parent
66d67056ad
commit
6ab7ec48cf
5 changed files with 22 additions and 10 deletions
|
@ -14,4 +14,5 @@ export const METERING_TASK = {
|
|||
SAMPLE_PERIOD_SECONDS: 3600,
|
||||
THRESHOLD_MINUTES: 30,
|
||||
USAGE_TYPE_PREFIX: 'security_solution_',
|
||||
MISSING_PROJECT_ID: 'missing_project_id',
|
||||
};
|
||||
|
|
|
@ -96,7 +96,7 @@ describe('EndpointMeteringService', () => {
|
|||
const usageRecords = await endpointMeteringService.getUsageRecords(args);
|
||||
|
||||
expect(usageRecords[0]).toEqual({
|
||||
id: `endpoint-${agentId}-${timestamp}`,
|
||||
id: `endpoint-${agentId}-${timestamp.toISOString()}`,
|
||||
usage_timestamp: heartbeatDocSrc!.event.ingested,
|
||||
creation_timestamp: heartbeatDocSrc!.event.ingested,
|
||||
usage: {
|
||||
|
@ -140,7 +140,7 @@ describe('EndpointMeteringService', () => {
|
|||
: `${ProductLine.cloud}_${ProductLine.endpoint}`;
|
||||
|
||||
expect(usageRecords[0]).toEqual({
|
||||
id: `endpoint-${agentId}-${timestamp}`,
|
||||
id: `endpoint-${agentId}-${timestamp.toISOString()}`,
|
||||
usage_timestamp: heartbeatDocSrc!.event.ingested,
|
||||
creation_timestamp: heartbeatDocSrc!.event.ingested,
|
||||
usage: {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import type { AggregationsAggregate, SearchResponse } from '@elastic/elasticsearch/lib/api/types';
|
||||
import type { ElasticsearchClient } from '@kbn/core/server';
|
||||
import type { ElasticsearchClient, Logger } from '@kbn/core/server';
|
||||
import { ENDPOINT_HEARTBEAT_INDEX } from '@kbn/security-solution-plugin/common/endpoint/constants';
|
||||
import type { EndpointHeartbeat } from '@kbn/security-solution-plugin/common/endpoint/types';
|
||||
|
||||
|
@ -14,6 +14,7 @@ import { ProductLine, ProductTier } from '../../../common/product';
|
|||
|
||||
import type { UsageRecord, MeteringCallbackInput } from '../../types';
|
||||
import type { ServerlessSecurityConfig } from '../../config';
|
||||
|
||||
import { METERING_TASK } from '../constants/metering';
|
||||
|
||||
export class EndpointMeteringService {
|
||||
|
@ -27,6 +28,7 @@ export class EndpointMeteringService {
|
|||
abortController,
|
||||
lastSuccessfulReport,
|
||||
config,
|
||||
logger,
|
||||
}: MeteringCallbackInput): Promise<UsageRecord[]> => {
|
||||
this.setType(config);
|
||||
if (!this.type) {
|
||||
|
@ -52,6 +54,7 @@ export class EndpointMeteringService {
|
|||
|
||||
const { agent, event } = _source;
|
||||
const record = this.buildMeteringRecord({
|
||||
logger,
|
||||
agentId: agent.id,
|
||||
timestampStr: event.ingested,
|
||||
taskId,
|
||||
|
@ -87,11 +90,13 @@ export class EndpointMeteringService {
|
|||
}
|
||||
|
||||
private buildMeteringRecord({
|
||||
logger,
|
||||
agentId,
|
||||
timestampStr,
|
||||
taskId,
|
||||
projectId = '',
|
||||
projectId,
|
||||
}: {
|
||||
logger: Logger;
|
||||
agentId: string;
|
||||
timestampStr: string;
|
||||
taskId: string;
|
||||
|
@ -102,10 +107,10 @@ export class EndpointMeteringService {
|
|||
timestamp.setSeconds(0);
|
||||
timestamp.setMilliseconds(0);
|
||||
|
||||
return {
|
||||
const usageRecord = {
|
||||
// keep endpoint instead of this.type as id prefix so
|
||||
// we don't double count in the event of add-on changes
|
||||
id: `endpoint-${agentId}-${timestamp}`,
|
||||
id: `endpoint-${agentId}-${timestamp.toISOString()}`,
|
||||
usage_timestamp: timestampStr,
|
||||
creation_timestamp: timestampStr,
|
||||
usage: {
|
||||
|
@ -116,12 +121,18 @@ export class EndpointMeteringService {
|
|||
},
|
||||
source: {
|
||||
id: taskId,
|
||||
instance_group_id: projectId,
|
||||
instance_group_id: projectId || METERING_TASK.MISSING_PROJECT_ID,
|
||||
metadata: {
|
||||
tier: this.tier,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
if (!projectId) {
|
||||
logger.error(`project id missing for record: ${JSON.stringify(usageRecord)}`);
|
||||
}
|
||||
|
||||
return usageRecord;
|
||||
}
|
||||
|
||||
private setType(config: ServerlessSecurityConfig) {
|
||||
|
|
|
@ -72,7 +72,7 @@ export class SecuritySolutionServerlessPlugin
|
|||
logFactory: this.initializerContext.logger,
|
||||
config: this.config,
|
||||
taskManager: pluginsSetup.taskManager,
|
||||
cloudSetup: pluginsSetup.cloudSetup,
|
||||
cloudSetup: pluginsSetup.cloud,
|
||||
taskType: cloudSecurityMetringTaskProperties.taskType,
|
||||
taskTitle: cloudSecurityMetringTaskProperties.taskTitle,
|
||||
version: cloudSecurityMetringTaskProperties.version,
|
||||
|
@ -88,7 +88,7 @@ export class SecuritySolutionServerlessPlugin
|
|||
version: ENDPOINT_METERING_TASK.VERSION,
|
||||
meteringCallback: endpointMeteringService.getUsageRecords,
|
||||
taskManager: pluginsSetup.taskManager,
|
||||
cloudSetup: pluginsSetup.cloudSetup,
|
||||
cloudSetup: pluginsSetup.cloud,
|
||||
});
|
||||
|
||||
pluginsSetup.serverless.setupProjectSettings(SECURITY_PROJECT_SETTINGS);
|
||||
|
|
|
@ -38,7 +38,7 @@ export interface SecuritySolutionServerlessPluginSetupDeps {
|
|||
features: PluginSetupContract;
|
||||
ml: MlPluginSetup;
|
||||
taskManager: TaskManagerSetupContract;
|
||||
cloudSetup: CloudSetup;
|
||||
cloud: CloudSetup;
|
||||
}
|
||||
|
||||
export interface SecuritySolutionServerlessPluginStartDeps {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue