[Security Solution] add shared serverless metering logic (#161607)

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Joey F. Poon 2023-07-13 16:51:23 -07:00 committed by GitHub
parent d728789f55
commit 0f57d8aa01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 79 additions and 5 deletions

View file

@ -17,7 +17,8 @@
"ml",
"security",
"securitySolution",
"serverless"
"serverless",
"taskManager"
],
"optionalPlugins": [
"securitySolutionEss"

View file

@ -0,0 +1,8 @@
/*
* 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.
*/
export { usageReportingService } from './usage_reporting_service';

View file

@ -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 { Response } from 'node-fetch';
import fetch from 'node-fetch';
import { USAGE_SERVICE_USAGE_URL } from '../../constants';
import type { UsageRecord } from '../../types';
export class UsageReportingService {
public async reportUsage(records: UsageRecord[]): Promise<Response> {
return fetch(USAGE_SERVICE_USAGE_URL, {
method: 'post',
body: JSON.stringify([records]),
headers: { 'Content-Type': 'application/json' },
});
}
}
export const usageReportingService = new UsageReportingService();

View file

@ -0,0 +1,12 @@
/*
* 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.
*/
// TODO: this probably shouldn't live in code
const namespace = 'elastic-system';
const USAGE_SERVICE_BASE_API_URL = `http://usage-api.${namespace}/api`;
const USAGE_SERVICE_BASE_API_URL_V1 = `${USAGE_SERVICE_BASE_API_URL}/v1`;
export const USAGE_SERVICE_USAGE_URL = `${USAGE_SERVICE_BASE_API_URL_V1}/usage`;

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import type { PluginInitializerContext, Plugin, CoreSetup } from '@kbn/core/server';
import type { PluginInitializerContext, Plugin, CoreSetup, CoreStart } from '@kbn/core/server';
import type { ServerlessSecurityConfig } from './config';
import { getProductAppFeatures } from '../common/pli/pli_features';
@ -42,11 +42,10 @@ export class SecuritySolutionServerlessPlugin
}
pluginsSetup.ml.setFeaturesEnabled({ ad: true, dfa: true, nlp: false });
return {};
}
public start() {
public start(_coreStart: CoreStart, pluginsSetup: SecuritySolutionServerlessPluginStartDeps) {
return {};
}

View file

@ -11,6 +11,10 @@ import type {
PluginSetup as SecuritySolutionPluginSetup,
PluginStart as SecuritySolutionPluginStart,
} from '@kbn/security-solution-plugin/server';
import type {
TaskManagerSetupContract as TaskManagerPluginSetup,
TaskManagerStartContract as TaskManagerPluginStart,
} from '@kbn/task-manager-plugin/server';
import type { SecuritySolutionEssPluginSetup } from '@kbn/security-solution-ess/server';
import type { MlPluginSetup } from '@kbn/ml-plugin/server';
@ -26,10 +30,35 @@ export interface SecuritySolutionServerlessPluginSetupDeps {
securitySolutionEss: SecuritySolutionEssPluginSetup;
features: PluginSetupContract;
ml: MlPluginSetup;
taskManager: TaskManagerPluginSetup;
}
export interface SecuritySolutionServerlessPluginStartDeps {
security: SecurityPluginStart;
securitySolution: SecuritySolutionPluginStart;
features: PluginStartContract;
taskManager: TaskManagerPluginStart;
}
export interface UsageRecord {
id: string;
usage_timestamp: string;
creation_timestamp: string;
usage: UsageMetrics;
source: UsageSource;
}
export interface UsageMetrics {
type: string;
sub_type?: string;
quantity: number;
period_seconds?: number;
cause?: string;
metadata?: unknown;
}
export interface UsageSource {
id: string;
instance_group_id: string;
instance_group_type: string;
}

View file

@ -31,6 +31,7 @@
"@kbn/shared-ux-page-kibana-template",
"@kbn/features-plugin",
"@kbn/ml-plugin",
"@kbn/kibana-utils-plugin"
"@kbn/kibana-utils-plugin",
"@kbn/task-manager-plugin"
]
}