Skip to content

Commit

Permalink
Merge branch 'main' into remove-update-button
Browse files Browse the repository at this point in the history
  • Loading branch information
paulstn authored Apr 30, 2024
2 parents a0d3943 + 23cca62 commit e7d43ea
Show file tree
Hide file tree
Showing 47 changed files with 3,535 additions and 194 deletions.
4 changes: 4 additions & 0 deletions common/constants/data_sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,7 @@ export const ACCELERATION_AGGREGRATION_FUNCTIONS = [
];

export const SPARK_PARTITION_INFO = `# Partition Information`;
export const OBS_DEFAULT_CLUSTER = 'observability-default'; // prefix key for generating data source id for default cluster in data selector
export const OBS_S3_DATA_SOURCE = 'observability-s3'; // prefix key for generating data source id for s3 data sources in data selector
export const S3_DATA_SOURCE_GROUP_DISPLAY_NAME = 'Amazon S3'; // display group name for Amazon-managed-s3 data sources in data selector
export const S3_DATA_SOURCE_GROUP_SPARK_DISPLAY_NAME = 'Spark'; // display group name for OpenSearch-spark-s3 data sources in data selector
2 changes: 1 addition & 1 deletion common/constants/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export const VISUALIZATION_ERROR = {
NO_METRIC: 'Invalid Metric MetaData',
};

export const S3_DATASOURCE_TYPE = 'S3_DATASOURCE';
export const S3_DATA_SOURCE_TYPE = 's3glue';

export const ASYNC_QUERY_SESSION_ID = 'async-query-session-id';
export const ASYNC_QUERY_DATASOURCE_CACHE = 'async-query-catalog-cache';
Expand Down
17 changes: 13 additions & 4 deletions public/components/custom_panels/helpers/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -704,16 +704,25 @@ export const constructOtelMetricsMetaData = () => {
};
};

export const parseMetadataUserConfig = (
userConfigs?: string | SavedObjectAttributes
): SavedObjectAttributes => {
if (userConfigs === undefined || userConfigs === '') {
return {};
} else if (typeof userConfigs === 'string') {
return JSON.parse(userConfigs);
} else {
return userConfigs;
}
};

// Renders visualization in the vizualization container component
export const displayVisualization = (metaData: any, data: any, type: string) => {
if (metaData === undefined || isEmpty(metaData)) {
return <></>;
}

if (metaData.userConfigs !== undefined && metaData.userConfigs !== '') {
metaData.userConfigs = JSON.parse(metaData.userConfigs);
}

metaData.userConfigs = parseMetadataUserConfig(metaData.userConfigs);
const dataConfig = { ...(metaData.userConfigs?.dataConfig || {}) };
const hasBreakdowns = !_.isEmpty(dataConfig.breakdowns);
const realTimeParsedStats = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ exports[`Data Connection Page test Renders S3 data connection page with data 1`]
>
<button
aria-controls="random_html_id"
aria-selected="true"
class="euiTab euiTab-isSelected"
aria-selected="false"
class="euiTab"
id="associated_objects"
role="tab"
type="button"
Expand Down Expand Up @@ -401,8 +401,8 @@ exports[`Data Connection Page test Renders S3 data connection page with data 1`]
</button>
<button
aria-controls="random_html_id"
aria-selected="false"
class="euiTab"
aria-selected="true"
class="euiTab euiTab-isSelected"
id="access_control"
role="tab"
type="button"
Expand All @@ -415,7 +415,7 @@ exports[`Data Connection Page test Renders S3 data connection page with data 1`]
</button>
</div>
<div
aria-labelledby="associated_objects"
aria-labelledby="access_control"
id="random_html_id"
role="tabpanel"
>
Expand Down Expand Up @@ -446,9 +446,18 @@ exports[`Data Connection Page test Renders S3 data connection page with data 1`]
<span
class="euiCallOutHeader__title"
>
Accelerations recommended for tables. Setup acceleration or configure integrations
Configurations may be managed elsewhere.
</span>
</div>
<div
class="euiText euiText--small"
>
<div
class="euiTextColor euiTextColor--default"
>
Access to data may be managed in other systems outside of OpenSearch. Check with your administrator for additional configurations.
</div>
</div>
</div>
<div
class="euiSpacer euiSpacer--l"
Expand All @@ -457,7 +466,7 @@ exports[`Data Connection Page test Renders S3 data connection page with data 1`]
class="euiPanel euiPanel--paddingMedium euiPanel--borderRadiusMedium euiPanel--plain euiPanel--hasShadow"
>
<div
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--alignItemsCenter euiFlexGroup--directionRow euiFlexGroup--responsive"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--directionRow euiFlexGroup--responsive"
>
<div
class="euiFlexItem"
Expand All @@ -468,78 +477,17 @@ exports[`Data Connection Page test Renders S3 data connection page with data 1`]
<h2
class="panel-title"
>
Associated objects
Access control
</h2>
Manage objects associated with this data sources.
</div>
</div>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<div
class="euiText euiText--extraSmall"
>
<div
class="euiTextAlign euiTextAlign--right"
>
<div
class="euiTextColor euiTextColor--subdued"
>
Last updated at:
</div>
</div>
</div>
<div
class="euiText euiText--extraSmall"
>
<div
class="euiTextAlign euiTextAlign--right"
>
<div
class="euiTextColor euiTextColor--subdued"
>
1/1/2024, 12:00:00 AM
</div>
</div>
Control which OpenSearch users have access to this data source.
</div>
</div>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<button
class="euiButton euiButton--primary"
type="button"
>
<span
class="euiButtonContent euiButton__content"
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiIcon--inherit euiButtonContent__icon"
focusable="false"
height="16"
role="img"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M11.228 2.942a.5.5 0 1 1-.538.842A5 5 0 1 0 13 8a.5.5 0 1 1 1 0 6 6 0 1 1-2.772-5.058ZM14 1.5v3A1.5 1.5 0 0 1 12.5 6h-3a.5.5 0 0 1 0-1h3a.5.5 0 0 0 .5-.5v-3a.5.5 0 1 1 1 0Z"
/>
</svg>
<span
class="euiButton__text"
>
Refresh
</span>
</span>
</button>
</div>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<button
class="euiButton euiButton--primary euiButton--fill"
data-test-subj="createButton"
type="button"
>
<span
Expand All @@ -548,7 +496,7 @@ exports[`Data Connection Page test Renders S3 data connection page with data 1`]
<span
class="euiButton__text"
>
Create acceleration
Edit
</span>
</span>
</button>
Expand All @@ -558,31 +506,38 @@ exports[`Data Connection Page test Renders S3 data connection page with data 1`]
class="euiHorizontalRule euiHorizontalRule--full euiHorizontalRule--marginLarge"
/>
<div
class="euiEmptyPrompt"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--directionRow euiFlexGroup--responsive"
>
<span
class="euiLoadingSpinner euiLoadingSpinner--xLarge"
/>
<div
class="euiSpacer euiSpacer--m"
/>
<span
class="euiTextColor euiTextColor--subdued"
class="euiFlexItem"
>
<div
class="euiText euiText--medium"
class="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--directionColumn euiFlexGroup--responsive"
>
<p>
Loading
databases
</p>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
<div
class="euiText euiText--medium overview-title"
>
Query access
</div>
<div
class="euiText euiText--small overview-content"
>
Admin only
</div>
</div>
</div>
</span>
</div>
</div>
</div>
<div
class="euiSpacer euiSpacer--l"
/>
<div
class="euiSpacer euiSpacer--l"
/>
</div>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { act } from '@testing-library/react';
import { act, render, waitFor } from '@testing-library/react';
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import React from 'react';
Expand Down Expand Up @@ -65,4 +65,44 @@ describe('Data Connection Page test', () => {
});
expect(container).toMatchSnapshot();
});

it('Does not render Associated Objects, Accelerations, and Installed Integrations tabs for Prometheus data source', async () => {
CatalogCacheManager.saveDataSourceCache(mockDataSourceCacheData);
CatalogCacheManager.saveAccelerationsCache(mockAccelerationCacheData);

(coreRefs.http!.get as jest.Mock).mockResolvedValue(describePrometheusDataConnection);

const { container, queryByText } = render(<DataConnection dataSource="PROMETHEUS" />);

await waitFor(() => {
expect(queryByText('Associated Objects')).not.toBeInTheDocument();
expect(queryByText('Accelerations')).not.toBeInTheDocument();
expect(queryByText('Installed Integrations')).not.toBeInTheDocument();

const accessControlTabs = Array.from(container.querySelectorAll('.euiTab__content')).filter(
(el) => el.textContent === 'Access control'
);
expect(accessControlTabs.length).toBeGreaterThan(0);
});
});

it('Renders all tabs for S3Glue data source', async () => {
CatalogCacheManager.saveDataSourceCache(mockDataSourceCacheData);
CatalogCacheManager.saveAccelerationsCache(mockAccelerationCacheData);

(coreRefs.http!.get as jest.Mock).mockResolvedValue(describeS3Dataconnection);

const { container, getByText } = render(<DataConnection dataSource="S3GLUE" />);

await waitFor(() => {
expect(getByText('Associated Objects')).toBeInTheDocument();
expect(getByText('Accelerations')).toBeInTheDocument();
expect(getByText('Installed Integrations')).toBeInTheDocument();

const accessControlTabs = Array.from(container.querySelectorAll('.euiTab__content')).filter(
(el) => el.textContent === 'Access control'
);
expect(accessControlTabs.length).toBeGreaterThan(0);
});
});
});
81 changes: 46 additions & 35 deletions public/components/datasources/components/manage/data_connection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,41 +209,7 @@ export const DataConnection = (props: { dataSource: string }) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [chrome, http]);

const tabs = [
{
id: 'associated_objects',
name: 'Associated Objects',
disabled: false,
content: (
<AssociatedObjectsTab
datasource={datasourceDetails}
cacheLoadingHooks={cacheLoadingHooks}
selectedDatabase={selectedDatabase}
setSelectedDatabase={setSelectedDatabase}
/>
),
},
{
id: 'acceleration_table',
name: 'Accelerations',
disabled: false,
content: (
<AccelerationTable dataSourceName={dataSource} cacheLoadingHooks={cacheLoadingHooks} />
),
},
{
id: 'installed_integrations',
name: 'Installed Integrations',
disabled: false,
content: (
<InstalledIntegrationsTable
integrations={dataSourceIntegrations}
datasourceType={datasourceDetails.connector}
datasourceName={datasourceDetails.name}
refreshInstances={refreshInstances}
/>
),
},
const genericTabs = [
{
id: 'access_control',
name: 'Access control',
Expand All @@ -260,6 +226,51 @@ export const DataConnection = (props: { dataSource: string }) => {
},
];

const conditionalTabs =
datasourceDetails.connector === 'S3GLUE'
? [
{
id: 'associated_objects',
name: 'Associated Objects',
disabled: false,
content: (
<AssociatedObjectsTab
datasource={datasourceDetails}
cacheLoadingHooks={cacheLoadingHooks}
selectedDatabase={selectedDatabase}
setSelectedDatabase={setSelectedDatabase}
/>
),
},
{
id: 'acceleration_table',
name: 'Accelerations',
disabled: false,
content: (
<AccelerationTable
dataSourceName={dataSource}
cacheLoadingHooks={cacheLoadingHooks}
/>
),
},
{
id: 'installed_integrations',
name: 'Installed Integrations',
disabled: false,
content: (
<InstalledIntegrationsTable
integrations={dataSourceIntegrations}
datasourceType={datasourceDetails.connector}
datasourceName={datasourceDetails.name}
refreshInstances={refreshInstances}
/>
),
},
]
: [];

const tabs = [...conditionalTabs, ...genericTabs];

const QueryOrAccelerateData = () => {
switch (datasourceDetails.connector) {
case 'S3GLUE':
Expand Down
Loading

0 comments on commit e7d43ea

Please sign in to comment.