Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions changelogs/fragments/10798.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
infra:
- Supply data source version to Datasets ([#10798](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/10798))
3 changes: 3 additions & 0 deletions src/plugins/data/common/data_views/data_views/data_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class DataView extends IndexPattern implements IDataView {
this.dataSourceRef = {
id: this.dataSourceRef.id,
type: attributes.dataSourceEngineType || this.dataSourceRef.type,
version: attributes.dataSourceVersion || this.dataSourceRef.version,
name: attributes.title || this.dataSourceRef.name || this.dataSourceRef.id,
};
} catch (error) {
Expand Down Expand Up @@ -115,6 +116,7 @@ export class DataView extends IndexPattern implements IDataView {
id: dataSourceReference.id,
title: attributes.title || dataSourceReference.id,
type: attributes.dataSourceEngineType || 'OpenSearch',
version: attributes.dataSourceVersion || '',
};
} catch (error) {
// If we can't fetch the data source, create a minimal version
Expand All @@ -125,6 +127,7 @@ export class DataView extends IndexPattern implements IDataView {
? dataSourceReference.name
: dataSourceReference.id,
type: 'OpenSearch',
version: '',
};
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/common/datasets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export interface DataSource {
title: string;
/** The engine type of the data source */
type: string;
/** Version of the data source */
version: string;
/** Optional metadata for the data source */
meta?: DataSourceMeta;
}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/index_patterns/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export interface SavedObjectReference {
name?: string;
id: string;
type: string;
version: string;
}
export interface IndexPatternSpec {
id?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class DatasetService {
id: dataset.dataSource.id!,
name: dataset.dataSource.title,
type: dataset.dataSource.type,
version: dataset.dataSource.version,
}
: undefined,
} as IndexPatternSpec;
Expand Down Expand Up @@ -201,6 +202,7 @@ export class DatasetService {
id: dataset.dataSource.id!,
name: dataset.dataSource.title,
type: dataset.dataSource.type,
version: dataset.dataSource.version,
}
: undefined,
} as IndexPatternSpec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ describe('shouldShowBreakdownSelector', () => {
timeFieldName: '@timestamp',
} as DataView;

it('should return false when dataView is undefined', () => {
const mockServices = {
uiSettings: {
get: jest.fn().mockReturnValue(true),
},
};

it('should return false when dataset is undefined', () => {
expect(shouldShowBreakdownSelector(undefined)).toBe(false);
});

Expand All @@ -20,22 +26,174 @@ describe('shouldShowBreakdownSelector', () => {
});

it('should return false when experimental setting is disabled', () => {
const mockServices = {
const mockDisabledServices = {
uiSettings: {
get: jest.fn().mockReturnValue(false),
},
};
expect(shouldShowBreakdownSelector(mockDataView, mockDisabledServices)).toBe(false);
});

expect(shouldShowBreakdownSelector(mockDataView, mockServices)).toBe(false);
it('should return true when dataSourceRef does not exist (default behavior)', () => {
expect(
shouldShowBreakdownSelector(
{
timeFieldName: '@timestamp',
} as DataView,
mockServices
)
).toBe(true);
});

it('should return true when dataView exists and experimental setting is enabled', () => {
const mockServices = {
uiSettings: {
get: jest.fn().mockReturnValue(true),
},
};
it('should return true when dataSourceRef exists but type is missing', () => {
expect(
shouldShowBreakdownSelector(
{
timeFieldName: '@timestamp',
dataSourceRef: {
id: 'test-id',
version: '3.3.0',
},
} as any,
mockServices
)
).toBe(true);
});

it('should return true when dataSourceRef exists but version is missing', () => {
expect(
shouldShowBreakdownSelector(
{
timeFieldName: '@timestamp',
dataSourceRef: {
id: 'test-id',
type: 'OpenSearch',
},
} as any,
mockServices
)
).toBe(true);
});

it('should return true for OpenSearch version 3.3.0', () => {
expect(
shouldShowBreakdownSelector(
{
timeFieldName: '@timestamp',
dataSourceRef: {
id: 'test-id',
type: 'OpenSearch',
version: '3.3.0',
},
} as any,
mockServices
)
).toBe(true);
});

it('should return true for OpenSearch version greater than 3.3.0', () => {
expect(
shouldShowBreakdownSelector(
{
timeFieldName: '@timestamp',
dataSourceRef: {
id: 'test-id',
type: 'OpenSearch',
version: '3.4.0',
},
} as any,
mockServices
)
).toBe(true);

expect(
shouldShowBreakdownSelector(
{
timeFieldName: '@timestamp',
dataSourceRef: {
id: 'test-id',
type: 'OpenSearch',
version: '4.0.0',
},
} as any,
mockServices
)
).toBe(true);
});

it('should return false for OpenSearch version less than 3.3.0', () => {
expect(
shouldShowBreakdownSelector(
{
timeFieldName: '@timestamp',
dataSourceRef: {
id: 'test-id',
type: 'OpenSearch',
version: '3.2.0',
},
} as any,
mockServices
)
).toBe(false);

expect(
shouldShowBreakdownSelector(
{
timeFieldName: '@timestamp',
dataSourceRef: {
id: 'test-id',
type: 'OpenSearch',
version: '2.5.0',
},
} as any,
mockServices
)
).toBe(false);
});

it('should return false for non-OpenSearch data sources', () => {
expect(
shouldShowBreakdownSelector(
{
timeFieldName: '@timestamp',
dataSourceRef: {
id: 'test-id',
type: 'S3',
version: '8.0.0',
},
} as any,
mockServices
)
).toBe(false);
});

it('should handle version strings without patch version', () => {
expect(
shouldShowBreakdownSelector(
{
timeFieldName: '@timestamp',
dataSourceRef: {
id: 'test-id',
type: 'OpenSearch',
version: '3.3',
},
} as any,
mockServices
)
).toBe(true);

expect(shouldShowBreakdownSelector(mockDataView, mockServices)).toBe(true);
expect(
shouldShowBreakdownSelector(
{
timeFieldName: '@timestamp',
dataSourceRef: {
id: 'test-id',
type: 'OpenSearch',
version: '3.2',
},
} as any,
mockServices
)
).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
* SPDX-License-Identifier: Apache-2.0
*/

import semver from 'semver';
import { DataView } from '../../../../../data/common';
import { ENABLE_EXPERIMENTAL_SETTING } from '../../../../common';

/**
* Determines whether the breakdown selector should be shown.
*
* @param dataView - The current data view
* @param dataset - The current data view
* @param services - Services object containing uiSettings
* @returns true if breakdown selector should be shown, false otherwise
*/
export const shouldShowBreakdownSelector = (
dataView: DataView | undefined,
dataset: DataView | undefined,
services?: any
): boolean => {
if (!dataView) {
if (!dataset) {
return false;
}

Expand All @@ -27,5 +28,21 @@ export const shouldShowBreakdownSelector = (
return false;
}

return true;
// Check for dataSourceRef - if it doesn't exist, default to true (show)
const dataSourceRef = (dataset as any).dataSourceRef;
if (!dataSourceRef) {
return true;
}

// If type or version is missing, default to true (show)
if (!dataSourceRef.type || !dataSourceRef.version) {
return true;
}

// Check if it's OpenSearch and version is 3.3 or greater
const isOpenSearch = dataSourceRef.type === 'OpenSearch';
const isCompatibleVersion = semver.gte(semver.coerce(dataSourceRef.version) || '0.0.0', '3.3.0');

// Show breakdown selector only if it's OpenSearch 3.3+
return isOpenSearch && isCompatibleVersion;
};
Loading