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

[Cloud Security] Refactor D4C metering function #183814

Merged
merged 18 commits into from
May 30, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
eslint fix
  • Loading branch information
CohenIdo committed May 28, 2024
commit d7c51cdb9360abcbd223608202d119e40b80093e
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/

import type { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { CLOUD_DEFEND, CLOUD_SECURITY_TASK_TYPE, CLOUD_DEFEND_HEARTBEAT_INDEX } from './constants';
import type { AggregationsAggregate, SearchResponse } from '@elastic/elasticsearch/lib/api/types';
import type { Tier, UsageRecord } from '../types';
import type { CloudSecurityMeteringCallbackInput } from './types';
import { AggregationsAggregate, SearchResponse } from '@elastic/elasticsearch/lib/api/types';
import { CLOUD_DEFEND, CLOUD_SECURITY_TASK_TYPE, CLOUD_DEFEND_HEARTBEAT_INDEX } from './constants';

const BATCH_SIZE = 1000;

Expand Down Expand Up @@ -47,7 +47,7 @@ const buildMeteringRecord = (
id: taskId,
instance_group_id: projectId,
metadata: {
tier: tier,
tier,
},
},
};
Expand All @@ -57,9 +57,9 @@ const buildMeteringRecord = (
export const getUsageRecords = async (
esClient: ElasticsearchClient,
searchFrom: Date,
searchAfter?: any[]
searchAfter?: number[]
): Promise<SearchResponse<CloudDefendHeartbeat, Record<string, AggregationsAggregate>>> => {
return await esClient.search<CloudDefendHeartbeat>(
return esClient.search<CloudDefendHeartbeat>(
{
index: CLOUD_DEFEND_HEARTBEAT_INDEX,
size: BATCH_SIZE,
Expand Down Expand Up @@ -99,7 +99,7 @@ export const getCloudDefendUsageRecords = async ({
}: CloudSecurityMeteringCallbackInput): Promise<UsageRecord[] | undefined> => {
try {
let allRecords: UsageRecord[] = [];
let searchAfter: any[] | undefined = undefined;
let searchAfter: number[] | undefined;
let fetchMore = true;

while (fetchMore) {
Expand Down