-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Security Solution] add cloud + endpoint metering #164331
Merged
joeypoon
merged 1 commit into
elastic:main
from
joeypoon:feature/cloud-endpoint-metering
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import type { ElasticsearchClient } 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'; | ||
|
||
import { ProductLine, type ProductTier } from '../../../common/product'; | ||
import { ProductLine, ProductTier } from '../../../common/product'; | ||
|
||
import type { UsageRecord, MeteringCallbackInput } from '../../types'; | ||
import type { ServerlessSecurityConfig } from '../../config'; | ||
|
@@ -20,6 +20,7 @@ const SAMPLE_PERIOD_SECONDS = 3600; | |
const THRESHOLD_MINUTES = 30; | ||
|
||
export class EndpointMeteringService { | ||
private type: ProductLine.endpoint | `${ProductLine.cloud}_${ProductLine.endpoint}` | undefined; | ||
private tier: ProductTier | undefined; | ||
|
||
public getUsageRecords = async ({ | ||
|
@@ -30,6 +31,11 @@ export class EndpointMeteringService { | |
lastSuccessfulReport, | ||
config, | ||
}: MeteringCallbackInput): Promise<UsageRecord[]> => { | ||
this.setType(config); | ||
if (!this.type) { | ||
return []; | ||
} | ||
|
||
this.setTier(config); | ||
|
||
const heartbeatsResponse = await this.getHeartbeatsSince( | ||
|
@@ -42,14 +48,6 @@ export class EndpointMeteringService { | |
return []; | ||
} | ||
|
||
if (!this.tier) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we no longer need this since we're now checking add-on explicitly. |
||
throw new Error( | ||
`no product tier information found for heartbeats: ${JSON.stringify( | ||
heartbeatsResponse.hits.hits | ||
)}` | ||
); | ||
} | ||
|
||
return heartbeatsResponse.hits.hits.reduce((acc, { _source }) => { | ||
if (!_source) { | ||
return acc; | ||
|
@@ -108,11 +106,14 @@ export class EndpointMeteringService { | |
timestamp.setMilliseconds(0); | ||
|
||
return { | ||
// 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}`, | ||
usage_timestamp: timestampStr, | ||
creation_timestamp: timestampStr, | ||
usage: { | ||
type: 'security_solution_endpoint', | ||
// type postfix is used to determine the PLI to bill | ||
type: `security_solution_${this.type}`, | ||
period_seconds: SAMPLE_PERIOD_SECONDS, | ||
quantity: 1, | ||
}, | ||
|
@@ -126,15 +127,44 @@ export class EndpointMeteringService { | |
}; | ||
} | ||
|
||
private setType(config: ServerlessSecurityConfig) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: If you rename it to |
||
if (this.type) { | ||
return; | ||
} | ||
|
||
let hasCloudAddOn = false; | ||
let hasEndpointAddOn = false; | ||
config.productTypes.forEach((productType) => { | ||
if (productType.product_line === ProductLine.cloud) { | ||
hasCloudAddOn = true; | ||
} | ||
if (productType.product_line === ProductLine.endpoint) { | ||
hasEndpointAddOn = true; | ||
} | ||
}); | ||
|
||
if (hasEndpointAddOn) { | ||
this.type = ProductLine.endpoint; | ||
return; | ||
} | ||
if (hasCloudAddOn) { | ||
this.type = `${ProductLine.cloud}_${ProductLine.endpoint}`; | ||
} | ||
} | ||
|
||
private setTier(config: ServerlessSecurityConfig) { | ||
if (this.tier) { | ||
return; | ||
} | ||
|
||
const endpoint = config.productTypes.find( | ||
(productType) => productType.product_line === ProductLine.endpoint | ||
const product = config.productTypes.find( | ||
(productType) => | ||
// tiers are always matching so either is fine | ||
productType.product_line === ProductLine.endpoint || | ||
productType.product_line === ProductLine.cloud | ||
); | ||
this.tier = endpoint?.product_tier; | ||
// default essentials is safe since we only reach tier if add-on exists | ||
this.tier = product?.product_tier || ProductTier.essentials; | ||
} | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Perhaps better to call it
pliType
instead oftype
.