Skip to content

Commit

Permalink
[Fleet] clean up for deleted file task (#144624)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
joeypoon and kibanamachine authored Nov 7, 2022
1 parent 7793d4d commit 5de249f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 28 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"server": true,
"ui": true,
"configPath": ["xpack", "fleet"],
"requiredPlugins": ["licensing", "data", "encryptedSavedObjects", "navigation", "customIntegrations", "share", "spaces", "security", "unifiedSearch", "savedObjectsTagging", "taskManager", "guidedOnboarding"],
"requiredPlugins": ["licensing", "data", "encryptedSavedObjects", "navigation", "customIntegrations", "share", "spaces", "security", "unifiedSearch", "savedObjectsTagging", "taskManager", "guidedOnboarding", "files"],
"optionalPlugins": ["features", "cloud", "usageCollection", "home", "globalSearch", "telemetry", "discover", "ingestPipelines"],
"extraPublicDirs": ["common"],
"requiredBundles": ["kibanaReact", "cloudChat", "esUiShared", "infra", "kibanaUtils", "usageCollection", "unifiedSearch"]
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/fleet/server/constants/fleet_es_assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,5 @@ on_failure:
- 'failed in Fleet agent final_pipeline: {{ _ingest.on_failure_message }}'`;

// File storage indexes supporting endpoint Upload/download
export const FILE_STORAGE_METADATA_INDEX = '.fleet-*-files';
export const FILE_STORAGE_DATA_INDEX = '.fleet-*-file-data';
export const FILE_STORAGE_METADATA_INDEX_PATTERN = '.fleet-*-files';
export const FILE_STORAGE_DATA_INDEX_PATTERN = '.fleet-*-file-data';
8 changes: 4 additions & 4 deletions x-pack/plugins/fleet/server/services/files/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { elasticsearchServiceMock } from '@kbn/core/server/mocks';

import { ES_SEARCH_LIMIT } from '../../../common/constants';
import {
FILE_STORAGE_DATA_INDEX,
FILE_STORAGE_METADATA_INDEX,
FILE_STORAGE_DATA_INDEX_PATTERN,
FILE_STORAGE_METADATA_INDEX_PATTERN,
} from '../../constants/fleet_es_assets';

import { fileIdsWithoutChunksByIndex, getFilesByStatus, updateFilesStatus } from '.';
Expand Down Expand Up @@ -61,7 +61,7 @@ describe('files service', () => {

expect(esClientMock.search).toBeCalledWith(
{
index: FILE_STORAGE_METADATA_INDEX,
index: FILE_STORAGE_METADATA_INDEX_PATTERN,
body: {
size: ES_SEARCH_LIMIT,
query: {
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('files service', () => {

expect(esClientMock.search).toBeCalledWith(
{
index: FILE_STORAGE_DATA_INDEX,
index: FILE_STORAGE_DATA_INDEX_PATTERN,
body: {
size: ES_SEARCH_LIMIT,
query: {
Expand Down
14 changes: 7 additions & 7 deletions x-pack/plugins/fleet/server/services/files/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

import type { ElasticsearchClient } from '@kbn/core/server';
import type { UpdateByQueryResponse, SearchHit } from '@elastic/elasticsearch/lib/api/types';
import type { FileStatus } from '@kbn/files-plugin/common/types';

import {
FILE_STORAGE_DATA_INDEX,
FILE_STORAGE_METADATA_INDEX,
FILE_STORAGE_DATA_INDEX_PATTERN,
FILE_STORAGE_METADATA_INDEX_PATTERN,
} from '../../constants/fleet_es_assets';
import { ES_SEARCH_LIMIT } from '../../../common/constants';
import type { FILE_STATUS } from '../../types/files';

/**
* Gets files with given status
Expand All @@ -25,11 +25,11 @@ import type { FILE_STATUS } from '../../types/files';
export async function getFilesByStatus(
esClient: ElasticsearchClient,
abortController: AbortController,
status: FILE_STATUS = 'READY'
status: FileStatus = 'READY'
): Promise<SearchHit[]> {
const result = await esClient.search(
{
index: FILE_STORAGE_METADATA_INDEX,
index: FILE_STORAGE_METADATA_INDEX_PATTERN,
body: {
size: ES_SEARCH_LIMIT,
query: {
Expand Down Expand Up @@ -74,7 +74,7 @@ export async function fileIdsWithoutChunksByIndex(

const chunks = await esClient.search<{ bid: string }>(
{
index: FILE_STORAGE_DATA_INDEX,
index: FILE_STORAGE_DATA_INDEX_PATTERN,
body: {
size: ES_SEARCH_LIMIT,
query: {
Expand Down Expand Up @@ -124,7 +124,7 @@ export function updateFilesStatus(
esClient: ElasticsearchClient,
abortController: AbortController,
fileIdsByIndex: FileIdsByIndex,
status: FILE_STATUS
status: FileStatus
): Promise<UpdateByQueryResponse[]> {
return Promise.all(
Object.entries(fileIdsByIndex).map(([index, fileIds]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import type { ElasticsearchClientMock } from '@kbn/core-elasticsearch-client-ser
import { loggingSystemMock } from '@kbn/core/server/mocks';

import { createAppContextStartContractMock } from '../mocks';
import { FILE_STORAGE_DATA_INDEX, FILE_STORAGE_METADATA_INDEX } from '../constants/fleet_es_assets';
import {
FILE_STORAGE_DATA_INDEX_PATTERN,
FILE_STORAGE_METADATA_INDEX_PATTERN,
} from '../constants/fleet_es_assets';
import { appContextService } from '../services';

import { CheckDeletedFilesTask, TYPE, VERSION } from './check_deleted_files_task';
Expand Down Expand Up @@ -115,12 +118,12 @@ describe('check deleted files task', () => {
hits: [
{
_id: 'metadata-testid1',
_index: FILE_STORAGE_METADATA_INDEX,
_index: FILE_STORAGE_METADATA_INDEX_PATTERN,
_source: { file: { status: 'READY' } },
},
{
_id: 'metadata-testid2',
_index: FILE_STORAGE_METADATA_INDEX,
_index: FILE_STORAGE_METADATA_INDEX_PATTERN,
_source: { file: { status: 'READY' } },
},
],
Expand All @@ -144,7 +147,7 @@ describe('check deleted files task', () => {
hits: [
{
_id: 'data-testid1',
_index: FILE_STORAGE_DATA_INDEX,
_index: FILE_STORAGE_DATA_INDEX_PATTERN,
_source: {
bid: 'metadata-testid1',
},
Expand All @@ -157,7 +160,7 @@ describe('check deleted files task', () => {

expect(esClient.updateByQuery).toHaveBeenCalledWith(
{
index: FILE_STORAGE_METADATA_INDEX,
index: FILE_STORAGE_METADATA_INDEX_PATTERN,
query: {
ids: {
values: ['metadata-testid2'],
Expand Down
8 changes: 0 additions & 8 deletions x-pack/plugins/fleet/server/types/files/index.ts

This file was deleted.

3 changes: 2 additions & 1 deletion x-pack/plugins/fleet/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
{ "path": "../licensing/tsconfig.json" },
{ "path": "../../../src/plugins/data/tsconfig.json" },
{ "path": "../encrypted_saved_objects/tsconfig.json" },
{ "path": "../../../src/plugins/guided_onboarding/tsconfig.json" },
{ "path": "../../../src/plugins/guided_onboarding/tsconfig.json" },
{ "path": "../../../src/plugins/files/tsconfig.json"},

// optionalPlugins from ./kibana.json
{ "path": "../security/tsconfig.json" },
Expand Down

0 comments on commit 5de249f

Please sign in to comment.