Skip to content

Commit

Permalink
Add the index health
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <[email protected]>
  • Loading branch information
RyanL1997 committed Mar 12, 2024
1 parent e409de9 commit 2051068
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ exports[`Data Connection Page test Renders Prometheus data connection page with
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiIcon--customColor euiIcon-isLoading"
class="euiIcon euiIcon--medium euiIcon--success euiIcon-isLoading"
focusable="false"
height="16"
role="img"
Expand All @@ -641,7 +641,7 @@ exports[`Data Connection Page test Renders Prometheus data connection page with
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
Paused
Active
</div>
</div>
</div>
Expand Down Expand Up @@ -809,7 +809,7 @@ exports[`Data Connection Page test Renders Prometheus data connection page with
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiIcon--customColor euiIcon-isLoading"
class="euiIcon euiIcon--medium euiIcon--success euiIcon-isLoading"
focusable="false"
height="16"
role="img"
Expand All @@ -825,7 +825,7 @@ exports[`Data Connection Page test Renders Prometheus data connection page with
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
Paused
Active
</div>
</div>
</div>
Expand Down Expand Up @@ -993,7 +993,7 @@ exports[`Data Connection Page test Renders Prometheus data connection page with
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiIcon--customColor euiIcon-isLoading"
class="euiIcon euiIcon--medium euiIcon--success euiIcon-isLoading"
focusable="false"
height="16"
role="img"
Expand All @@ -1009,7 +1009,7 @@ exports[`Data Connection Page test Renders Prometheus data connection page with
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
Paused
Active
</div>
</div>
</div>
Expand Down Expand Up @@ -1175,7 +1175,7 @@ exports[`Data Connection Page test Renders Prometheus data connection page with
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiIcon--customColor euiIcon-isLoading"
class="euiIcon euiIcon--medium euiIcon--success euiIcon-isLoading"
focusable="false"
height="16"
role="img"
Expand All @@ -1191,7 +1191,7 @@ exports[`Data Connection Page test Renders Prometheus data connection page with
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
Paused
Active
</div>
</div>
</div>
Expand Down Expand Up @@ -2227,7 +2227,7 @@ exports[`Data Connection Page test Renders S3 data connection page with data 1`]
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiIcon--customColor"
class="euiIcon euiIcon--medium euiIcon--success"
focusable="false"
height="16"
role="img"
Expand All @@ -2245,7 +2245,7 @@ exports[`Data Connection Page test Renders S3 data connection page with data 1`]
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
Paused
Active
</div>
</div>
</div>
Expand Down Expand Up @@ -2413,7 +2413,7 @@ exports[`Data Connection Page test Renders S3 data connection page with data 1`]
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiIcon--customColor"
class="euiIcon euiIcon--medium euiIcon--success"
focusable="false"
height="16"
role="img"
Expand All @@ -2431,7 +2431,7 @@ exports[`Data Connection Page test Renders S3 data connection page with data 1`]
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
Paused
Active
</div>
</div>
</div>
Expand Down Expand Up @@ -2599,7 +2599,7 @@ exports[`Data Connection Page test Renders S3 data connection page with data 1`]
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiIcon--customColor"
class="euiIcon euiIcon--medium euiIcon--success"
focusable="false"
height="16"
role="img"
Expand All @@ -2617,7 +2617,7 @@ exports[`Data Connection Page test Renders S3 data connection page with data 1`]
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
Paused
Active
</div>
</div>
</div>
Expand Down Expand Up @@ -2783,7 +2783,7 @@ exports[`Data Connection Page test Renders S3 data connection page with data 1`]
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiIcon--customColor"
class="euiIcon euiIcon--medium euiIcon--success"
focusable="false"
height="16"
role="img"
Expand All @@ -2801,7 +2801,7 @@ exports[`Data Connection Page test Renders S3 data connection page with data 1`]
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
>
Paused
Active
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ const getSettings = (index: string): Promise<OpenSearchDashboardsResponse> | und
return coreRefs.dslService?.fetchSettings(index);
};

const getIndexInfo = (index: string): Promise<OpenSearchDashboardsResponse> | undefined => {
return coreRefs.dslService?.fetchIndices(index);
};

const handlePromise = (
promise: Promise<OpenSearchDashboardsResponse> | undefined,
flintIndexName: string
Expand All @@ -55,20 +59,15 @@ export const AccelerationDetailsFlyout = ({
}: AccelerationDetailsFlyoutProps) => {
const { index, acceleration } = selectedAcc;
const { flintIndexName } = acceleration;
console.log('hahhahhaha flintIndexName: ', flintIndexName);
// console.log(index);
// console.log('?????index');
console.log('acceleration AccelerationDetailsFlyout: ', acceleration);
// console.log(index);
const [selectedTab, setSelectedTab] = useState('details');
const tabsMap: { [key: string]: any } = {

Check warning on line 63 in public/components/datasources/components/manage/accelerations/acceleration_details_flyout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
details: AccelerationDetailsTab,
schema: AccelerationSchemaTab,
sql_definition: AccelerationSqlTab,
};
// const { dslService } = coreRefs;
const [settings, setSettings] = useState<object>();
const [mappings, setMappings] = useState();
const [indexInfo, setIndexInfo] = useState();

const updateMapping = (result) => {
console.log('updateMapping: ');
Expand All @@ -82,15 +81,22 @@ export const AccelerationDetailsFlyout = ({
setSettings(result.data[slectedIndex]);
};

const updateIndexInfo = (result) => {
console.log('updateIndexInfo: ');
console.log(result);
setIndexInfo(result);
};

const getAccDetail = (selectedIndex: string) => {
console.log('getAccDetail index: ', selectedIndex);
Promise.all([
handlePromise(getMappings(selectedIndex), 'getMappings'),
handlePromise(getSettings(selectedIndex), 'getSettings'),
handlePromise(getIndexInfo(selectedIndex), 'getIndexInfo'),
])
.then((results) => {
updateMapping(results[0]);
updateSetting(results[1], selectedIndex);
updateIndexInfo(results[2]);
})
.catch((errors: Error[]) => {
errors.forEach((error, errorIndex) => {
Expand Down Expand Up @@ -162,12 +168,17 @@ export const AccelerationDetailsFlyout = ({
};

const renderTabContent = (tab: string, tabAcceleration: any) => {

Check warning on line 170 in public/components/datasources/components/manage/accelerations/acceleration_details_flyout.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const { acceleration: acc, settings: sett, mappings: mapp } = tabAcceleration;
const {
acceleration: acc,
settings: sett,
mappings: mapp,
indexInfo: indexI,
} = tabAcceleration;

const TabToDisplay = tabsMap[tab];
console.log('tabAcceleration: ', tabAcceleration);

return <TabToDisplay acceleration={acc} settings={sett} mappings={mapp} />;
return <TabToDisplay acceleration={acc} settings={sett} mappings={mapp} indexInfo={indexI} />;
};

return (
Expand All @@ -193,7 +204,7 @@ export const AccelerationDetailsFlyout = ({
<EuiTabs style={{ marginBottom: '-25px' }}>{renderTabs()}</EuiTabs>
</EuiFlyoutHeader>
<EuiFlyoutBody>
{renderTabContent(selectedTab, { acceleration, settings, mappings })}
{renderTabContent(selectedTab, { acceleration, settings, mappings, indexInfo })}
</EuiFlyoutBody>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
EuiSpacer,
EuiTitle,
} from '@elastic/eui';
import { AccelerationStatus } from '../helpers/utils';
import { AccelerationHealth, AccelerationStatus } from '../helpers/utils';

interface AccelerationDetailsTabProps {
acceleration: {
Expand All @@ -28,15 +28,22 @@ interface AccelerationDetailsTabProps {
};
settings: object;
mappings: object;
indexInfo: any;

Check warning on line 31 in public/components/datasources/components/manage/accelerations/flyout_modules/acceleration_details_tab.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
}

export const AccelerationDetailsTab = ({
acceleration,
settings,
mappings,
indexInfo,
}: AccelerationDetailsTabProps) => {
const accStatus = acceleration.status;
console.log('Hereererere is the status: ', accStatus);

Check failure on line 40 in public/components/datasources/components/manage/accelerations/flyout_modules/acceleration_details_tab.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `⏎`
console.log('mappings:', mappings);
console.log('indexInfo:', indexInfo);
console.log('indexInfo data:', indexInfo?.data);
console.log('First item in indexInfo data:', indexInfo?.data[0]);
console.log('Health of the first item:', indexInfo?.data[0]?.health);

const DetailComponent = ({
title,
description,
Expand Down Expand Up @@ -99,10 +106,10 @@ export const AccelerationDetailsTab = ({
<EuiSpacer />
<TitleComponent title="Index details" />
<EuiFlexGroup>
<DetailComponent title="Index name" description={acceleration.flintIndexName} />
<DetailComponent title="Index name" description={indexInfo?.data[0]?.index} />
<DetailComponent
title="Health"
description={<AccelerationStatus status={acceleration.status} />}
description={<AccelerationHealth health={indexInfo?.data[0]?.health} />}
/>
<DetailComponent title="Refresh interval" description="2s" />
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,38 @@ import { EuiHealth } from '@elastic/eui';

export const AccelerationStatus = (props: { status: string }) => {
const { status } = props;
// TODO: actually get status from acceleration
console.log('status is', status);
const label = status === 'Active' ? 'Active' : 'Paused';
const color = status === 'Active' ? 'success' : 'inactive';
return <EuiHealth color={color}>{label}</EuiHealth>;
};

export const AccelerationHealth = ({ health }: { health: string }) => {
console.log('health is', health);

Check warning on line 18 in public/components/datasources/components/manage/accelerations/helpers/utils.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/accelerations/helpers/utils.tsx#L18

Added line #L18 was not covered by tests

let label, color;

Check failure on line 20 in public/components/datasources/components/manage/accelerations/helpers/utils.tsx

View workflow job for this annotation

GitHub Actions / Lint

Split 'let' declarations into multiple statements

switch (health) {
case 'green':
label = 'Green';
color = 'success';
break;
case 'red':
label = 'Red';
color = 'danger';
break;
case 'yellow':
label = 'Yellow';
color = 'warning';
break;
default:
label = 'Invalid';
color = 'danger';

Check warning on line 37 in public/components/datasources/components/manage/accelerations/helpers/utils.tsx

View check run for this annotation

Codecov / codecov/patch

public/components/datasources/components/manage/accelerations/helpers/utils.tsx#L23-L37

Added lines #L23 - L37 were not covered by tests
}

return <EuiHealth color={color}>{label}</EuiHealth>;
};

export const getRefreshButtonIcon = () => {
// TODO: If acceleration can only be manually refreshed, return inputOutput
// If acceleration is automatically refreshed and paused, return play
Expand Down
4 changes: 2 additions & 2 deletions public/services/requests/dsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ export default class DSLService {
.catch((error) => console.error(error));
};

fetchIndices = async () => {
fetchIndices = async (index: string = '') => {
return this.http
.get(`${DSL_BASE}${DSL_CAT}`, {
query: {
format: 'json',
index,
},
})
.catch((error) => console.error(error));
};

fetchFields = async (index: string) => {
console.log('index: ', index);
return this.http.get(`${DSL_BASE}${DSL_MAPPING}`, {

Check warning on line 40 in public/services/requests/dsl.ts

View check run for this annotation

Codecov / codecov/patch

public/services/requests/dsl.ts#L40

Added line #L40 was not covered by tests
query: {
index,
Expand Down
2 changes: 1 addition & 1 deletion server/routes/dsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function registerDslRoute({ router }: { router: IRouter; facet: DSLFacet
validate: {
query: schema.object({
format: schema.string(),
index: schema.string(),
}),
},
},
Expand All @@ -77,7 +78,6 @@ export function registerDslRoute({ router }: { router: IRouter; facet: DSLFacet
router.get(
{
path: `${DSL_BASE}${DSL_MAPPING}`,
// path: `${DSL_BASE}/indices.getFieldMapping`,
validate: { query: schema.any() },
},
async (context, request, response) => {
Expand Down

0 comments on commit 2051068

Please sign in to comment.