Skip to content

Commit

Permalink
[Build] restore esTypes (#377)
Browse files Browse the repository at this point in the history
Restoring the opensearchTypes to esTypes and then updated the tests
(unit, integ, and func test all passing). This is allowable because
this is for functional purposes and for clusters/plugins that will
migrate to Dashboards. Their index will not require re-indexing for 1.0.0
and shouldn't require a full migration after further updates.

Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed May 26, 2021
1 parent 40b8106 commit b6e34ef
Show file tree
Hide file tree
Showing 49 changed files with 301 additions and 307 deletions.
2 changes: 1 addition & 1 deletion src/fixtures/logstash_fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function stubbedLogstashFields() {
return {
name,
type,
opensearchTypes: [opensearchType],
esTypes: [opensearchType],
readFromDocValues: shouldReadFieldFromDocValues(aggregatable, opensearchType),
aggregatable,
searchable,
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/dashboard/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ interface FieldSubType {
export interface Field {
name: string;
type: string;
// opensearchTypes might be undefined on old index patterns that have not been refreshed since we added
// esTypes might be undefined on old index patterns that have not been refreshed since we added
// this prop. It is also undefined on scripted fields.
opensearchTypes?: string[];
esTypes?: string[];
aggregatable: boolean;
filterable: boolean;
searchable: boolean;
Expand Down
46 changes: 22 additions & 24 deletions src/plugins/data/common/field_formats/field_formats_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ export class FieldFormatsRegistry {
* using the format:defaultTypeMap config map
*
* @param {OSD_FIELD_TYPES} fieldType - the field type
* @param {OPENSEARCH_FIELD_TYPES[]} opensearchTypes - Array of OpenSearch data types
* @param {OPENSEARCH_FIELD_TYPES[]} esTypes - Array of OpenSearch data types
* @return {FieldType}
*/
getDefaultConfig = (
fieldType: OSD_FIELD_TYPES,
opensearchTypes?: OPENSEARCH_FIELD_TYPES[]
esTypes?: OPENSEARCH_FIELD_TYPES[]
): FieldFormatConfig => {
const type = this.getDefaultTypeName(fieldType, opensearchTypes);
const type = this.getDefaultTypeName(fieldType, esTypes);

return (
(this.defaultMap && this.defaultMap[type]) || { id: FIELD_FORMAT_IDS.STRING, params: {} }
Expand Down Expand Up @@ -120,14 +120,14 @@ export class FieldFormatsRegistry {
* used by the field editor
*
* @param {OSD_FIELD_TYPES} fieldType
* @param {OPENSEARCH_FIELD_TYPES[]} opensearchTypes - Array of OpenSearch data types
* @param {OPENSEARCH_FIELD_TYPES[]} esTypes - Array of OpenSearch data types
* @return {FieldFormatInstanceType | undefined}
*/
getDefaultType = (
fieldType: OSD_FIELD_TYPES,
opensearchTypes?: OPENSEARCH_FIELD_TYPES[]
esTypes?: OPENSEARCH_FIELD_TYPES[]
): FieldFormatInstanceType | undefined => {
const config = this.getDefaultConfig(fieldType, opensearchTypes);
const config = this.getDefaultConfig(fieldType, esTypes);

return this.getType(config.id);
};
Expand All @@ -136,34 +136,32 @@ export class FieldFormatsRegistry {
* Get the name of the default type for OpenSearch types like date_nanos
* using the format:defaultTypeMap config map
*
* @param {OPENSEARCH_FIELD_TYPES[]} opensearchTypes - Array of OpenSearch data types
* @param {OPENSEARCH_FIELD_TYPES[]} esTypes - Array of OpenSearch data types
* @return {OPENSEARCH_FIELD_TYPES | undefined}
*/
getTypeNameByOpenSearchTypes = (
opensearchTypes: OPENSEARCH_FIELD_TYPES[] | undefined
esTypes: OPENSEARCH_FIELD_TYPES[] | undefined
): OPENSEARCH_FIELD_TYPES | undefined => {
if (!Array.isArray(opensearchTypes)) {
if (!Array.isArray(esTypes)) {
return undefined;
}

return opensearchTypes.find(
(type) => this.defaultMap[type] && this.defaultMap[type].opensearch
);
return esTypes.find((type) => this.defaultMap[type] && this.defaultMap[type].opensearch);
};

/**
* Get the default FieldFormat type name for
* a field type, using the format:defaultTypeMap.
*
* @param {OSD_FIELD_TYPES} fieldType
* @param {OPENSEARCH_FIELD_TYPES[]} opensearchTypes
* @param {OPENSEARCH_FIELD_TYPES[]} esTypes
* @return {OPENSEARCH_FIELD_TYPES | OSD_FIELD_TYPES}
*/
getDefaultTypeName = (
fieldType: OSD_FIELD_TYPES,
opensearchTypes?: OPENSEARCH_FIELD_TYPES[]
esTypes?: OPENSEARCH_FIELD_TYPES[]
): OPENSEARCH_FIELD_TYPES | OSD_FIELD_TYPES => {
const opensearchType = this.getTypeNameByOpenSearchTypes(opensearchTypes);
const opensearchType = this.getTypeNameByOpenSearchTypes(esTypes);

return opensearchType || fieldType;
};
Expand Down Expand Up @@ -195,15 +193,15 @@ export class FieldFormatsRegistry {
* Get the default fieldFormat instance for a field format.
*
* @param {OSD_FIELD_TYPES} fieldType
* @param {OPENSEARCH_FIELD_TYPES[]} opensearchTypes
* @param {OPENSEARCH_FIELD_TYPES[]} esTypes
* @return {FieldFormat}
*/
getDefaultInstancePlain = (
fieldType: OSD_FIELD_TYPES,
opensearchTypes?: OPENSEARCH_FIELD_TYPES[],
esTypes?: OPENSEARCH_FIELD_TYPES[],
params: Record<string, any> = {}
): FieldFormat => {
const conf = this.getDefaultConfig(fieldType, opensearchTypes);
const conf = this.getDefaultConfig(fieldType, esTypes);
const instanceParams = {
...conf.params,
...params,
Expand All @@ -215,20 +213,20 @@ export class FieldFormatsRegistry {
* Returns a cache key built by the given variables for caching in memoized
* Where opensearchType contains fieldType, fieldType is returned
* -> OpenSearch Dashboards types have a higher priority in that case
* -> would lead to failing tests that match e.g. date format with/without opensearchTypes
* -> would lead to failing tests that match e.g. date format with/without esTypes
* https://lodash.com/docs#memoize
*
* @param {OSD_FIELD_TYPES} fieldType
* @param {OPENSEARCH_FIELD_TYPES[]} opensearchTypes
* @param {OPENSEARCH_FIELD_TYPES[]} esTypes
* @return {String}
*/
getDefaultInstanceCacheResolver(
fieldType: OSD_FIELD_TYPES,
opensearchTypes: OPENSEARCH_FIELD_TYPES[]
esTypes: OPENSEARCH_FIELD_TYPES[]
): string {
// @ts-ignore
return Array.isArray(opensearchTypes) && opensearchTypes.indexOf(fieldType) === -1
? [fieldType, ...opensearchTypes].join('-')
return Array.isArray(esTypes) && esTypes.indexOf(fieldType) === -1
? [fieldType, ...esTypes].join('-')
: fieldType;
}

Expand All @@ -254,7 +252,7 @@ export class FieldFormatsRegistry {
* It's a memoized function that builds and reads a cache
*
* @param {OSD_FIELD_TYPES} fieldType
* @param {OPENSEARCH_FIELD_TYPES[]} opensearchTypes
* @param {OPENSEARCH_FIELD_TYPES[]} esTypes
* @return {FieldFormat}
*/
getDefaultInstance = memoize(this.getDefaultInstancePlain, this.getDefaultInstanceCacheResolver);
Expand Down
14 changes: 7 additions & 7 deletions src/plugins/data/common/index_patterns/field.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { IFieldType } from '.';
export const stubFields: IFieldType[] = [
{
name: 'machine.os',
opensearchTypes: ['text'],
esTypes: ['text'],
type: 'string',
aggregatable: false,
searchable: false,
Expand All @@ -44,47 +44,47 @@ export const stubFields: IFieldType[] = [
{
name: 'machine.os.raw',
type: 'string',
opensearchTypes: ['keyword'],
esTypes: ['keyword'],
aggregatable: true,
searchable: true,
filterable: true,
},
{
name: 'not.filterable',
type: 'string',
opensearchTypes: ['text'],
esTypes: ['text'],
aggregatable: true,
searchable: false,
filterable: false,
},
{
name: 'bytes',
type: 'number',
opensearchTypes: ['long'],
esTypes: ['long'],
aggregatable: true,
searchable: true,
filterable: true,
},
{
name: '@timestamp',
type: 'date',
opensearchTypes: ['date'],
esTypes: ['date'],
aggregatable: true,
searchable: true,
filterable: true,
},
{
name: 'clientip',
type: 'ip',
opensearchTypes: ['ip'],
esTypes: ['ip'],
aggregatable: true,
searchable: true,
filterable: true,
},
{
name: 'bool.field',
type: 'boolean',
opensearchTypes: ['boolean'],
esTypes: ['boolean'],
aggregatable: true,
searchable: true,
filterable: true,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b6e34ef

Please sign in to comment.