Skip to content

Commit

Permalink
ISPN-15324 Reset stats
Browse files Browse the repository at this point in the history
* Global stats
* Per cache stats
  • Loading branch information
karesti committed Nov 24, 2023
1 parent 3bd694a commit 2e6835e
Show file tree
Hide file tree
Showing 19 changed files with 371 additions and 239 deletions.
16 changes: 12 additions & 4 deletions cypress/e2e/1_global-stats.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ describe('Global stats', () => {
cy.contains('Cluster distribution');
});

//View all caches href
it('successfully loads Global stats', () => {
it('successfully links to caches link', () => {
//click View all caches should navigate to console page
cy.get('[data-cy="viewCachesLink"]').click();
//Verify that page is properly loaded after click;
Expand All @@ -24,13 +23,22 @@ describe('Global stats', () => {
cy.contains('java-serialized-cache');
});

//View Cluster Status href
it('successfully loads Global stats', () => {
it('successfully links to cluster status', () => {
//click View Cluster Status should navigate to cluster-membership page
cy.get('[data-cy="viewClustersLink"]').click();

//Verify that page is properly loaded after click;
cy.get('h1').should('contain', 'Cluster membership');
cy.contains('Healthy');
});

it('successfully resets and refresh global metrics', () => {
cy.get('[data-cy="globalStatsActions"]').click();
cy.get('[data-cy="clearAccessMetricsButton"]').click();
cy.contains('Permanently clear global metrics?');
cy.get('[data-cy="confirmButton"]').click();
cy.get('[data-cy="globalStatsActions"]').click();
cy.get('[data-cy="refreshAction"]').click();
});

});
14 changes: 14 additions & 0 deletions cypress/e2e/1_rbac_func.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ describe('RBAC Functionality Tests', () => {
checkMenu(false);
cy.login(monitorUserName, Cypress.env('password'), '/cache/default');
checkNoEntriesTabView(false);
cy.login(monitorUserName, Cypress.env('password'), '/global-stats');
checkGlobalStatsView(false)
});

it('successfully logins and performs actions with observer user', () => {
Expand All @@ -36,6 +38,8 @@ describe('RBAC Functionality Tests', () => {
checkCountersPageView();
cy.login(observerUserName, Cypress.env('password'), '/cache/default');
checkNoEntriesTabView(false);
cy.login(observerUserName, Cypress.env('password'), '/global-stats');
checkGlobalStatsView(false)
});

it('successfully logins and performs actions with application user', () => {
Expand All @@ -53,6 +57,8 @@ describe('RBAC Functionality Tests', () => {
checkCountersPageView();
cy.login(applicationUserName, Cypress.env('password'), '/cache/default');
checkNoEntriesTabView(false);
cy.login(applicationUserName, Cypress.env('password'), '/global-stats');
checkGlobalStatsView(false)
});

it('successfully logins and performs actions with deployer user', () => {
Expand All @@ -70,6 +76,8 @@ describe('RBAC Functionality Tests', () => {
checkCountersPageView();
cy.login(deployerUserName, Cypress.env('password'), '/cache/default');
checkNoEntriesTabView(false);
cy.login(deployerUserName, Cypress.env('password'), '/global-stats');
checkGlobalStatsView(false)
});

it('successfully logins and performs actions with admin user', () => {
Expand Down Expand Up @@ -181,6 +189,7 @@ describe('RBAC Functionality Tests', () => {
cy.get('[data-cy=queriesTab]').should('exist');
}

cy.get('[data-cy=detailCacheActions]').click();
cy.get('[data-cy=manageIndexesLink]').click();
if (isSuperAdmin) {
cy.get('[data-cy=clearIndexButton]').should('exist');
Expand Down Expand Up @@ -277,6 +286,7 @@ describe('RBAC Functionality Tests', () => {
cy.get('[data-cy=cacheConfigurationTab]').click();
cy.contains('authorization').should('not.exist');
}
cy.get('[data-cy=detailCacheActions]').click();
cy.get('[data-cy=manageIndexesLink]').click();
if (isSuperAdmin) {
cy.get('[data-cy=clearIndexButton]').should('exist');
Expand Down Expand Up @@ -410,6 +420,10 @@ describe('RBAC Functionality Tests', () => {
// metrics tab is visible
cy.contains('Data access').should('exist');
}
}

function checkGlobalStatsView() {
cy.get('[data-cy="globalStatsActions"]').click();
cy.contains('[data-cy="clearAccessMetricsButton"]').should('not.exist');
}
});
3 changes: 3 additions & 0 deletions cypress/e2e/2_cache-detail-search.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ describe('Cache Detail Overview', () => {
//Opening indexed-cache cache page.
cy.login(Cypress.env("username"), Cypress.env("password"), '/cache/indexed-cache');

cy.get('[data-cy=detailCacheActions]').click();
cy.get("[data-cy=manageIndexesLink]").click();
cy.contains("org.infinispan.Person");
cy.contains("3 k");
cy.get("[data-cy=backButton]").click();
cy.contains("Elaia");

cy.get('[data-cy=detailCacheActions]').click();
cy.get("[data-cy=manageIndexesLink]").click();
cy.get("[data-cy=clearIndexButton]").click();
cy.contains("Permanently clear index?");
Expand All @@ -76,6 +78,7 @@ describe('Cache Detail Overview', () => {

cy.get("[data-cy=backButton]").click();
cy.contains("Elaia");
cy.get('[data-cy=detailCacheActions]').click();
cy.get("[data-cy=manageIndexesLink]").click();
cy.contains("3 k");
})
Expand Down
9 changes: 9 additions & 0 deletions cypress/e2e/2_cache-metrics.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ describe('Cache Metrics Overview', () => {
verifyCacheMetrics(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
});

it('successfully resets metrics', () => {
cy.login(Cypress.env('username'), Cypress.env('password'), '/cache/people');
cy.get('[data-cy=cacheMetricsTab]').click();
cy.get('[data-cy=clearAccessMetricsButton]').click();
cy.contains('Permanently clear data access metrics?');
cy.get('[data-cy=confirmButton]').click();
cy.contains('Cache stats people cleared');
});

// TODO: Add a test of good stats display with a cache that does not change and provided different metrics

function verifyCacheMetrics(
Expand Down
76 changes: 0 additions & 76 deletions src/__tests__/views/GlobalStats.test.tsx

This file was deleted.

12 changes: 2 additions & 10 deletions src/app/AccessManagement/AccessManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ const AccessManager = () => {
const [isOpen, setIsOpen] = useState(false);
const [isFlushCache, setIsFlushCache] = useState(false);

const onToggleClick = () => {
setIsOpen(!isOpen);
};

const onSelect = (_event: React.MouseEvent<Element, MouseEvent> | undefined, value: string | number | undefined) => {
setIsOpen(false);
};

interface AccessTab {
key: string;
name: string;
Expand Down Expand Up @@ -100,10 +92,10 @@ const AccessManager = () => {
<ToolbarItem>
<Dropdown
isOpen={isOpen}
onSelect={onSelect}
onSelect={() => setIsOpen(false)}
onOpenChange={(isOpen: boolean) => setIsOpen(isOpen)}
toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
<MenuToggle ref={toggleRef} data-cy="aclActions" onClick={onToggleClick} isExpanded={isOpen}>
<MenuToggle ref={toggleRef} data-cy="aclActions" onClick={() => setIsOpen(!isOpen)} isExpanded={isOpen}>
{t('common.actions.actions')}
</MenuToggle>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/app/Caches/CacheMetrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ const CacheMetrics = (props: { cacheName: string; display: boolean }) => {
{displayDataDistribution && <GridItem span={8}> {buildDataDistribution()}</GridItem>}
<GridItem span={4}>
<CacheLifecycle stats={stats} />
<DataAccess stats={stats} />
<DataAccess cacheName={props.cacheName} stats={stats} />
</GridItem>
<GridItem span={displayDataDistribution ? 12 : 8}>{buildQueryStats()}</GridItem>
</Grid>
Expand Down
49 changes: 44 additions & 5 deletions src/app/Caches/DataAccess.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import {
Card,
CardBody,
Expand All @@ -9,16 +9,26 @@ import {
TextList,
TextListItem,
TextListVariants,
TextListItemVariants
TextListItemVariants,
LevelItem,
Level,
Button,
ButtonVariant
} from '@patternfly/react-core';
import { useTranslation } from 'react-i18next';
import { PopoverHelp } from '@app/Common/PopoverHelp';
import displayUtils from '@services/displayUtils';
import { global_spacer_sm } from '@patternfly/react-tokens';
import { ConsoleServices } from '@services/ConsoleServices';
import { ConsoleACL } from '@services/securityService';
import { ClearMetrics } from '@app/ClearMetrics/ClearMetrics';
import { useConnectedUser } from '@app/services/userManagementHook';

const DataAccess = (props: { stats: CacheStats }) => {
const DataAccess = (props: { cacheName: string; stats: CacheStats }) => {
const { t } = useTranslation();
const brandname = t('brandname.brandname');
const { connectedUser } = useConnectedUser();
const [isClearMetricsModalOpen, setClearMetricsModalOpen] = useState<boolean>(false);

const all =
props.stats.hits +
props.stats.retrievals +
Expand All @@ -41,9 +51,38 @@ const DataAccess = (props: { stats: CacheStats }) => {
);
};

const buildClearStatsButton = () => {
if (!ConsoleServices.security().hasConsoleACL(ConsoleACL.ADMIN, connectedUser)) {
return '';
}

return (
<LevelItem>
<Button
data-cy="clearAccessMetricsButton"
variant={ButtonVariant.danger}
onClick={() => setClearMetricsModalOpen(true)}
>
{t('caches.cache-metrics.button-clear-access-stats')}
</Button>
<ClearMetrics
name={props.cacheName}
isModalOpen={isClearMetricsModalOpen}
closeModal={() => setClearMetricsModalOpen(false)}
type={'cache-metrics'}
/>
</LevelItem>
);
};

return (
<Card>
<CardTitle>{t('caches.cache-metrics.data-access-title')}</CardTitle>
<CardTitle>
<Level id={'access-stats'}>
<LevelItem>{t('caches.cache-metrics.data-access-title')}</LevelItem>
{buildClearStatsButton()}
</Level>
</CardTitle>
<CardBody>
<TextContent>
<TextList component={TextListVariants.dl}>
Expand Down
Loading

0 comments on commit 2e6835e

Please sign in to comment.