Skip to content

Commit

Permalink
Replace DataType enum with type & add runtime dataTypes (#82231) (#82656
Browse files Browse the repository at this point in the history
)

## Summary

Expands on pattern added in #82188

Replace `enum DataType` with TS type `DataType` & runtime JS `dataTypes`
```diff
- export enum DataType {
-  logs = 'logs',
-  metrics = 'metrics',
-}
+ export const dataTypes = {
+  Logs: 'logs',
+  Metrics: 'metrics',
+ } as const;
+ export type DataType = typeof dataTypes;
```

<img width="513" alt="Screen Shot 2020-11-02 at 5 13 56 PM" src="https://user-images.githubusercontent.com/57655/97926339-f5898c00-1d30-11eb-8935-92aad936aeea.png">
<img width="774" alt="Screen Shot 2020-11-02 at 5 14 05 PM" src="https://user-images.githubusercontent.com/57655/97926341-f5898c00-1d30-11eb-8d68-b39e2904cf85.png">
<img width="780" alt="Screen Shot 2020-11-02 at 5 19 50 PM" src="https://user-images.githubusercontent.com/57655/97926342-f5898c00-1d30-11eb-9799-95d77bfc1757.png">

# Conflicts:
#	x-pack/plugins/ingest_manager/common/constants/epm.ts
#	x-pack/plugins/ingest_manager/common/types/models/epm.ts
  • Loading branch information
John Schulz authored Nov 4, 2020
1 parent ec5163c commit cb7ce2d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions x-pack/plugins/ingest_manager/common/constants/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ export const requiredPackages = {
System: 'system',
Endpoint: 'endpoint',
} as const;

export const dataTypes = {
Logs: 'logs',
Metrics: 'metrics',
} as const;
7 changes: 2 additions & 5 deletions x-pack/plugins/ingest_manager/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Follow pattern from https://github.com/elastic/kibana/pull/52447
// TODO: Update when https://github.com/elastic/kibana/issues/53021 is closed
import { SavedObject, SavedObjectAttributes, SavedObjectReference } from 'src/core/public';
import { requiredPackages } from '../../constants';
import { dataTypes, requiredPackages } from '../../constants';

export enum InstallationStatus {
installed = 'installed',
Expand Down Expand Up @@ -45,10 +45,7 @@ export enum ElasticsearchAssetType {
transform = 'transform',
}

export enum DataType {
logs = 'logs',
metrics = 'metrics',
}
export type DataType = typeof dataTypes;

export enum AgentAssetType {
input = 'input',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
import * as Registry from '../../registry';
import { loadFieldsFromYaml, Fields, Field } from '../../fields/field';
import { getPackageKeysByStatus } from '../../packages/get';
import { dataTypes } from '../../../../../common/constants';
import { ValueOf } from '../../../../../common/types';
import {
InstallationStatus,
RegistryPackage,
Expand Down Expand Up @@ -119,7 +121,7 @@ export async function installIndexPatterns(
const packageVersionsInfo = await Promise.all(packageVersionsFetchInfoPromise);

// for each index pattern type, create an index pattern
const indexPatternTypes = [DataType.logs, DataType.metrics];
const indexPatternTypes = Object.values(dataTypes);
indexPatternTypes.forEach(async (indexPatternType) => {
// if this is an update because a package is being uninstalled (no pkgkey argument passed) and no other packages are installed, remove the index pattern
if (!pkgName && installedPackages.length === 0) {
Expand All @@ -146,7 +148,7 @@ export async function installIndexPatterns(
// of all fields from all data streams matching data stream type
export const getAllDataStreamFieldsByType = async (
packages: RegistryPackage[],
dataStreamType: DataType
dataStreamType: ValueOf<DataType>
): Promise<Fields> => {
const dataStreamsPromises = packages.reduce<Array<Promise<Field[]>>>((acc, pkg) => {
if (pkg.data_streams) {
Expand Down Expand Up @@ -391,7 +393,7 @@ export const ensureDefaultIndices = async (callCluster: CallESAsCurrentUser) =>
// that no matching indices exist https://github.com/elastic/kibana/issues/62343
const logger = appContextService.getLogger();
return Promise.all(
Object.keys(DataType).map(async (indexPattern) => {
Object.values(dataTypes).map(async (indexPattern) => {
const defaultIndexPatternName = indexPattern + INDEX_PATTERN_PLACEHOLDER_SUFFIX;
const indexExists = await callCluster('indices.exists', { index: defaultIndexPatternName });
if (!indexExists) {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/ingest_manager/server/types/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export {
PostAgentEnrollRequest,
PostAgentCheckinRequest,
DataType,
dataTypes,
} from '../../common';

export type CallESAsCurrentUser = LegacyScopedClusterClient['callAsCurrentUser'];
Expand Down

0 comments on commit cb7ce2d

Please sign in to comment.